srcdir = @srcdir@
VPATH = $(srcdir)

LIBOBJECTS = 	header.o 	misc.o		messages.o 	\
		rpmerr.o 	falloc.o 			\
		md5.o		md5sum.o	dbindex.o	\
		rpmrc.o		depends.o	rpmdb.o		\
		stringbuf.o	rpmlead.o	package.o	\
		uninstall.o	oldheader.o	install.o	\
		signature.o	verify.o	rebuilddb.o	\
		tread.o 	cpio.o		formats.o	\
		fs.o		lookup.o

SOURCES = $(addprefix $(srcdir)/,$(subst .o,.c,$(LIBOBJECTS))) 
TAGTABLE = tagtable.o
LIBRPM = librpm.a
LOADLIBES = -lrpm -lgdbm -ldb $(LIBEFENCE)
PROGS = 
INSTALL= @INSTALL@
INSTALL_PROGRAM= @INSTALL_PROGRAM@
INSTALL_DATA= @INSTALL_DATA@

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

include $(srcdir)/../Makefile.inc

ifeq (.depend,$(wildcard .depend))
TARGET=allprogs
else
TARGET=depend allprogs
endif

all: $(TARGET)

allprogs: $(LIBRPM) $(PROGS)

$(PROGS): $(LIBRPM)

$(LIBRPM): $(LIBRPM)($(LIBOBJECTS) $(TAGTABLE))
	$(RANLIB) $@

tagtable.c: rpmlib.h 
	echo '#include "rpmlib.h"' > tagtable.c
	echo '' >> tagtable.c
	echo 'const struct headerTagTableEntry rpmTagTable[] = {' >> tagtable.c
	awk '/(RPMTAG_[A-Z0-9]*)[ \t]+([0-9]*)/ && !/internal/ { printf("\t{ \"%s\", %s },\n", $$2, $$3); }' < $(srcdir)/rpmlib.h >> tagtable.c
	echo '	{ NULL, 0 }' >> tagtable.c
	echo '};' >> tagtable.c
	echo '' >> tagtable.c
	echo 'const int rpmTagTableSize = sizeof(rpmTagTable) / sizeof(struct headerTagTableEntry) - 1;' >> tagtable.c

install:
	$(INSTALL) -m 644 $(srcdir)/rpmlib.h $(INCDIR)
	$(INSTALL) -m 644 $(srcdir)/dbindex.h $(INCDIR)
	$(INSTALL) -m 644 $(srcdir)/header.h $(INCDIR)
	$(INSTALL) -m 644 librpm.a $(LIBDIR)

distclean: clean
	rm -f .depend Makefile	

clean:
	rm -f *.a *.o *~ $(PROGS) test.out tagtable.c

squeaky: clean
	rm -f depend

depend:
	$(CPP) $(CFLAGS) -M $(SOURCES) > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif
