CPP = cc -E
MAKE = make
#Note: an alternative is  CPP = /lib/cpp

all: Makefile.use doall doc.dist

doall:
	$(MAKE) -f Makefile.use ${MFLAGS} all

clean:
	rm -f *.ols *~ *.lst

priv:
	chmod 755 map
	chown root map
	chmod u+s map

map: Makefile.use domap

domap:
	$(MAKE) -f Makefile.use ${MFLAGS} map


config.h:
	sh config



SUPPORT = $(DOCS) $(CONTROLS) $(DATAFILES)

DOCS =		Copyright Intro ReadMe Status ToDo Updates

CONTROLS =	Makefile Makefile.in

DATAFILES =	map.cf map.PS.header Hosts mib.mib \
		LCS.Geometry AI.Geometry MIT.Geometry NEAR.Geometry

NETSRC = icmp.h icmp.c chstat.c chopen.c find_file.c getline.c \
		new_string.c upcase.c

CONFIGS = config config.default config.SNMP config.LCS

HDRS = common.h map.h cmd.h debug.h $(CONFIGS)

SRC = map.c version.c snmp.c cmd.c debug.c X10.c X11.c ps.c tek.c


#
# "Distribute" copies of supporting documents, i.e. keep anon. ftp up to date
doc.dist:	$(DOCS)
	cp $(DOCS) ftp
	@echo "Marker for make, do not molest." >doc.dist


#
# Install in common directory
install: domap $(DATAFILES)
	-cp map $(DATAFILES) /usr/lib/nets


#
# Make a full release for distribution
release: $(SUPPORT) $(NETSRC) $(HDRS) $(SRC)
	tr '"' ' ' <version.c | awk '{print $$5}' >version.nbr
	@echo "Version number of this release is `cat version.nbr`"
	echo 'char *version = "Version '`cat version.nbr`'";' >version.c
	rm -f release
	mkdir release
	cp $(SUPPORT) $(NETSRC) $(HDRS) $(SRC) release
	ln -s ../aux release
	mv release V`cat version.nbr`
	tar chBf - V`cat version.nbr` | compress -v >release
	cp release ftp/map.V`cat version.nbr`
	make doc.dist
	@echo Sources in \"V`cat version.nbr`'", compressed tar in "release" and on anonymous FTP.
	@echo Now making and installing executable of released version.'
	${MAKE} ${MFLAGS} install
	@echo '++++++  Remember to "make priv" to set suid bit.  ++++++'
	echo 'char *version = "Version '`awk 'BEGIN{FS=".";OFS="."}{$$NF+=1;print}' version.nbr`' Experimental";' >version.c
	rm version.nbr


#
# Make a test release, this is just like above but doesn't affect version
test: $(SUPPORT) $(NETSRC) $(HDRS) $(SRC)
	mkdir test
	cp $(SUPPORT) $(NETSRC) $(HDRS) $(SRC) test
	tar chBf - test | compress -v >test.Z
	@echo 'Compressed tar in "test.Z", removing temp dir.'
	rm -r test



# If you have a problem with cc -E here, changing
# the definition of CPP above may fix it.
Makefile.use:	Makefile.in config.h
	rm -f Makefile.use
	ln Makefile.in Makefile.c
	echo '# This is an automatically generated file, see Makefile and Makefile.in' > Makefile.use
	$(CPP) Makefile.c | \
		sed -e 's/^#.*//' -e 's/^[ \f	]$$//' -e 's/^ /	/' | \
		sed -n -e '/^...*$$/p' >> Makefile.use
	rm -f Makefile.c


# Make a tags table for emacs.
TAGS:	$(HDRS) $(NETSRC) $(SRC)
	etags $(HDRS) $(NETSRC) $(SRC)
