# Pluto Makefile
# Copyright (C) 1997, 1998, 1999 Angelos D. Keromytis.
#
# 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# 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.
#
# RCSID $Id: Makefile,v 1.1 2000/11/18 00:30:20 bj Exp $
#
# changed by dev@fx.dk (port to OS/2) 21/07/1999
#

#SHELL = /bin/sh

CC = gcc

# directory in which to install programs
BINDIR=/usr/local/sbin

# directory in which to install man pages
MANTREE=/usr/local/man
FMANDIR=$(MANTREE)/man5
PMANDIR=$(MANTREE)/man8

FREESWANLIBDIR=../lib
FREESWANINCLS= -I../lib -I../gmp -I../libdes -I.
FREESWANLIB=../lib/libfreeswan.a
LIBDESLITE=../libdes/libdes.a
LIBGMP=../gmp/libgmp.a

KLIPSD=../klips/src

INSTALL=install

# -O on Linux makes gcc coredump when compiling sha1.c
CFLAGS = -g -Wall #-Wmissing-prototypes #-O

# where to find klips headers and FreeS/WAN headers
HDRDIRS = -I$(KLIPSD) $(FREESWANINCLS)

# On non-LINUX systems, these one of these may be needed (see endian.h)
# BYTE_ORDER = -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
# BYTE_ORDER = -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN

# -DKLIPS enables interface to Kernel LINUX IPsec code (see also the
#    definition of KERNELKLIPS below)
# -DDEBUG enables debugging code, allowing for debugging output
#    (note that output must also be selected at runtime, so it is
#    reasonable to always define this)
# -DGCC_LINT uses gcc-specific declarations to improve compile-time
#    diagnostics.  Some "zero-length format string" warnings are expected.

# -DLEAK_DETECTIVE enables crude code to find memory allocation leaks.

# The following are best left undefined -- each can be overridden at runtime
# if need be.
# -DPORT=n sets the default UDP port for IKE messages (otherwise 500)
# -DSHARED_SECRETS_FILE=string overrides /etc/ipsec.secrets as the
#    default name of the file containing secrets used to authenticate other
#    IKE daemons.  In the Makefile, two levels of quoting are needed:
#    -DSHARED_SECRETS_FILE='"/etc/ipsec.secrets"'
# -DLOCK_DIR=string overrides /var/run as default directory where pluto
#    creates its pluto.pid lock file.  Double quoting may be needed.
# -DROAD_WARRIOR_FUDGE enables support for initiators with IP addresses
#    previously unknown to the responder.

CPPFLAGS = $(HDRDIRS) -DDEBUG $(BYTE_ORDER) -DTCPIPV4 -D__OS2__ -DROAD_WARRIOR_FUDGE -DSUPPORT_ESP_NULL
#CPPFLAGS = $(HDRDIRS) -DDEBUG $(BYTE_ORDER) -DTCPIPV4 -D__OS2__ -DROAD_WARRIOR_FUDGE -DDODGE_DH_MISSING_ZERO_BUG

ALLFLAGS = $(CPPFLAGS) $(CFLAGS)

# libefence is a free memory allocation debugger
# Solaris 2 needs -lsocket -lnsl
LIBSPLUTO = -lsocket -lbsd
# -lefence

LDFLAGS =

# Solaris needs -lsocket -lnsl
LIBSWHACK = -lsocket

BINNAMEPLUTO = pluto.exe
BINNAMEWHACK = whack.exe

RM = /bin/rm
RMFLAGS = -f

.SUFFIXES:
.SUFFIXES: .c .o

# files for a (source) distribution

DISTMISC = CHANGES ipsec.secrets Makefile \
	 pluto.8 ipsec.secrets.5

DISTSRC = \
	connections.c connections.h \
	constants.c constants.h \
	cookie.c cookie.h \
	crypto.h crypto.c \
	defs.h defs.c \
	demux.c demux.h \
	endian.h \
	ipsec_doi.c ipsec_doi.h \
	kernel.c kernel.h \
	kernel_comm.c kernel_comm.h \
	log.c log.h \
        getopt.c getopt1.c getopt.h \
	main.c \
	md5.c md5.h \
	packet.c packet.h \
	preshared.c preshared.h \
	rnd.c rnd.h \
	server.c server.h \
	sha1.c sha1.h \
	spdb.c spdb.h \
	state.c state.h \
	timer.c timer.h \
	whack.c whack.h \
	syslog.c syslog.h \
	eventlog.c eventlog.h \
	route.c route.h \
	os2misc.c os2misc.h \
	conf.c conf.h 

DIST = $(DISTMISC) $(DISTSRC)


OBJSPLUTO = connections.o constants.o cookie.o crypto.o defs.o log.o \
	state.o main.o server.o timer.o ipsec_doi.o kernel.o \
	kernel_comm.o demux.o packet.o preshared.o rnd.o spdb.o \
        getopt.o getopt1.o eventlog.o route.o conf.o\
	sha1.o md5.o syslog.o os2misc.o \
	$(LIBDESLITE) $(LIBGMP) $(FREESWANLIB)

