include Makefile.inc

srcdir= @srcdir@

INSTALL= @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
#LIBEFENCE = -lefence

GTAR=@GTAR@
POSIXSHELL=@POSIXSHELL@
DO_DEBUG = @DO_DEBUG@
DO_UM_RPM = @DO_UM_RPM@
CCDEPMODE = @CCDEPMODE@

CC = @CC@
CXX = @CXX@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
MAKE=@MAKE@

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
datadir=@datadir@
mandir=@mandir@
mansubdir=@mansubdir@

#DEBUG = -g
installprefix=$(ROOT)

#LIBEFENCE = -lefence


################################### Leave this stuff alone

### These are variables meant to be exported

VPATH = $(srcdir)
WARNINGS = 

BINDIR=$(prefix)/bin
RPMBINDIR=$(subst usr/bin,bin,$(BINDIR))
MANDIR1=$(prefix)/man/man1
MANDIR5=$(prefix)/man/man5
MANDIR8=$(prefix)/man/man8
MANDIR=$(prefix)/man/man8
LIBDIR=$(libdir)
INCDIR=$(prefix)/include
ETCDIR=$(ROOT)/etc

# -----------------------------------------------------------------------

SUBDIRS = swsupplib swstructlib swprogs tests/devel doc
CSUBDIRS = swsupplib 
CPPSUBDIRS = swstructlib swprogs tests/devel doc
INSTSUBDIRS = lib @PO@
OTHERSUBDIRS =
OBJS =
PROGS =
LIBS = @LIBS@
LIB=
LOADLIBES =

SOURCES = $(subst .o,.c,$(OBJS))

TARGET=depend everything

all:
	$(MAKE) $(TARGET)
	@echo ""
	@echo "Testing is recommended (after installing)."
	@echo "      make test"
	@echo "      make testall   requires a Ext2, (Old) Unix, or"
	@echo "        Ext3 (with b-tree indexes turned off) file system"
	@echo "        due to directory entry ordering dependencies"
	@echo ""

test:
	$(MAKE) $(TARGET) testsuite1

testall:
	$(MAKE) $(TARGET) testsuite1 testsuite2

everything: make-subdirs $(PROGS) $(LIB) 

showtests:
	$(MAKE) -s showtests_

showtests_:
	echo "shorttest     test the md5 and sha1 digest code (short)."
	echo "shorttest2    test the md5 and sha1 digest code (short)."
	echo "digesttest    test the md5 and sha1 digest code (5 min.)."
	echo "digesttest2   test the md5 and sha1 digest code (5 min.)."
	echo "parsertest    parser regression test008 (short)."	
	echo "parsertest2   parser regression test009 (short)."	
	echo "archivetest0  run the make_archive script (short)."	
	echo "swigntest1    swign regression test024, asks for passphrase  (short)."	
	echo "swigntest2    swign regression test026 (short)."	
	echo "swigntest3    swign regression test027 (short)."	
	echo "swigntest4    swign regression test028 (short)."	

testsuite1: \
	testsuite1info \
	shorttest \
	shorttest2 \
	parsertest \
	parsertest2 \
	tartest1

testsuite1info:
	@echo ""
	@echo "Test the parser, md5, and sha1 digest code"
	@echo ""
	@echo "This test should only fail due to missing sha1sum, md5sum"
	@echo "or openssl utilities."
	@echo ""


testsuite2: \
	testsuite2info \
	swigntest2 \
	swigntest3 \
	swigntest4 \
	swigntest5 \
	tartest1

testsuite2info:
	@echo ""
	@echo "Test swpackage and swverify"
	@echo ""
	@echo "This test may fail if gpg is an old verion, if not running on"
	@echo "a GNU/Linux system, or if you don't have GNU tar."
	@echo ""

shorttest:
	(echo; cd swsupplib/tests; $(SHELL) ./testdig.sh --short; exit 0)

shorttest2:
	(echo; cd swsupplib/tests; $(SHELL) ./testdig2.sh --short; exit 0)

digesttest:
	(cd swsupplib/tests;  $(SHELL) ./testdig.sh)

digesttest2:
	(cd swsupplib/tests;  $(SHELL) ./testdig2.sh)

parsertest:
	(cd tests/regression; $(MAKE) -s test008 2>/dev/null; exit $?)

parsertest2:
	(cd tests/regression; $(MAKE) -s test009 2>/dev/null; exit $?)

archivetest0:
	(AUTHOR="Test User" ./make_archive --test-release; exit $?)

swigntest1:
	(cd tests/regression; $(MAKE) -s test024)

swigntest2:
	(cd tests/regression; $(MAKE) -s test026)

swigntest3:
	(cd tests/regression; $(MAKE) -s test027)

