#
# rcsid $Header: /usr/cvsroot/magic/Makefile,v 1.2 2005/02/11 17:31:52 tim Exp $
#

MAGICDIR   = .
PROGRAMS   = magic ext2sim ext2spice
TECH       = scmos
LIBRARIES  = database utils extflat
MODULES    = cmwind commands database dbwind debug drc extflat extract \
	     graphics netmenu plow resis select sim textio tiles utils \
	     windows wiring

MAKEFLAGS  =
INSTALL_CAD_DIRS = windows doc ${TECH}

include defs.mak

all:	$(ALL_TARGET)

standard:
	@echo --- errors and warnings logged in file make.log
	@${MAKE} mains 2>&1 | tee -a make.log | egrep -i "(.c:|---)"

tcl:
	@echo --- errors and warnings logged in file make.log
	@${MAKE} tcllibrary 2>&1 | tee -a make.log | egrep -i "(.c:|---)"

force: clean all

defs.mak:
	@echo No \"defs.mak\" file found. Run "make config" to make one.

config:
	@if ( test -d ~cad ) ; then \
	${MAGICDIR}/scripts/config ~cad ; \
	else \
	${MAGICDIR}/scripts/config /usr/local ; \
	fi

tcllibrary: database/database.h modules
	@echo --- making Tcl shared libraries
	for dir in ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} tcl-main); done

mains: database/database.h modules libs
	@echo --- making main programs
	for dir in ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} main); done

database/database.h: database/database.h.in
	@echo --- making header file database/database.h
	${SCRIPTS}/makedbh database/database.h.in database/database.h

modules:
	@echo --- making modules
	for dir in ${MODULES} ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} module); done

libs:
	@echo --- making libraries
	for dir in ${LIBRARIES}; do \
		(cd $$dir && ${MAKE} lib); done

depend:	database/database.h
	${RM} */Depend
	for dir in ${MODULES} ${UNUSED_MODULES} ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} depend); done

install: $(INSTALL_TARGET)

install-magic:
	@echo --- installing to ${CADDIR}
	@${MAKE} install-real 2>&1 >> install.log

install-real: install-dirs
	for dir in ${INSTALL_CAD_DIRS}; do \
		(cd $$dir && ${MAKE} install); done
	for dir in ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} install); done

install-tcl-dirs:
	${MAGICDIR}/scripts/mkdirs ${BINDIR} ${MANDIR} ${SYSDIR} ${TCLDIR} ${TCLDIR}/bitmaps

install-dirs:
	${MAGICDIR}/scripts/mkdirs ${BINDIR} ${MANDIR} ${SYSDIR} ${SCMDIR}

install-tcl:
	@echo --- installing to ${CADDIR}
	@${MAKE} install-tcl-real 2>&1 >> install.log

install-tcl-real: install-tcl-dirs
	for dir in ${INSTALL_CAD_DIRS} ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} install-tcl); done

clean:
	for dir in ${MODULES} ${PROGRAMS} ${TECH} ${UNUSED_MODULES}; do \
		(cd $$dir && ${MAKE} clean); done
	${RM} *.tmp */*.tmp *.sav */*.sav *.log TAGS tags

veryclean:
	touch defs.mak
	@${MAKE} clean
	${RM} defs.mak old.defs.mak ${MAGICDIR}/scripts/defs.mak
	${RM} ${MAGICDIR}/scripts/default.conf
	touch defs.mak
	chown --reference=. defs.mak >& /dev/null

clean-mains:
	for dir in ${PROGRAMS}; do \
		(cd $$dir && ${RM} $$dir); done

tags:
	${RM} tags
	find . ${MODULES} ${PROGRAMS} -name "*.[ch]" -maxdepth 1 | xargs ctags -o tags

TAGS: 
	${RM} TAGS
	find . ${MODULES} ${PROGRAMS} -name "*.[ch]" -maxdepth 1 | xargs etags -o TAGS
