# Master Unix makefile for the OPAC library
# Steve McConnel, 24-Oct-2002
#
# additional possible definitions:
# Hardware
# -DRISC   = RISC CPU such as SPARC
#	chooses file I/O approach used in record.c (major timing difference)
#MORECFLAGS=-DRISC
MORECFLAGS=

@SET_MAKE@
srcdir    = @srcdir@
VPATH     = @srcdir@
CC        = @CC@
CFLAGS    = @CFLAGS@ @DEFS@ $(MORECFLAGS) -I. -I.. -I../include
ANSIFLAGS = @ANSIFLAGS@
RANLIB    = @RANLIB@
INSTALL   = @INSTALL@
COPY      = @COPYPROG@

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

@make_shell@ = /bin/sh

SOURCES = add_sl.c   adjfname.c ambprog.c  appnd_sl.c cat_sl.c   tokenize.c \
          change.c   copy_sl.c  dtbin.c    dtbout.c   equal_sl.c equiv_sl.c \
          erasecha.c errcheck.c free_sl.c  free_wt.c  isolatew.c numbrmsg.c \
          loadintx.c loadoutx.c membr_sl.c merge_sl.c allocmem.c myctype.c  \
          promptus.c readfiel.c readline.c record.c   resetxtc.c rmstr_sl.c \
          rpterror.c rptmessg.c rptprgrs.c safeexit.c senttemp.c size_sl.c  \
          sqz_sl.c   strcla.c   textin.c   textout.c  trie.c     trimspac.c \
          unlst_sl.c updat_sl.c write_sl.c matchbeg.c matchend.c ufopen.c   \
          fulldisk.c free_ct.c  write_ct.c wordanal.c dynstr.c   cma.c      \
          change.h   allocmem.h opaclib.h  record.h   rpterror.h strclass.h \
          strlist.h  template.h textctl.h  trie.h     dynstr.h   

DISTFILES = $(SOURCES) Makefile.in Makefile.dj \
            Opaclib.dsp Opaclib.vcproj
TESTFILES =
#
#  OPAC function library
#
OBJ = myctype.o  allocmem.o dtbin.o    free_wt.o  resetxtc.o tokenize.o \
      record.o   strcla.o   isolatew.o change.o   dtbout.o   textin.o   \
      trie.o     promptus.o textout.o  loadintx.o loadoutx.o add_sl.o   \
      appnd_sl.o cat_sl.o   copy_sl.o  equal_sl.o equiv_sl.o free_sl.o  \
      membr_sl.o merge_sl.o rmstr_sl.o size_sl.o  sqz_sl.o   write_sl.o \
      rpterror.o rptmessg.o rptprgrs.o erasecha.o readfiel.o errcheck.o \
      numbrmsg.o adjfname.o ambprog.o  unlst_sl.o updat_sl.o safeexit.o \
      senttemp.o readline.o trimspac.o matchbeg.o matchend.o ufopen.o   \
      fulldisk.o free_ct.o  write_ct.o wordanal.o dynstr.o   

libopac.a: $(OBJ)
	rm -f libopac.a
	ar rc libopac.a $(OBJ)
	$(RANLIB) libopac.a
#
#  OPAC function library compiled for profiling
#
OBJP= myctype.op  allocmem.op dtbin.op    free_wt.op  resetxtc.op tokenize.op \
      record.op   strcla.op   isolatew.op change.op   dtbout.op   textin.op   \
      trie.op     promptus.op textout.op  loadintx.op loadoutx.op add_sl.op   \
      appnd_sl.op cat_sl.op   copy_sl.op  equal_sl.op equiv_sl.op free_sl.op  \
      membr_sl.op merge_sl.op rmstr_sl.op size_sl.op  sqz_sl.op   write_sl.op \
      rpterror.op rptmessg.op rptprgrs.op erasecha.op readfiel.op errcheck.op \
      numbrmsg.op adjfname.op ambprog.op  unlst_sl.op updat_sl.op safeexit.op \
      senttemp.op readline.op trimspac.op matchbeg.op matchend.op ufopen.op   \
      fulldisk.op free_ct.op  write_ct.op wordanal.op dynstr.op   

