#
# Makefile for all of magic
#
#	MODULES are pieces of the Magic system.  The makefiles for
#		each of these will 'install' in the subdirectories
#		'lib' and 'installed'.
#	PROGRAMS are individual programs that get installed.
#		The makefiles for each of these will 'install' in
#		~cad/bin.
#	FILES are miscellaneous files 
#	DIRS are whole directories that get copied (also see disttape).
#
# Special handling: the subdirectory cadlib gets installed remotely
# as ~cad/lib/magic.  It is a symbolic link.  The module 'graphics' appears 
# in PROGRAMS because that is where X11Helper, grSunProg, and grSunProg2 reside.
#
# rcsid $Header: Makefile,v 1.16 90/09/13 10:29:32 mayo Exp $
#

SHELL=/bin/sh

#
# NOTE: tiles and tech must be before database in this list
#

BASEMODS	= tiles tech \
		  calma cif cmwind commands database dbwind debug drc \
		  extflat extract garouter gcr graphics grouter irouter \
		  macros main misc mzrouter netlist netmenu \
		  parser plot plow resis router select signals sim \
		  textio undo utils windows wiring 
MODULES		= ${BASEMODS} 

BASEMAINS	= ext2dlys ext2sim ext2spice magic magicusage \
		  net2ir extcheck mpack 
#	fsleeper 
PROGRAMS	= ${BASEMAINS} graphics
FILES		= :cadtomag :countlines :makeall :makeforce :makelib \
		  :status Makefile READ_ME
DIRS		= include cadlib
CMD		= echo Need to define your command via 'make cmd CMD=command'
CADDIR		= `:findcad`
CADDIR_SUB	= `../:findcad`

everything: ${MODULES} .config
	/bin/csh :makeall installhdrs ${MODULES}
	/bin/csh :makeall install ${MODULES}
	/bin/csh :makemains ${PROGRAMS}

install: everything directories install-tech
	cd windows; make installcad CADDIR=${CADDIR_SUB}
	cd doc; make installcad CADDIR=${CADDIR_SUB}
	/bin/csh :execmod "make installcad CADDIR=${CADDIR}" ${PROGRAMS}

install-tech:
	cd scmos; make install CADDIR=${CADDIR_SUB}

directories:
	:mkdir ${CADDIR}/bin
	:mkdir ${CADDIR}/lib
	:mkdir ${CADDIR}/lib/magic
	:mkdir ${CADDIR}/lib/magic/sys
	:mkdir ${CADDIR}/man

# Remakes the binary in 'lib', if needed.  Used for recompiling on 
# a remote machine.
onlylib: ${MODULES} .config
	/bin/csh :makelib ${MODULES}

modules:
	mkdir ${MODULES}

installhdrs: ${MODULES} .config
	/bin/csh :makeall installhdrs ${MODULES}

cmd:	forceit
	/bin/csh :execmod "${CMD}" ${MODULES} ${BASEMAINS}

allobj:	${MODULES} .config
	/bin/csh :makeall  "" ${MODULES}

force:	clean
	/bin/csh :makeall installhdrs ${MODULES}
	/bin/csh :makeforce install ${MODULES}
	/bin/csh :makemains ${PROGRAMS}

clean:	forceit
	rm -f lib/*.o lib/*.a
	rm -f include/*.h
	rm -f *.tmp */*.tmp *.sav */*.sav
	/bin/csh :execmod "make clean" ${MODULES} ${BASEMAINS} ${PROGRAMS}

lint:	forceit
	/bin/csh :execmod "make lint" ${MODULES} ${BASEMAINS}

status:	${MODULES}
	/bin/csh :status ${MODULES}

config:	forceit
	/bin/csh :config
	date > .config

.config: 
	echo "*** ERROR:  You need to do a \"make config\" first!"
	cat .config

magic:	everything
	cd magic; make magic

tar:	clean
	chmod a-w */Makefile */*.[ch]
	rm -f .config misc/CFLAGS misc/DFLAGS misc/CPPFLAGS
	cd misc; cp CFLAGS.orig CFLAGS; cp DFLAGS.orig DFLAGS; cp CPPFLAGS.orig CPPFLAGS
	cd ..; rm -f magic-6.4.4.tar.Z; tar cvf - magic-6.4.4 > magic-6.4.4.tar; compress magic-6.4.4.tar

tags:
	rm -f magic/tags
	cp /dev/null magic/tags
	-for i in ${MODULES}; do \
		(cd magic ; ctags -a -t ../$$i/*.[ch] ; cd ..); done
	sort magic/tags -o magic/tags

TAGS:
	rm -f magic/TAGS.build
	-for i in ${MODULES}; do \
		(cd magic ; etags ../$$i/*.[ch] ; cat TAGS >> TAGS.build ;\
		 cd ..); done
	mv magic/TAGS.build magic/TAGS

tagdirs:
	-for i in ${MODULES}; do \
		(cd $$i ; rm -f tags ; ln -s ../magic/tags tags ; cd ..); done

allp:	${MODULES}
	/bin/csh :makeall profile ${MODULES}

forcep:	${MODULES}
	/bin/csh :makeforce profile ${MODULES}

magicp: allp
	cd magic; make magicp

wc:	${MODULES}
	:countlines ${MODULES}

moduleNames:
	echo ${MODULES}

forceit:
	
