srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

LIBOBJECTS = 	popt.o

SOURCES = $(addprefix $(srcdir)/,$(subst .o,.c,$(LIBOBJECTS)))
LIBPOPT = libpopt.a
CC = @CC@

RANLIB=@RANLIB@
INSTALL=@INSTALL@
INSTALL_PREOGRAM=@INSTALL_PREOGRAM@
INSTALL_DATA=@INSTALL_DATA@
prefix=@prefix@
LIBS=$(prefix)/lib
INCLUDE=$(prefix)/include
CPP=@CPP@

VERSION=$(shell awk '/define version/ { print $$3 }' popt.spec)
CVSTAG = r$(subst .,-,$(VERSION))

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

CFLAGS = @CFLAGS@ @DEFS@ $(OPTS)

ifeq ($(RANLIB),)
RANLIB=ranlib
endif

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

$(LIBPOPT): $(LIBPOPT)($(LIBOBJECTS))
	$(RANLIB) $@

distclean: clean
	rm -f Makefile .depend-done config.log config.status

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

squeaky: distclean
	rm -f .depend

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

install:
	mkdir -p $(PREFIX)/$(INCLUDE)
	mkdir -p $(PREFIX)/$(LIBS)
	$(INSTALL_DATA) -m 644 popt.h $(PREFIX)/$(INCLUDE)/popt.h
	$(INSTALL_DATA) -m 644 $(LIBPOPT) $(PREFIX)/$(LIBS)/$(LIBPOPT)

archive:
	cvs tag -F $(CVSTAG) .
	@rm -rf /tmp/popt-$(VERSION) /tmp/popt
	@cd /tmp; cvs export -r$(CVSTAG) popt
	@cd /tmp/popt; autoconf
	@mv /tmp/popt /tmp/popt-$(VERSION)
	@dir=$$PWD; cd /tmp; tar cvzf $$dir/popt-$(VERSION).tar.gz popt-$(VERSION)
	@rm -rf /tmp/popt-$(VERSION)
	@echo "The archive is in popt-$(VERSION).tar.gz"

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