OBJSWHACK = whack.o getopt.o getopt1.o $(FREESWANLIB)

all: $(BINNAMEPLUTO) $(BINNAMEWHACK)

install: all
	$(INSTALL) $(BINNAMEPLUTO) $(BINNAMEWHACK) $(BINDIR)
	$(INSTALL) pluto.8 $(PMANDIR)/ipsec_pluto.8
	ln -f -s ipsec_pluto.8 $(PMANDIR)/ipsec_whack.8
	$(INSTALL) ipsec.secrets.5 $(FMANDIR)

$(BINNAMEPLUTO): $(OBJSPLUTO)
	$(CC) -o $(BINNAMEPLUTO) $(LDFLAGS) $(OBJSPLUTO) $(LIBSPLUTO) iidll_os2\iidll.a -Zcrtdll
#	dllrname pluto.exe emxlibcs=emrlibcs

$(BINNAMEWHACK): $(OBJSWHACK)
	$(CC) -o $(BINNAMEWHACK) $(OBJSWHACK) $(LIBSWHACK)
#	dllrname whack.exe emxlibcs=emrlibcs

distlist:
	@echo $(DIST)

CTAGSFLAGS = -N --format=1 # fishy options required for RH5.2's ctags

tags:	$(DISTSRC)
	ctags $(CTAGSFLAGS) $(DISTSRC)

cleanall: clean

distclean: clean

mostlyclean: clean

realclean: clean

clean:
	$(RM) $(RMFLAGS) $(OBJSPLUTO) *.core core *~ a.out ktrace.out
	$(RM) $(RMFLAGS) $(BINNAMEPLUTO) $(OBJSWHACK) $(BINNAMEWHACK)

.c.o:
	$(CC) $(COPTS) $(ALLFLAGS) -c $<

# kernel.o depends on the following only if made with "-DKLIPS"
#KERNELKLIPS=$(KLIPSD)/radij.h $(KLIPSD)/ipsec_encap.h \
#	$(KLIPSD)/ipsec_netlink.h $(KLIPSD)/ipsec_xform.h
#kernel.o: $(KERNELKLIPS)

# These rules are not for production use
#$(FREESWANLIB):
#	cd $(FREESWANLIBDIR) ; $(MAKE)

#$(LIBDESLITE):
#	cd $(FREESWANLIBDIR) ; $(MAKE) libdes.a

#$(LIBGMP):
#	cd $(FREESWANLIBDIR) ; $(MAKE) libgmp.a

# Gather dependencies caused by explicit #includes within .c files
#
# Each .c is assumed to compile into a .o with the corresponding name.
# Unlike dependencies generated by the compiler, these include dependencies
# suppressed by conditional compilation (good, we think).
# This code can be tricked by embeding #include in comments or
# vice-versa, but we're among friends.

gatherdeps:
	@ls $(DISTSRC) | grep '\.c' | sed -e 's/\(.*\)\.c$$/\1.o: \1.c/'
	@echo
	@ls $(DISTSRC) | grep '\.c' | xargs grep '^#[ 	]*include[ 	]*"' | \
		sed -e 's/\.c:#[ 	]*include[ 	]*"/.o: /' -e 's/".*//'

# Dependencies generated by "make gatherdeps":

connections.o: connections.c
constants.o: constants.c
cookie.o: cookie.c
crypto.o: crypto.c
defs.o: defs.c
demux.o: demux.c
ipsec_doi.o: ipsec_doi.c
kernel.o: kernel.c
kernel_comm.o: kernel_comm.c
log.o: log.c
main.o: main.c
md5.o: md5.c
packet.o: packet.c
preshared.o: preshared.c
rnd.o: rnd.c
server.o: server.c
sha1.o: sha1.c
spdb.o: spdb.c
state.o: state.c
timer.o: timer.c
whack.o: whack.c

getopt.o: getopt.c
getopt.o: getopt1.c
getopt.o: getopt.h

