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

@SET_MAKE@
srcdir      = @srcdir@
VPATH       = @srcdir@
CC          = @CC@
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 = ktagger.c version.h
DISTFILES = $(SOURCES) Makefile.in Makefile.dj \
            Ktagger.dsp Ktagger.vcproj
TESTFILES = check.bat
ENGFILES = engtdf.ctl eng.ttt engsgml.ctl eng.sss engsgml2.ctl eng.ss2 \
           engsfm.ctl eng.sff eng.in test.bat \
           mac-tdf.ctl mac-sgml.ctl mac-sgm2.ctl mac-sfm.ctl
#
#  KTAGGER program
#
OBJ =ktagger.o
LIBS=../lib/libkimmo.a ../lib/libpatr.a ../lib/libcmd.a \
     ../lib/libopac.a ../lib/libcport.a

ktagger: $(OBJ) $(LIBS)
	$(CC) -o ktagger $(OBJ) $(LIBS) @LIBS@
#
#  KTAGGER program compiled for profiling
#
LIBSP=../lib/libkimmo_p.a ../lib/libpatr_p.a ../lib/libcmd_p.a \
      ../lib/libopac_p.a ../lib/libcport_p.a
OBJP =ktagger.op

ktagger_p: $(OBJP) $(LIBSP)
	$(CC) -pg -o ktagger_p $(OBJP) $(LIBSP) @LIBS@
#
#  sources unique to KTAGGER
#
ktagger.o ktagger.op: ktagger.c version.h ../include/kimmo.h ../include/patr.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 ktagger

profile: profile_libs ktagger_p

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

uninstall:
	rm -f $(BINDIR)/ktagger

check: ktagger
	@(Prev=none; \
	cd test/eng; rm -f eng.dif; \
	../../ktagger -x engtdf.ctl -i eng.in -o eng.tdf 2>/dev/null; \
	if (cmp eng.tdf eng.ttt); then \
	    rm -f eng.tdf; \
	    if [ "$$Prev"  = "bad"  ]; then echo ; fi; \
	    if [ "$$Prev" != "good" ]; then echo -n ktagger passed test/eng; fi; \
	    Prev=good; \
	else \
	    diff -c eng.tdf eng.ttt >>eng.dif; \
	    if [ "$$Prev" = "good" ]; then echo ; fi; \
	    if [ "$$Prev" != "bad" ]; then echo -n ':-(' ktagger failed test/eng; fi; \
	    Prev=bad; \
	fi; \
	echo -n ' 'tdf; \
	../../ktagger -x engsgml.ctl -i eng.in -o eng.sgm 2>/dev/null; \
	if (cmp eng.sgm eng.sss); then \
	    rm -f eng.sgm; \
	    if [ "$$Prev"  = "bad"  ]; then echo ; fi; \
	    if [ "$$Prev" != "good" ]; then echo -n ktagger passed test/eng; fi; \
	    Prev=good; \
	else \
	    diff -c eng.sgm eng.sss >>eng.dif; \
	    if [ "$$Prev" = "good" ]; then echo ; fi; \
	    if [ "$$Prev" != "bad" ]; then echo -n ':-(' ktagger failed test/eng; fi; \
	    Prev=bad; \
	fi; \
	echo -n ' 'sgml-1; \
	../../ktagger -x engsgml2.ctl -i eng.in -o eng.sg2 2>/dev/null; \
	if (cmp eng.sg2 eng.ss2); then \
	    rm -f eng.sg2; \
	    if [ "$$Prev"  = "bad"  ]; then echo ; fi; \
	    if [ "$$Prev" != "good" ]; then echo -n ktagger passed test/eng; fi; \
	    Prev=good; \
	else \
	    diff -c eng.sg2 eng.ss2 >>eng.dif; \
	    if [ "$$Prev" = "good" ]; then echo ; fi; \
	    if [ "$$Prev" != "bad" ]; then echo -n ':-(' ktagger failed test/eng; fi; \
	    Prev=bad; \
	fi; \
	echo -n ' 'sgml-2; \
	../../ktagger -x engsfm.ctl -i eng.in -o eng.sfm 2>/dev/null; \
	if (cmp eng.sfm eng.sff); then \
	    rm -f eng.sfm; \
	    if [ "$$Prev"  = "bad"  ]; then echo ; fi; \
	    if [ "$$Prev" != "good" ]; then echo -n ktagger passed test/eng; fi; \
	    Prev=good; \
	else \
	    diff -c eng.sfm eng.sff >>eng.dif; \
	    if [ "$$Prev" = "good" ]; then echo ; fi; \
	    if [ "$$Prev" != "bad" ]; then echo -n ':-(' ktagger failed test/eng; fi; \
	    Prev=bad; \
	fi; \
	echo -n ' 'sfm; \
	if [ "$Prev" != "none" ]; then echo ; fi; \
	Prev=none; \
	cd ../..;  \
	)

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

clean: mostlyclean

distclean: clean
	rm -f ktagger ktagger_p Makefile TAGS

maintainer-clean: distclean

TAGS: $(SOURCES)
	etags $(SOURCES)

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

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
	mkdir $(distdir)/test/eng
	for f in $(ENGFILES); do \
	    if [ -f test/eng/$$f ]; then \
		ln test/eng/$$f $(distdir)/test/eng || \
		  { echo copying test/eng/$$f instead; \
	    	$(COPY) test/eng/$$f $(distdir)/test/eng;}; \
	    fi; \
	done

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

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