swigntest4:
	(cd tests/regression; $(MAKE) -s test028)

swigntest5:
	(cd tests/regression; $(MAKE) -s test029)

Xtartest1:
	sh bin/testforgnutar.sh; case  $$? in 0) \
	(cd tests/regression; $(MAKE) -s test030); ;; \
	*) echo GNU tar not found, test030 not run, exiting with status 0; exit 0; ;; esac

tartest1:
	$(MAKE) -s Xtartest1

make-subdirs:
	for d in $(SUBDIRS); do \
		(cd $$d; $(MAKE)) \
		  || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac;\
	done && test -z "$$fail"
	(mkdir tmp/ 2>/dev/null; exit 0)
	(mkdir swsupplib/tmp/ 2>/dev/null; exit 0)
	(mkdir swstructlib/src/tmp 2>/dev/null; exit 0)
	(mkdir swstructlib/src/lib 2>/dev/null; exit 0)
	(mkdir tests/tmp 2>/dev/null; exit 0)

make-include_links:
	find  *.h  swprogs swstructlib swsupplib -name '*.h' | \
	sed -e 's@^\./@@' | \
	egrep -v -e '/config.h' -v -e swuser_config.h -v -e /um_rpm/rpm- | \
	(while read file; do (cd include; ln -s  ../$$file `basename $$file`); done; exit 0)
	(${MAKE} -s make-final_include_links; exit 0)
	if [ "$(DO_UM_RPM)" ]; then \
		(${MAKE} -s make-um-rpm_include_links; exit 0); \
	fi

make-um-rpm_include_links:
	cat swsupplib/um_rpm/linklist | \
	sed -e 's@^\./@@' | \
	egrep -v -e '/config.h' -v -e swuser_config.h  | \
	while read file; do (cd include; ln -s  ../$$file `basename $$file`); done

make-final_include_links:
	echo swsupplib/sw_parse/swparse.tab.h | \
	sed -e 's@^\./@@' | \
	egrep -v -e '/config.h' -v -e swuser_config.h -v -e /um_rpm/rpm- |\
	while read file; do (cd include; ln -s  ../$$file `basename $$file`); done
	\
	echo 'swsupplib/sw_parse/y.tab.h' | \
	while read file; do (cd include; ln -s  ../$$file `basename $$file`); done
	\
	echo 'swstructlib/src/misc/swptrlist.cxx' | \
	sed -e 's@^\./@@' | \
	egrep -v -e /config.h | \
	egrep -v -e swuser_config.h | \
	while read file; do (cd include; ln -s  ../$$file `basename $$file`); done
	\
	(cd include && cp /dev/null popt.h;)
	(cd include && rm config.h; ln -s ../swsupplib/config.h config.h;)

$(PROGS): $(OBJS) 

.PHONY:		install
install:
	for d in $(SUBDIRS); do \
		(cd $$d; $(MAKE) $@) ;\
	done

.PHONY:		clean
clean:
	for d in $(SUBDIRS); do \
		(cd $$d; $(MAKE) $@) ;\
	done
	/bin/rm -f *.S *.a *.o core *~ $(PROGS) rpm.shared 
	/bin/rm -f include/*LINKS
	/bin/rm -f include/LINKS
	find . -name "*.orig" -exec /bin/rm {} \;
	find . -name core -exec /bin/rm {} \;
	/bin/rm -fr tmp/*

.PHONY:		distclean
distclean:	
	for d in $(SUBDIRS); do \
		(cd $$d; $(MAKE) $@) ;\
	done
	/bin/rm -f *.a *.o core *~ $(PROGS) rpm.shared librpmrc find-provides.sh find-requires.sh design.ps design.eps
	/bin/rm -f .depend Makefile Makefile.inc config.h config.cache config.status config.log lib-rpmrc *.bak
	/bin/rm -f CHANGES.rej*
	(cd include; find . -type l -exec /bin/rm -f {} \;)
	(cd include; rm -f popt.h \;)
	(find . -name gmon.out -exec /bin/rm -f {} \;)
	(find . -name .depend -exec /bin/rm -f {} \;)
	/bin/rm -fr tmp/*
	/bin/rm -f .[a-z]*

.PHONY:		depend

.depend: 
	$(MAKE) make-include_links
	for d in $(CSUBDIRS); do \
		(cd $$d; $(MAKE) depend) ;\
	done
	for d in $(CPPSUBDIRS); do \
		(cd $$d; $(MAKE) depend) ;\
	done
	( > .depend )

#	($(CPP) $(CFLAGS) -M $(srcdir)/$(SOURCES) > .depend; exit 0)

depend: .depend 

noconfig:
	find . -name "Makefile" -exec rm {} \; 
	rm -f *gz *rpm config.*

