# FreeS/WAN library
# Copyright (C) 1998, 1999  Henry Spencer.
# 
# 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.26 1999/12/03 02:18:20 rgb Exp $

OBJS=ultoa.o addrtoa.o subnettoa.o subnetof.o goodmask.o datatoa.o rangetoa.o \
	satoa.o atoul.o atoaddr.o atosubnet.o atodata.o atoasr.o atosa.o \
	optionsfrom.o pfkey_v2_parse.o pfkey_v2_build.o pfkey_v2_ext_bits.o
HDRS=freeswan.h internal.h
LIB=libfreeswan.a
CFLAGS=-O3 -I.
#CFLAGS=-O3 -I. -g -Wall -W -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wmissing-declarations -Wwrite-strings -Wstrict-prototypes
# -Wbad-function-cast 
ARFLAGS=crvs
EXTHDRS=des.h gmp.h
EXTLIBS=libdes.a libgmp.a
MANTREE=/usr/local/man
MANDIR=$(MANTREE)/man3
MANS=atoaddr.3 atoasr.3 atodata.3 atosa.3 atoul.3 goodmask.3 optionsfrom.3 \
	subnetof.3
INSTALL=install

SHELL=/bin/sh


all:	$(EXTHDRS) $(LIB) $(EXTLIBS)

install:
	for f in $(MANS) ; \
	do \
		$(INSTALL) $$f $(MANDIR)/ipsec_$$f || exit 1 ; \
		../utils/manlink $(MANDIR) ipsec_$$f ; \
	done

$(LIB):	$(OBJS)
	ar $(ARFLAGS) $(LIB) $(OBJS)

$(OBJS):	$(HDRS)

des.h:
	ln -s ../libdes/des.h

libdes.a:	../libdes/libdes.a
	ln -f -s ../libdes/libdes.a

# yes, that's CFLAG=, not CFLAGS=
../libdes/libdes.a:
	cd ../libdes ; \
	if test " `arch | sed 's/^i[3456]/x/'`" = " x86" ; \
	then $(MAKE) CC='$(CC)' CFLAG='$(CFLAGS)' TESTING='' x86-elf ; \
	else $(MAKE) CC='$(CC)' CFLAG='$(CFLAGS)' libdes.a ; \
	fi

gmp.h:
	ln -s ../gmp/gmp.h

libgmp.a:	../gmp/libgmp.a
	ln -f -s ../gmp/libgmp.a

../gmp/libgmp.a:	../gmp/Makefile
	cd ../gmp ; $(MAKE)

../gmp/Makefile:	../gmp/configure
	cd ../gmp ; ./configure

clean:
	rm -f $(LIB) *.o try* core *.core $(EXTHDRS) $(EXTLIBS)
	cd ../libdes ; $(MAKE) clean
	if test -f ../gmp/Makefile ; then cd ../gmp ; $(MAKE) distclean ; fi



# developer-only stuff
l:
	$(MAKE) $(LIB) ARFLAGS=crv CFLAGS=-O
	ranlib $(LIB)

t:	$(LIB)
	cp atosubnet.c try.c
	cc -DATOSUBNET_MAIN try.c $(LIB) -o try
	./try -r
	cp atodata.c try2.c
	cc -DATODATA_MAIN try2.c $(LIB) -o try2
	./try2 -r
	cp atoasr.c try3.c
	cc -DATOASR_MAIN try3.c $(LIB) -o try3
	./try3 -r
	cp atosa.c try4.c
	cc -DATOSA_MAIN try4.c $(LIB) -o try4
	./try4 -r

lt:	$(LIB)
	$(MAKE) t
	cp optionsfrom.c try5.c
	cc -DTEST try5.c $(LIB) -o try5
	echo --foo --bar >try5in1
	echo --optionsfrom >>try5in1
	echo try5in2 >>try5in1
	echo --foo >try5in2
	./try5 --foo --bar --optionsfrom try5in1 --bar something

tar:	clean
	tar -cvf /tmp/lib.tar Makefile [a-z]*