libopac_p.a: $(OBJP)
	rm -f libopac_p.a
	ar rc libopac_p.a $(OBJP)
	$(RANLIB) libopac_p.a
#
#  sources shared as a library
#
change.o   change.op  : change.c   allocmem.h textctl.h strclass.h strlist.h \
                                   change.h rpterror.h
myctype.o  myctype.op : myctype.c  textctl.h allocmem.h
allocmem.o allocmem.op: allocmem.c allocmem.h rpterror.h
dtbin.o    dtbin.op   : dtbin.c    template.h strlist.h record.h allocmem.h
free_wt.o  free_wt.op : free_wt.c  template.h strlist.h allocmem.h
isolatew.o isolatew.op: isolatew.c
record.o   record.op  : record.c   allocmem.h record.h
strcla.o   strcla.op  : strcla.c   allocmem.h textctl.h rpterror.h strclass.h \
                                   strlist.h
textin.o   textin.op  : textin.c   allocmem.h textctl.h template.h strlist.h \
                                   change.h
dtbout.o   dtbout.op  : dtbout.c   strlist.h template.h
myctype.o  myctype.op : myctype.c  textctl.h allocmem.h rpterror.h
add_sl.o   add_sl.op  : add_sl.c   strlist.h allocmem.h
appnd_sl.o appnd_sl.op: appnd_sl.c strlist.h allocmem.h
cat_sl.o   cat_sl.op  : cat_sl.c   strlist.h allocmem.h
copy_sl.o  copy_sl.op : copy_sl.c  strlist.h allocmem.h
equal_sl.o equal_sl.op: equal_sl.c strlist.h
equiv_sl.o equiv_sl.op: equiv_sl.c strlist.h
free_sl.o  free_sl.op : free_sl.c  strlist.h allocmem.h
membr_sl.o membr_sl.op: membr_sl.c strlist.h
merge_sl.o merge_sl.op: merge_sl.c strlist.h allocmem.h
rmstr_sl.o rmstr_sl.op: rmstr_sl.c strlist.h allocmem.h
size_sl.o  size_sl.op : size_sl.c  strlist.h
sqz_sl.o   sqz_sl.op  : sqz_sl.c   strlist.h allocmem.h
write_sl.o write_sl.op: write_sl.c strlist.h
unlst_sl.o unlst_sl.op: unlst_sl.c strlist.h allocmem.h
updat_sl.o updat_sl.op: updat_sl.c strlist.h allocmem.h
trie.o     trie.op    : trie.c     allocmem.h trie.h rpterror.h
textout.o  textout.op : textout.c  allocmem.h textctl.h template.h strlist.h \
                                   change.h
loadintx.o loadintx.op: loadintx.c allocmem.h textctl.h rpterror.h strclass.h \
                                   strlist.h record.h template.h change.h
resetxtc.o resetxtc.op: resetxtc.c allocmem.h textctl.h rpterror.h strclass.h \
                                   strlist.h record.h template.h change.h
rpterror.o rpterror.op: rpterror.c rpterror.h
rptmessg.o rptmessg.op: rptmessg.c rpterror.h
numbrmsg.o numbrmsg.op: numbrmsg.c rpterror.h
rptprgrs.o rptprgrs.op: rptprgrs.c
erasecha.o erasecha.op: erasecha.c
readfiel.o readfiel.op: readfiel.c allocmem.h
readline.o readline.op: readline.c allocmem.h
adjfname.o adjfname.op: adjfname.c allocmem.h
ambprog.o  ambprog.op : ambprog.c
trimspac.o trimspac.op: trimspac.c
safeexit.o safeexit.op: safeexit.c
senttemp.o senttemp.op: senttemp.c template.h allocmem.h rpterror.h
matchbeg.o matchbeg.op: matchbeg.c
matchend.o matchend.op: matchend.c
fulldisk.o fulldisk.op: fulldisk.c
tokenize.o tokenize.op: tokenize.c
free_ct.o  free_ct.op:  free_ct.c  record.h allocmem.h
write_ct.o write_ct.op: write_ct.c record.h
wordanal.o wordanal.op: wordanal.c template.h textctl.h change.h strclass.h \
                                   strlist.h allocmem.h
