# Makefile for secnet
# Copyright (C) 1995-2001 Stephen Early <steve@greenend.org.uk>

# 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, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

.PHONY:	all clean realclean distclean dist install

PACKAGE:=secnet
VERSION:=0.1.18

@SET_MAKE@

srcdir:=@srcdir@
VPATH:=@srcdir@

SHELL:=/bin/sh
RM:=@RM@
CC:=@CC@
INSTALL:=@INSTALL@
INSTALL_PROGRAM:=@INSTALL_PROGRAM@

# Use -DHACKY_PARALLEL if you are compiling secnet for an extremely
# slow machine
#CFLAGS:=-Wall @WRITESTRINGS@ @CFLAGS@ -DHACKY_PARALLEL
CFLAGS:=-Wall @WRITESTRINGS@ @CFLAGS@
ALL_CFLAGS:=@DEFS@ -I$(srcdir) -I. $(CFLAGS)
CPPFLAGS:=@CPPFLAGS@
LDFLAGS:=@LDFLAGS@
LDLIBS:=@LIBS@

prefix:=@prefix@
exec_prefix:=@exec_prefix@
sbindir:=@sbindir@
sysconfdir:=@sysconfdir@
transform:=@program_transform_name@

TARGETS:=secnet

OBJECTS:=secnet.o util.o conffile.yy.o conffile.tab.o conffile.o modules.o \
	resolver.o random.o udp.o site.o transform.o netlink.o rsa.o dh.o \
	serpent.o md5.o version.o tun.o slip.o sha1.o ipaddr.o log.o \
	process.o @LIBOBJS@ \
	hackypar.o

DISTDIRS:=debian
DISTFILES:=BUGS COPYING CREDITS INSTALL LICENSE.txt Makefile.in \
	NEWS NOTES README TODO \
	ac_prog_cc_no_writeable_strings.m4 \
	conffile.c conffile.fl conffile.h conffile.y \
	conffile_internal.h \
	config.h.in configure \
	configure.in depend.sh dh.c \
	example.conf \
	getopt.c getopt1.c getopt.h \
	install-sh ipaddr.c ipaddr.h ipaddr.py linux log.c \
	magic.h md5.c md5.h \
	make-secnet-sites \
	modules.c netlink.c netlink.h process.c process.h \
	random.c resolver.c rsa.c \
	secnet.c secnet.h serpent.c serpent.h serpentsboxes.h \
	snprintf.c snprintf.h \
	sha1.c site.c slip.c stamp-h.in transform.c tun.c udp.c \
	unaligned.h util.c util.h \
	hackypar.c hackypar.h
DISTSUBDIRS:=debian/copyright debian/changelog debian/control \
	debian/init debian/rules debian/compat debian/default

%.c:	%.y

%.yy.c:	%.fl
	flex -o$@ $<

%.tab.c %.tab.h:	%.y
	bison -d -o $@ $<

%.o: %.c
	$(CC) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@

all:	$(TARGETS)

# Automatic remaking of configuration files, from autoconf documentation
${srcdir}/configure: configure.in
	cd ${srcdir} && autoconf

# autoheader might not change config.h.in, so touch a stamp file.
${srcdir}/config.h.in: stamp-h.in
${srcdir}/stamp-h.in: configure.in
	cd ${srcdir} && autoheader
	echo timestamp > ${srcdir}/stamp-h.in

config.h: stamp-h
stamp-h: config.h.in config.status
	./config.status

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck
# End of config file remaking rules

# C and header file dependency rules
SOURCES:=$(OBJECTS:.o=.c)
DEPENDS:=$(OBJECTS:.o=.d)

$(DEPENDS): ${srcdir}/depend.sh

%.d: %.c
	${srcdir}/depend.sh $(srcdir) $(CPPFLAGS) $(ALL_CFLAGS) $< > $@

-include $(DEPENDS)

# Manual dependencies section
conffile.yy.c:	conffile.fl conffile.tab.c
conffile.tab.c:	conffile.y
# End of manual dependencies section

secnet:	$(OBJECTS)
	$(CC) $(LDFLAGS) $(ALL_CFLAGS) -o $@ $(OBJECTS) $(LDLIBS)

version.c: Makefile
	echo "char version[]=\"secnet $(VERSION)\";" >version.c

install: all
	$(INSTALL) -d $(prefix)/share/secnet $(sbindir)
	$(INSTALL_PROGRAM) secnet $(sbindir)/`echo secnet|sed '$(transform)'`
	$(INSTALL_PROGRAM) ${srcdir}/make-secnet-sites $(sbindir)/`echo make-secnet-sites|sed '$(transform)'`
	$(INSTALL) ${srcdir}/ipaddr.py $(prefix)/share/secnet/ipaddr.py

clean:
	$(RM) -f *.o *.yy.c *.tab.[ch] $(TARGETS) core version.c

realclean:	clean
	$(RM) -f *~ Makefile config.h  *.d \
	config.log config.status config.cache \
	stamp-h Makefile.bak

distclean:	realclean

pfname:=$(PACKAGE)-$(VERSION)
dist:
	$(RM) -rf $(pfname)
	mkdir $(pfname)
	for i in $(DISTDIRS) ; do mkdir $(pfname)/$$i ; done
	for i in $(DISTFILES) ; do ln -s ../$(srcdir)/$$i $(pfname)/ ; done
	for i in $(DISTSUBDIRS) ; do ln -s ../../$(srcdir)/$$i $(pfname)/$$i ; done
	tar hcf ../$(pfname).tar --exclude=CVS --exclude=.cvsignore $(pfname)
	gzip -9f ../$(pfname).tar
	$(RM) -rf $(pfname)
