# Master Unix makefile for the SIL C Portability library
# Steve McConnel, 24-Oct-2002

@SET_MAKE@
srcdir  = @srcdir@
VPATH   = @srcdir@
CC      = @CC@
CFLAGS  = @ANSIFLAGS@ @CFLAGS@ @DEFS@ -I. -I..
RANLIB  = @RANLIB@
INSTALL = @INSTALL@
COPY    = @COPYPROG@

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

@make_shell@ = /bin/sh

SOURCES = abs.c      bcmp.c     bcopy.c    bsearch.c  bzero.c    ccommand.c \
	  concat.c   cpystr.c   ctermid.c  ffs.c      fgetss.c   fputss.c   \
	  fsize.c    getopt.c   index.c    iscntrl.c  isgraph.c  isodigit.c \
	  ispunct.c  itoa.c     itoa8.c    itoax.c    labs.c     memccpy.c  \
	  memchr.c   memcmp.c   memcpy.c   memmove.c  memset.c   rand.c     \
	  rindex.c   strcasec.c strchr.c   strcspn.c  streq.c    stricmp.c  \
	  strlwr.c   strpbrk.c  strpos.c   strrchr.c  strrpbrk.c strrpos.c  \
	  strspn.c   strstr.c   strtok.c   strtol.c   strtoul.c  strupr.c   \
	  swapmem.c  toint.c    tolower.c  toupper.c  zapnl.c    \
          cportlib.h 

DISTFILES = $(SOURCES) Makefile.in Makefile.dj \
            Cportlib.dsp Cportlib.vcproj
TESTFILES =
#
# C portability library
#
OBJS = @LIBOBJS@ \
       cpystr.o fgetss.o streq.o zapnl.o

libcport.a:  $(OBJS)
	ar rc libcport.a $(OBJS)
	$(RANLIB) libcport.a
#
# C portability library compiled for profiling
#
OBJSP = $(addsuffix .op,$(basename @LIBOBJS@)) \
       cpystr.op fgetss.op streq.op zapnl.op

libcport_p.a:  $(OBJSP)
	ar rc libcport_p.a $(OBJSP)
	$(RANLIB) libcport_p.a
#
# ANSI C functions
#
abs.o      abs.op     : abs.c
bsearch.o  bsearch.op : bsearch.c
iscntrl.o  iscntrl.op : iscntrl.c
isgraph.o  isgraph.op : isgraph.c
ispunct.o  ispunct.op : ispunct.c
labs.o     labs.op    : labs.c
memccpy.o  memccpy.op : memccpy.c
memchr.o   memchr.op  : memchr.c
memcmp.o   memcmp.op  : memcmp.c
memcpy.o   memcpy.op  : memcpy.c
memmove.o  memmove.op : memmove.c
memset.o   memset.op  : memset.c
rand.o     rand.op    : rand.c
strchr.o   strchr.op  : strchr.c
strcspn.o  strcspn.op : strcspn.c
strpbrk.o  strpbrk.op : strpbrk.c
strrchr.o  strrchr.op : strrchr.c
strspn.o   strspn.op  : strspn.c
strtok.o   strtok.op  : strtok.c
strtol.o   strtol.op  : strtol.c
strtoul.o  strtoul.op : strtoul.c
tmpnam.o   tmpnam.op  : tmpnam.c
tolower.o  tolower.op : tolower.c
toupper.o  toupper.op : toupper.c
#
# Unix C functions
#
bcmp.o     bcmp.op    : bcmp.c
bcopy.o    bcopy.op   : bcopy.c
bzero.o    bzero.op   : bzero.c
ctermid.o  ctermid.op : ctermid.c
ffs.o      ffs.op     : ffs.c
getopt.o   getopt.op  : getopt.c
index.o    index.op   : index.c
rindex.o   rindex.op  : rindex.c
strcasec.o strcasec.op: strcasec.c
tempnam.o  tempnam.op : tempnam.c
#
# other C functions
#
ccommand.o ccommand.op: ccommand.c
concat.o   concat.op  : concat.c
cpystr.o   cpystr.op  : cpystr.c
fgetss.o   fgetss.op  : fgetss.c
fputss.o   fputss.op  : fputss.c
fsize.o    fsize.op   : fsize.c
isodigit.o isodigit.op: isodigit.c
itoa.o     itoa.op    : itoa.c
itoa8.o    itoa8.op   : itoa8.c
itoax.o    itoax.op   : itoax.c
streq.o    streq.op   : streq.c
stricmp.o  stricmp.op : stricmp.c
strlwr.o   strlwr.op  : strlwr.c
strpos.o   strpos.op  : strpos.c
strrpbrk.o strrpbrk.op: strrpbrk.c
strrpos.o  strrpos.op : strrpos.c
strstr.o   strstr.op  : strstr.c
strupr.o   strupr.op  : strupr.c
swapmem.o  swapmem.op : swapmem.c
toint.o    toint.op   : toint.c
zapnl.o    zapnl.op   : zapnl.c

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

libs: installdirs ../lib/libcport.a ../include/cportlib.h

profile_libs: installdirs ../lib/libcport_p.a ../include/cportlib.h

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

../lib/libcport.a: libcport.a
	$(INSTALL) -m 644 -c libcport.a ../lib
	$(RANLIB) ../lib/libcport.a
../lib/libcport_p.a: libcport_p.a
	$(INSTALL) -m 644 -c libcport_p.a ../lib
	$(RANLIB) ../lib/libcport_p.a
../include/cportlib.h: cportlib.h
	$(COPY) cportlib.h ../include
	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 ../lib/libcport.a ../lib/libcport_p.a ../include/cportlib.h

maintainer-clean: distclean

TAGS: $(SOURCES)
	etags $(SOURCES)

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

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

testdist: 
# leave these lines commented out as long as TESTFILES is empty!
#	for file in $(TESTFILES); do \
#	  ln $$file $(distdir) \
#	    || { echo copying $$file instead; $(COPY) $$file $(distdir);}; \
#	done

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

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