dynstr.o   dynstr.op:   dynstr.c   dynstr.h allocmem.h
#
# these files don't like pedantically strict ANSI C compliance
#
promptus.o:   promptus.c
	$(CC) $(CFLAGS) -c -o $@ $<
promptus.op:  promptus.c
	$(CC) $(CFLAGS) -pg -c -o $@ $<

errcheck.o: errcheck.c rpterror.h
	$(CC) $(CFLAGS) -c -o $@ $<
errcheck.op: errcheck.c rpterror.h
	$(CC) $(CFLAGS) -pg -c -o $@ $<

ufopen.o: ufopen.c
	$(CC) $(CFLAGS) -c -o $@ $<
ufopen.op: ufopen.c
	$(CC) $(CFLAGS) -pg -c -o $@ $<
#
# program for distilling memory allocation trace files
# (cma = Check Memory Allocations)
#
cma: cma.c
	$(CC) $(CFLAGS) -o cma cma.c

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

headers: installdirs ../include/allocmem.h ../include/change.h \
      ../include/dynstr.h ../include/opaclib.h ../include/record.h \
      ../include/rpterror.h ../include/strclass.h ../include/strlist.h \
      ../include/template.h ../include/textctl.h ../include/trie.h

libs:         headers ../lib/libopac.a

profile_libs: headers ../lib/libopac_p.a

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

../lib/libopac.a: libopac.a
	$(INSTALL) -m 644 -c libopac.a ../lib
	$(RANLIB) ../lib/libopac.a
../lib/libopac_p.a: libopac_p.a
	$(INSTALL) -m 644 -c libopac_p.a ../lib
	$(RANLIB) ../lib/libopac_p.a

../include/allocmem.h: allocmem.h
	$(COPY) allocmem.h ../include/allocmem.h
	chmod u+w $@
../include/change.h: change.h
	$(COPY) change.h   ../include/change.h  
	chmod u+w $@
../include/dynstr.h: dynstr.h
	$(COPY) dynstr.h   ../include/dynstr.h  
	chmod u+w $@
../include/opaclib.h: opaclib.h
	$(COPY) opaclib.h  ../include/opaclib.h 
	chmod u+w $@
../include/record.h: record.h
	$(COPY) record.h   ../include/record.h  
	chmod u+w $@
../include/rpterror.h: rpterror.h
	$(COPY) rpterror.h ../include/rpterror.h
	chmod u+w $@
../include/strclass.h: strclass.h
	$(COPY) strclass.h ../include/strclass.h
	chmod u+w $@
../include/strlist.h: strlist.h
	$(COPY) strlist.h  ../include/strlist.h 
	chmod u+w $@
../include/template.h: template.h
	$(COPY) template.h ../include/template.h
	chmod u+w $@
../include/textctl.h: textctl.h
	$(COPY) textctl.h  ../include/textctl.h 
	chmod u+w $@
../include/trie.h: trie.h
	$(COPY) trie.h     ../include/trie.h    
	chmod u+w $@

all install: libs

profile: profile_libs

uninstall:

check:

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

clean: mostlyclean
	rm -f lib*.a

distclean: clean
	rm -f Makefile TAGS
	rm -f ../include/allocmem.h ../include/change.h   ../include/opaclib.h
	rm -f ../include/record.h   ../include/rpterror.h ../include/strclass.h
	rm -f ../include/strlist.h  ../include/template.h ../include/textctl.h
	rm -f ../include/trie.h     ../lib/libopac.a ../lib/libopac_p.a

maintainer-clean: distclean

TAGS: $(SOURCES)
	etags $(SOURCES)

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

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

testdist: 

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

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