#   -*-Makefile-*- template for the CIPE package.
#
#   Copyright 1996 Olaf Titz <olaf@bigred.inka.de>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version
#   2 of the License, or (at your option) any later version.

# $Id: Makefile-top.in,v 1.17.2.1 2001/02/11 21:42:41 olaf Exp $

INFODIR:=/usr/local/info

SRC:=	cipe
VERSION:=@VERSION@
BUILD:=	@BUILD@
BUILD_PKCIPE:=@BUILD_PKCIPE@

MAKE:=	@MAKE@
CC:=	@CC@
TEXINFO:=@TEXINFO@
MAKEINFO:=@MAKEINFO@

default: all

SRCS:=	cipe.h crypto.h \
	ciped.c ciped.h ioctl.c ioctl.h options.in genoptions.pl \
	module.c device.c sock.c output.c encaps.c \
	idea0.h idea0.c bf.h bf.c crc.c crc32.c crcgen.c \
	idea-i386.S bf-i386.S thruput.c
CONF:=	Makefile-top.in Makefile-obj.in aclocal.m4 config.h.in
SMPL:=	README options ip-up ip-down
MISC:=	configure configure.in cipe.info tcpdump.patch cipe.spec
DIST:=	README README.key-bug CHANGES COPYING cipe.lsm $(MISC) \
	$(CONF:%=conf/%) lib $(SRCS:%=$(SRC)/%) pkcipe $(SMPL:%=samples/%)

TEXAUX:=cipe.cp cipe.fn cipe.ky cipe.pg cipe.tp cipe.vr

.PHONY: default all install clean realclean distclean dvi tgz diffcheck dep depend
.EXPORT_ALL_VARIABLES:

all install dep depend:: $(SRC)/options.c

all install clean::
	$(MAKE) -C lib $@
	$(MAKE) -C $(BUILD) $@
ifneq (,$(BUILD_PKCIPE))
	$(MAKE) -C pkcipe $@
endif

$(SRC)/options.h $(SRC)/options.c options.t: $(SRC)/genoptions.pl $(SRC)/options.in
	(cd $(SRC); perl genoptions.pl options.in)

dvi: cipe.dvi

$(TEXAUX): cipe.texinfo options.t
	$(TEXINFO) $<

cipe.info: cipe.texinfo options.t
	$(MAKEINFO) --no-split $<

cipe.dvi: cipe.cp
	texindex $(TEXAUX)
	$(TEXINFO) cipe.texinfo

cipe.html: cipe.texinfo options.t
	texi2html -split chapter -no-section_navigation cipe.texinfo

thruput: $(SRC)/thruput.c
	$(CC) -Wall -O3 -s -o $@ $<

README.key-bug: cipe.info
	info -f ./cipe.info "Keys in older CIPE" | sed 1,2d > $@

cipe.spec: cipe.spec.in
	sed 's,%VERSION%,$(VERSION),g' cipe.spec.in > $@

Checksums: $(DIST)
	-$(MAKE) distclean -C lib
	-$(MAKE) distclean -C pkcipe
	makechecksums $(DIST) > Checksums

tgz:	diffcheck $(DIST) Checksums
	cd .. && ln -sf cipe-linux cipe-$(VERSION) && \
		tar czf cipe-$(VERSION).tar.gz --exclude CVS \
		$(DIST:%=cipe-$(VERSION)/%) cipe-$(VERSION)/Checksums

diffcheck:
	cvs diff >/dev/null 2>&1

BF=	bf.h bf.c bf-i386.S

$(SRC)/bf.checksums: $(BF:%=$(SRC)/%)
	(cd $(SRC); makechecksums $(BF) >bf.checksums)

bf.tgz: $(SRC)/bf.checksums
	(cd $(SRC); tar czf ../bf.tgz $(BF) bf.checksums)

install:: cipe.info
	-mkdir -p $(INFODIR)
	install -m 644 cipe.info $(INFODIR)

TAGS:
	etags *.[hc] */*.[hc]

clean realclean distclean::
	rm -f core *.out *.tmp *.[oaisd] thruput

realclean distclean::
	rm -rf $(BUILD)
	$(MAKE) -C lib $@
ifneq (,$(BUILD_PKCIPE))
	$(MAKE) -C pkcipe $@
endif
	rm -f config.cache config.log config.status Makefile
	rm -f $(SRC)/options.h $(SRC)/options.c options.t cipe.info*
	rm -f *~ *.bak *.dvi *.aux *.log *.toc *.html $(TEXAUX) $(TEXAUX:%=%s)
	rm -f cipe.spec Checksums $(SRC)/bf.checksums bf.tgz TAGS cipe-linux

dep depend::
	: nothing to do

configure: configure.in conf/aclocal.m4
	autoconf -l conf
	rm -f config.status
	@echo "*** Re-run configure"
	@exit 1

config.status: configure
	[ -f config.status ] && ./config.status --recheck || ./configure

Makefile: config.status conf/Makefile-top.in
	./config.status

