# autoconf Makefile.in for aatar

PREFIX= /usr/pkg
CFLAGS= -g -O2

PROG= aatar
SRCS= aa.c missing.c main.c
OBJS= aa.o missing.o main.o

WARNINGS= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
WARNINGS+= -Wno-sign-compare -Wno-traditional -Wno-uninitialized -Wreturn-type
WARNINGS+= -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -std=c99  -Werror
CPPFLAGS+= ${WARNINGS} -DPREFIX=\""${PREFIX}\""
LDADD+= -lz -lbz2
MAN= aatar.1

${PROG}: ${OBJS}
	${CC} ${LDFLAGS} ${OBJS} ${LDADD} -o ${PROG}

clean cleandir:
	rm -f *.o
	rm -f a.out [Ee]rrs mklog core *.core .gdbinit ${PROG}
	rm -f .depend aa.d main.d tags 

install: ${PROG}
	${INSTALL} ${PROG} ${PREFIX}/bin
	${INSTALL} ${MAN} ${PREFIX}/man/man1/

dist:
	cd .. && tar cvzf archangel.tar.gz archangel0
	cd .. && archangel0/aatar cvf archangel.aa archangel0

test: ${PROG}
	@echo "No news is good news"
	@cd tests && rm -f arch.aa O && ln -s Overview O
	@chmod 600 tests/Overview
	@echo "1. Creating archive"
	@cd tests && ../${PROG} -cf arch.aa Makefile Overview O > out.1 2>&1
	@-diff tests/expected.1 tests/out.1
	@echo "2. Listing archive"
	@cd tests && ../${PROG} -tf arch.aa > out.2 2>&1
	@-diff tests/expected.2 tests/out.2
	@echo "3. Verbosely listing archive"
	@cd tests && ../${PROG} -tvf arch.aa | awk '{ print $$1 " " $$2 " " $$3 " " $$4 " " $$5 " " $$9}' > out.3 2>&1
	@-diff tests/expected.3 tests/out.3
	@echo "4. Extracting from archive"
	@cd tests && mkdir t1 && cd t1 && ../../${PROG} -xvf ../arch.aa > ../out.4 2>&1
	@-diff tests/expected.4 tests/out.4
	@echo "5. Listing extraction from archive"
	@cd tests/t1 && ls -al | awk '$$1 == "total" { next }{ print $$1 " " $$2 " " $$3 " " $$4 " " $$9}' > ../out.5 2>&1
	@-diff tests/expected.5 tests/out.5
	@cd tests && rm -rf t1
	@echo "6. Listing archive from stdin"
	@cd tests && ../${PROG} -tvf - < arch.aa | awk '{ print $$1 " " $$2 " " $$3 " " $$4 " " $$5 " " $$9}' > out.6 2>&1
	@-diff tests/expected.6 tests/out.6
	@echo "7. Listing archive with no '-' for options from stdin"
	@cd tests && ../${PROG} tvf - < arch.aa | awk '{ print $$1 " " $$2 " " $$3 " " $$4 " " $$5 " " $$9}' > out.7 2>&1
	@-diff tests/expected.7 tests/out.7
	@echo "8. Taking file list from a file"
	@echo "tests/Makefile" > tests/T
	@echo "tests/O" >> tests/T
	@./${PROG} -cf tests/arch2.aa -T tests/T
	@./${PROG} tvf tests/arch2.aa | awk '{ print $$1 " " $$2 " " $$3 " " $$4 " " $$5 " " $$9}' > tests/out.8 2>&1
	@-diff tests/expected.8 tests/out.8
	@echo "9. Testing list from file and stdin"
	@cp tests/Makefile tests/M2
	@cd tests && ../${PROG} -cf arch3.aa CVS M2 Makefile Overview
	@./${PROG} tvvf tests/arch3.aa > tests/expected.9 2>&1
	@./${PROG} tvvf - < tests/arch3.aa > tests/out.9 2>&1
	@diff tests/expected.9 tests/out.9
	@echo "10. Testing -C arg"
	@cd tests && ../${PROG} -cf arch3.aa CVS M2 Makefile Overview
	@./${PROG} cf tests/arch4.aa -C tests CVS M2 Makefile Overview
	@./${PROG} tvvf tests/arch4.aa > tests/expected.A 2>&1
	@./${PROG} tvvf - < tests/arch4.aa > tests/out.A 2>&1
	@diff tests/expected.A tests/out.A
	@rm -f tests/expected.[9A] tests/out.* tests/arch.aa tests/O tests/T tests/arch?.aa
	@echo "All tests completed"
