# Master Unix makefile for the INTERGEN program
# Steve McConnel,  7-Oct-2002

@SET_MAKE@
srcdir      = @srcdir@
VPATH       = @srcdir@
CC          = @CC@
YACC        = @YACC@
LEX         = @LEX@
CFLAGS      = @ANSIFLAGS@ @CFLAGS@ @DEFS@ -I. -I.. -I../include
RANLIB      = @RANLIB@
INSTALL     = @INSTALL@
COPY        = @COPYPROG@
prefix      = @prefix@
exec_prefix = @exec_prefix@

.SUFFIXES: .op
.c.op:
	$(CC) $(CFLAGS) -pg -c -o $@ $<

@make_shell@ = /bin/sh
BINDIR = $(exec_prefix)/bin

SOURCES=intergen.c version.h

DISTFILES = $(SOURCES) Makefile.in Makefile.dj \
            readme.1st Intergen.dsp Intergen.vcproj
TESTFILES = check.bat
TESTS     = ae ck cq cz hg sb
TESTEXTS  = test.aaa test.iia test.iin outx.ctl
#
#  INTERGEN program
#
LIBS = ../lib/libopac.a ../lib/libcport.a
OBJ  = intergen.o

intergen: $(OBJ) $(LIBS)
	$(CC) -o intergen $(OBJ) $(LIBS) @LIBS@
#
#  INTERGEN program compiled for profiling
#
LIBSP = ../lib/libopac_p.a ../lib/libcport_p.a
OBJP  = intergen.op

intergen_p: $(OBJP) $(LIBSP)
	$(CC) -pg -o intergen_p $(OBJP) $(LIBSP) @LIBS@
#
#  sources unique to INTERGEN
#
intergen.o  intergen.op:  intergen.c version.h

#############################################################################

libs profile_libs: installdirs

installdirs:
	@if [ ! -d $(BINDIR) ];  then mkdir $(BINDIR);  fi
	@if [ ! -d ../lib ];     then mkdir ../lib;     fi
	@if [ ! -d ../include ]; then mkdir ../include; fi

all: libs intergen

profile: profile_libs intergen_p

install: all
	$(INSTALL) -s intergen $(BINDIR)

uninstall:
	rm -f $(BINDIR)/intergen

check: intergen
	@(Prev=none; cd test; \
	for t in $(TESTS); do \
	    case $$t in \
		ck | hg | sb) TXTCTL=-t\ $${t}outx.ctl ;; \
		*)            TXTCTL="" ;; \
	    esac; \
	    cd $$t; rm -f $${t}test.da $${t}test.dn ; \
	    ../../intergen -qa $$TXTCTL -i $${t}test.aaa -o $${t}test.ita; \
	    if (diff -b $${t}test.iia $${t}test.ita >$${t}test.da) then \
		rm $${t}test.da $${t}test.ita; \
		fi; \
	    ../../intergen -qan $$TXTCTL -i $${t}test.aaa -o $${t}test.itn; \
	    if (diff -b $${t}test.iin $${t}test.itn >$${t}test.dn) then \
		rm $${t}test.dn $${t}test.itn; \
		fi; \
	    if [ -f $${t}test.da -o -f $${t}test.dn ]; then \
		if [ "$$Prev" = "good" ]; then echo ; fi; \
		if [ "$$Prev" != "bad" ]; then \
			echo -n ':-(' intergen failed test; fi; \
		Prev=bad; \
	    else \
		if [ "$$Prev" =  "bad"  ]; then echo ; fi; \
		if [ "$$Prev" != "good" ]; then \
			echo -n intergen passed test; fi; \
		Prev=good; \
	    fi; \
	    echo -n ' '$$t; \
	    cd ..; \
	done; \
	if [ "$Prev" != "none" ]; then echo ; fi; \
	)

mostlyclean:
	rm -f *.o *.op *~

clean: mostlyclean
	rm -f *.aux *.log *.toc
	rm -f *.cp *.cps *.fn *.fns *.ky *.kys *.pg *.pgs *.tp *.tps *.vr *.vrs

distclean: clean
	rm -f intergen intergen_p Makefile TAGS *.dvi

maintainer-clean: distclean

TAGS: $(SOURCES)
	etags $(SOURCES)

doc dvi html info:
	(cd ../doc; $(MAKE) intergen$@)

dist: $(DISTFILES)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir) \
	    || { echo copying $$file instead; $(COPY) $$file $(distdir);}; \
	done

testdist: 
	mkdir $(distdir)/test
	for file in $(TESTFILES); do \
	  ln $$file $(distdir) \
	    || { echo copying $$file instead; $(COPY) $$file $(distdir);}; \
	done
	for dir in $(TESTS); do \
	    mkdir $(distdir)/test/$$dir; \
	    for f in $(TESTEXTS); do \
		if [ -f test/$$dir/$$dir$$f ]; then \
		    ln test/$$dir/$$dir$$f $(distdir)/test/$$dir || \
		      { echo copying test/$$dir/$$dir$$f instead; \
		  $(COPY) test/$$dir/$$dir$$f $(distdir)/test/$$dir;}; \
		fi; \
	    done; \
	    for f in test.sh test.bat; do \
		if [ -f test/$$dir/$$f ]; then \
		    ln test/$$dir/$$f $(distdir)/test/$$dir || \
		      { echo copying test/$$dir/$$f instead; \
			$(COPY) test/$$dir/$$f $(distdir)/test/$$dir;}; \
		fi; \
	    done; \
	done

############################################################################

.PHONY: all check clean dist distclean doc dvi html info install \
        libs maintainer-clean mostlyclean profile profile_libs testdist \
        uninstall installdirs
