# Master Unix makefile for the CMD library
# 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@

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

@make_shell@ = /bin/sh

SOURCES = cmd.c      cmdcd.c    cmddata.c  cmddir.c   cmdedit.c  cmdlog.c   \
          cmdsig.c   cmdtime.c  messages.c setcmdfi.c cmdsys.c   \
          wanthelp.c cmd.h
DISTFILES = $(SOURCES) Makefile.in Makefile.dj \
            Cmdlib.dsp Cmdlib.vcproj
TESTFILES = sample.c
#
#  CMD function library
#
OBJ=cmd.o      cmdcd.o    cmddir.o   cmdedit.o  cmdsys.o   cmdlog.o   \
    cmdsig.o   cmdtime.o  setcmdfi.o wanthelp.o cmddata.o  messages.o 

libcmd.a: $(OBJ)
	rm -f libcmd.a
	ar rc libcmd.a $(OBJ)
	$(RANLIB) libcmd.a
#
#  CMD function library compiled for profiling
#
OBJP=cmd.op      cmdcd.op    cmddir.op   cmdedit.op  cmdsys.op   cmdlog.op  \
     cmdsig.op   cmdtime.op  setcmdfi.op wanthelp.op cmddata.op  messages.op 

libcmd_p.a: $(OBJP)
	rm -f libcmd_p.a
	ar rc libcmd_p.a $(OBJP)
	$(RANLIB) libcmd_p.a
#
#  sources shared as a library
#
cmd.o      cmd.op:      cmd.c      cmd.h
cmdcd.o    cmdcd.op:    cmdcd.c    cmd.h
cmddata.o  cmddata.op:  cmddata.c  cmd.h
cmddir.o   cmddir.op:   cmddir.c   cmd.h
cmdedit.o  cmdedit.op:  cmdedit.c  cmd.h
cmdlog.o   cmdlog.op:   cmdlog.c   cmd.h
cmdsig.o   cmdsig.op:   cmdsig.c   cmd.h
cmdsys.o   cmdsys.op:   cmdsys.c   cmd.h
cmdtime.o  cmdtime.op:  cmdtime.c  cmd.h
messages.o messages.op: messages.c cmd.h
setcmdfi.o setcmdfi.op: setcmdfi.c cmd.h
wanthelp.o wanthelp.op: wanthelp.c cmd.h

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

libs: installdirs ../lib/libcmd.a ../include/cmd.h

profile_libs: installdirs ../lib/libcmd_p.a ../include/cmd.h

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

../lib/libcmd.a: libcmd.a
	$(INSTALL) -m 644 -c libcmd.a ../lib
	$(RANLIB) ../lib/libcmd.a
../lib/libcmd_p.a: libcmd_p.a
	$(INSTALL) -m 644 -c libcmd_p.a ../lib
	$(RANLIB) ../lib/libcmd_p.a
../include/cmd.h: cmd.h
	$(COPY) cmd.h ../include
	chmod u+w $@

all install: libs

profile: profile_libs

uninstall:

check: sample
#
#  build the sample program
#
LIBS=libcmd.a ../lib/libopac.a ../lib/libcport.a
sample: sample.o $(LIBS)
	$(CC) -o sample sample.o $(LIBS) @LIBS@
sample.o: sample.c

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

clean: mostlyclean
	rm -f lib*.a

distclean: clean
	rm -f sample Makefile TAGS
	rm -f ../lib/libcmd.a ../lib/libcmd_p.a ../include/cmd.h

maintainer-clean: distclean

TAGS: $(SOURCES)
	etags $(SOURCES)

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

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

testdist: 
	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
