#
# rcsid $Header: /ufs/repository/magic/Makefile,v 1.11 2001/01/14 19:22:26 rajit Exp $
#

MAGICDIR   = .
PROGRAMS   = ext2sim ext2spice magic
TECH       = scmos
LIBRARIES  = database utils extflat
MODULES    = cmwind commands database dbwind debug drc \
             extflat extract graphics \
             macros main misc netlist netmenu \
             parser resis select signals sim \
             textio tech tiles undo utils windows wiring

MAKEFLAGS  =
INSTALL_CAD_DIRS = windows doc ${TECH}

include defs.mak

all:
	@echo --- errors and warnings logged in file make.log
	@${MAKE} mains 2>&1 | tee -a make.log | egrep -i "(warning|error|---)" |\
	    egrep -v "extra tokens"

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

magic: all

force: clean all

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

config:
	@${MAGICDIR}/scripts/config

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

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

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:
	for dir in ${MODULES} ${PROGRAMS}; do \
		(cd $$dir && ${MAKE} depend); done

install:
	@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-dirs:
	${MAGICDIR}/scripts/mkdirs ${BINDIR} ${MANDIR} ${SYSDIR} ${SCMDIR} ${TCLDIR}

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

install-tcl-real: install-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 default.conf
	touch defs.mak

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
