include ../Makefile.config

TARGETLIB  = libargtable.a
RUNTESTS   = test10 test10cc test11 test11cc
TARGETEXE  = ${RUNTESTS}

all:	obj exe

obj:	${TARGETLIB}

exe:    ${TARGETEXE}

doc:	
	${C2MAN} -k argtable.c argtable.h -o../man/man3
	${C2MAN} -Th argtable.c argtable.h -o../doc
	-cp argtable.ps ../doc/
	-cp argtable.html ../doc/
	-rm ../doc/manpages.ps; groff -man ../man/man3/*.3 > ../doc/manpages.ps

libargtable.a: argtable.c
	${CXX} argtable.c -c -o argtable.o
	${AR} $@ argtable.o
	${RANLIB} $@

test10: test10.c ${TARGETLIB}
	${CC} test10.c -largtable -L. -o $@

test10cc: test10.c ${TARGETLIB}
	${CXX} test10.c -largtable -L. -o $@

test11: test11.c ${TARGETLIB}
	${CC} test11.c -largtable -L. -o $@

test11cc: test11.c ${TARGETLIB}
	${CXX} test11.c -largtable -L. -o $@

clean:
	-rm -f ${TARGETLIB} ${TARGETEXE} *.o *~ bb.out

distclean: clean
	-rm -f ../man/man3/arg_* ../doc/arg_*.html ../doc/argtable.ps ../doc/manpages.ps ../doc/argtable.html

install:
	@echo "installing to ${INSTALL_DIR}/"
	cp -i argtable.h ${INSTALL_DIR}/include/
	cp -i libargtable.a ${INSTALL_DIR}/lib/

uninstall:
	@echo "uninstalling files from ${INSTALL_DIR}"
	-rm ${INSTALL_DIR}/include/argtable.h
	-rm ${INSTALL_DIR}/lib/libargtable.a

runtest:
	@echo "RUNNING TESTS ${RUNTESTS}"
	@for i in ${RUNTESTS} "" ; do \
              if [ "$$i" = "" ] ; then \
                 echo "ALL TESTS PASSED" ; \
              else \
                 if (./$$i>/dev/null) ; then \
                    echo "$$i OK"; \
                 else \
                    echo "$$i FAILED" ; \
                    exit 1 ; \
                 fi ; \
              fi  \
        done           
