# Makefile
# Neil Moore
# 7 October 1998

.PHONY: depend doc clean veryclean tar all

CXX = g++
GENDEPS = g++ -MM
NROFF = groff

# We are assuming gcc 2.8.0 or higher (including egcs).
CXXFLAGS = -g -O2 -Wall -fexceptions -pedantic -ansi

# Flags that should be used for linking, but not for compiling.
LDFLAGS =

# Various files.
HDRS = util.h Properties.h
SRCS = $(HDRS:.h=.cc) proptest.cc
OBJS = $(SRCS:.cc=.o)
MISC = Properties.man proptest.prop proptest.txt index.html

all: proptest
tar: Properties.tar.gz

proptest: $(OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^

doc: Properties.ps

clean:
	-rm *.o proptest
	-rm -rf Properties

veryclean: clean
	-rm Properties.tar.gz Properties.ps

Properties.tar.gz: $(SRCS) $(HDRS) $(MISC) Makefile 
	-mkdir Properties/
	cp -f $(SRCS) $(HDRS) $(MISC) Makefile Properties/
	tar cf Properties.tar Properties
	gzip -f Properties.tar
	rm -rf Properties/

####### Implicit rules

.SUFFIXES: .cc .ps .man

.cc.o:
	$(CXX) -c $(CXXFLAGS) $<

.man.ps:
	$(NROFF) -Tps -man $< > $@

####### Dependency generation

.PHONY: depend

depend:
	cp -f Makefile Makefile.bak
	$(GENDEPS) $(SRCS) > depend.make
	echo '/^# Do not delete this line/ +' > edscript
	echo '.,$$d' >> edscript
	echo 'r depend.make' >> edscript
	echo 'w' >> edscript
	ed Makefile < edscript
	rm edscript depend.make

# At least one line must follow the next.
# Do not delete this line---make depend depends on it.
util.o: util.cc util.h
Properties.o: Properties.cc Properties.h util.h
proptest.o: proptest.cc Properties.h util.h
