VPATH		= @srcdir@
srcdir		= @srcdir@
top_srcdir	= @top_srcdir@
top_builddir	= ..

include ../Makefile.conf

CXX_SOURCES	= basecmds.cc baselist.cc basetop.cc bindings.cc curkeys.cc \
		  main.cc methkeys.cc methlist.cc method.cc methparse.cc \
		  pkgcmds.cc pkgdepcon.cc pkgdisplay.cc pkginfo.cc pkgkeys.cc \
		  pkglist.cc pkgsublist.cc pkgtop.cc helpmsgs.cc

MAN8PAGES	= dselect.8

OBJECTS		= $(patsubst %.cc, %.o, $(CXX_SOURCES))
GENFILES	= $(OBJECTS) dselect helpmsgs.h curkeys.h \
		  $(srcdir)/helpmsgs.h $(srcdir)/helpmsgs.cc

.PHONY: all
all:: dselect

.PHONY: install
install:: all

.PHONY: clean
clean::
	$(RM) $(GENFILES)

.PHONY: distclean
cvslean:: clean
	$(RM) Makefile

.PHONY: install
install:: install-program install-doc

.PHONY: install-program
install-program:
	$(mkinstalldirs) $(DESTDIR)/$(bindir)
	$(INSTALL) dselect $(DESTDIR)/$(bindir)

.PHONY: install-doc
install-doc:
	$(mkinstalldirs) $(DESTDIR)/$(man8dir)
	set -e ; for i in $(MAN8PAGES) ; do \
	    if test -f $$i ; then d= ; else d="$(srcdir)/" ; fi ; \
	    $(INSTALL_DATA) $$d$$i $(DESTDIR)/$(man8dir) ; \
	done

dselect: $(OBJECTS) ../lib/libdpkg.a
	$(CXX) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg -lncurses

basecmds.o: helpmsgs.h
curkeys.o: curkeys.h

$(srcdir)/helpmsgs.h $(srcdir)/helpmsgs.cc: helpmsgs.src $(srcdir)/mkhelpmsgs.pl
	cd $(srcdir) ; perl mkhelpmsgs.pl helpmsgs.src

curkeys.h: keyoverride $(srcdir)/mkcurkeys.pl
	cursesfile=`echo '#include <curses.h>' | \
		 $(CC) -E - | grep 'curses.h' | head -1 | \
		 $(SED) -e 's/^[^"]*"//; s/".*$$//'`; \
	if [ "$$cursesfile" = "" ]; then echo "can't find curses file"; exit 1; fi; \
	perl $(srcdir)/mkcurkeys.pl $< $$cursesfile > $@