connections.o: constants.h
connections.o: defs.h
connections.o: connections.h
connections.o: packet.h
connections.o: demux.h
connections.o: state.h
connections.o: ipsec_doi.h
connections.o: server.h
connections.o: kernel.h
connections.o: log.h
connections.o: whack.h
connections.o: connos2.inc
constants.o: constants.h
constants.o: packet.h
cookie.o: constants.h
cookie.o: defs.h
cookie.o: sha1.h
cookie.o: rnd.h
cookie.o: cookie.h
crypto.o: constants.h
crypto.o: defs.h
crypto.o: state.h
crypto.o: log.h
crypto.o: md5.h
crypto.o: sha1.h
crypto.o: crypto.h
defs.o: constants.h
defs.o: defs.h
defs.o: log.h
demux.o: constants.h
demux.o: defs.h
demux.o: cookie.h
demux.o: connections.h
demux.o: state.h
demux.o: packet.h
demux.o: md5.h
demux.o: sha1.h
demux.o: crypto.h
demux.o: log.h
demux.o: demux.h
demux.o: ipsec_doi.h
demux.o: timer.h
demux.o: whack.h
demux.o: server.h
ipsec_doi.o: constants.h
ipsec_doi.o: defs.h
ipsec_doi.o: state.h
ipsec_doi.o: connections.h
ipsec_doi.o: preshared.h
ipsec_doi.o: packet.h
ipsec_doi.o: demux.h
ipsec_doi.o: kernel.h
ipsec_doi.o: log.h
ipsec_doi.o: cookie.h
ipsec_doi.o: server.h
ipsec_doi.o: spdb.h
ipsec_doi.o: timer.h
ipsec_doi.o: rnd.h
ipsec_doi.o: ipsec_doi.h
ipsec_doi.o: whack.h
ipsec_doi.o: sha1.h
ipsec_doi.o: md5.h
ipsec_doi.o: crypto.h
ipsec_doi.o: ipsec_doi-aggr1.inc
ipsec_doi.o: ipsec_doi-aggr2.inc
ipsec_doi.o: ipsec_doi-aggr3.inc
ipsec_doi.o: ipsec_doi-aggr4.inc
ipsec_doi.o: ipsec_doi-aggr5.inc
ipsec_doi.o: ipsec_doi-aggr6.inc
kernel.o: constants.h
kernel.o: defs.h
kernel.o: rnd.h
kernel.o: connections.h
kernel.o: state.h
kernel.o: kernel.h
kernel.o: log.h
kernel.o: server.h
kernel_comm.o: constants.h
kernel_comm.o: defs.h
kernel_comm.o: connections.h
kernel_comm.o: whack.h
kernel_comm.o: packet.h
kernel_comm.o: demux.h
kernel_comm.o: state.h
kernel_comm.o: ipsec_doi.h
kernel_comm.o: kernel.h
kernel_comm.o: kernel_comm.h
kernel_comm.o: log.h
kernel_comm.o: preshared.h
kernel_comm.o: server.h
log.o: constants.h
log.o: defs.h
log.o: log.h
log.o: state.h
log.o: connections.h
log.o: whack.h
main.o: constants.h
main.o: defs.h
main.o: connections.h
main.o: server.h
main.o: kernel.h
main.o: log.h
main.o: preshared.h
main.o: rnd.h
main.o: state.h
main.o: sha1.h
main.o: md5.h
main.o: crypto.h
main.o: version.c
main.o: getopt.c
main.o: getopt1.c
main.o: getopt.h
md5.o: md5.h
md5.o: endian.h
packet.o: constants.h
packet.o: defs.h
packet.o: log.h
packet.o: packet.h
preshared.o: constants.h
preshared.o: defs.h
preshared.o: connections.h
preshared.o: state.h
preshared.o: preshared.h
preshared.o: log.h
preshared.o: preshos2.inc
rnd.o: sha1.h
rnd.o: constants.h
rnd.o: defs.h
rnd.o: rnd.h
rnd.o: log.h
rnd.o: timer.h
rnd.o: os2misc.h
server.o: constants.h
server.o: defs.h
server.o: state.h
server.o: connections.h
server.o: kernel.h
server.o: log.h
server.o: server.h
server.o: timer.h
server.o: packet.h
server.o: demux.h
server.o: kernel_comm.h
server.o: servos2.inc
sha1.o: sha1.h
sha1.o: endian.h
spdb.o: constants.h
spdb.o: defs.h
spdb.o: connections.h
spdb.o: state.h
spdb.o: packet.h
spdb.o: preshared.h
spdb.o: kernel.h
spdb.o: log.h
spdb.o: spdb.h
spdb.o: sha1.h
spdb.o: md5.h
spdb.o: crypto.h
state.o: constants.h
state.o: defs.h
state.o: connections.h
state.o: state.h
state.o: kernel.h
state.o: log.h
state.o: rnd.h
state.o: timer.h
state.o: whack.h
timer.o: constants.h
timer.o: defs.h
timer.o: connections.h
timer.o: state.h
timer.o: packet.h
timer.o: demux.h
timer.o: ipsec_doi.h
timer.o: server.h
timer.o: log.h
timer.o: rnd.h
timer.o: timer.h
timer.o: whack.h
whack.o: constants.h
whack.o: defs.h
whack.o: version.c
whack.o: connections.h
whack.o: whack.h
whack.o: getopt.c
whack.o: getopt1.c
whack.o: getopt.h

syslog.o: syslog.c
syslog.o: syslog.h

eventlog.o: eventlog.c
eventlog.o: eventlog.h

route.o: route.c
route.o: route.h

os2misc.o: os2misc.c
os2misc.o: os2misc.h

conf.o:  conf.h
conf.o:  conf.c

