srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_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 ../Makefile.inc

TARGET=allprogs

all: $(TARGET)

allprogs: $(LIBRPM) $(PROGS)

# GNU make doesn't need this, but stupid ones may
misc.o: misc.c
	$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -o $@ -c $<

# ditto
rpmrc.o: rpmrc.c
	$(CC) $(CFLAGS) -DLIBRPMRC_FILENAME="\"$(LIBRPMRC_FILENAME)"\" -o $@ -c $<

$(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_DATA) -m 644 $(srcdir)/rpmlib.h $(INCDIR)
	$(INSTALL_DATA) -m 644 $(srcdir)/dbindex.h $(INCDIR)
	$(INSTALL_DATA) -m 644 $(srcdir)/header.h $(INCDIR)
	$(INSTALL_DATA) -m 644 librpm.a $(LIBDIR)

distclean: clean
	rm -f Makefile	

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

squeaky: clean
	rm -f depend

depend:
	topdir_path=`( cd $(top_srcdir) && pwd )` ; \
	    $(CPP) $(CFLAGS) -MM $(SOURCES) | \
		sed s+$$topdir_path+$(top_srcdir)+g > .depend

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