# Makefile for KLIPS kernel code
# Copyright (C) 1998, 1999, 2000,2001  Richard Guy Briggs.
# 
# 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.3 2003/03/31 23:11:00 swahl Exp $
#
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definition is now in the main makefile...

ifndef TOPDIR
TOPDIR  := /usr/src/linux
endif

subdir-  := 
subdir-n := 
subdir-y :=
subdir-m :=

O_TARGET := ipsec.o
obj-y := ipsec_init.o ipsec_sa.o ipsec_radij.o radij.o
obj-y += ipsec_life.o ipsec_proc.o
obj-y += ipsec_tunnel.o ipsec_rcv.o sysctl_net_ipsec.o 
obj-y +=  pfkey_v2.o pfkey_v2_parser.o 

export-objs := radij.o
obj-m += $(O_TARGET)

# 'override CFLAGS' should really be 'EXTRA_CFLAGS'
EXTRA_CFLAGS += -Ilibfreeswan -Ilibdes
ifeq ($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION),2.4.2-2)
EXTRA_CFLAGS += -DREDHAT_BOGOSITY
endif
ifeq ($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION),2.4.3-12)
EXTRA_CFLAGS += -DREDHAT_BOGOSITY
endif

#ifeq ($(CONFIG_IPSEC_DEBUG),y)
#EXTRA_CFLAGS += -g
#endif

EXTRA_CFLAGS += $(KLIPSCOMPILE)
EXTRA_CFLAGS += -Wall
#EXTRA_CFLAGS += -Werror
#EXTRA_CFLAGS += -Wconversion 
#EXTRA_CFLAGS += -Wmissing-prototypes 
EXTRA_CFLAGS += -Wpointer-arith 
#EXTRA_CFLAGS += -Wcast-qual 
#EXTRA_CFLAGS += -Wmissing-declarations 
EXTRA_CFLAGS += -Wstrict-prototypes
#EXTRA_CFLAGS += -pedantic
#EXTRA_CFLAGS += -O3
#EXTRA_CFLAGS += -W
#EXTRA_CFLAGS += -Wwrite-strings 
#EXTRA_CFLAGS += -Wbad-function-cast 

obj-$(CONFIG_IPSEC_ENC_3DES) += libdes/libdes.a
#obj-$(CONFIG_IPSEC_AUTH_HMAC_MD5) += ipsec_md5c.o
#obj-$(CONFIG_IPSEC_AUTH_HMAC_SHA1) += ipsec_sha1.o
obj-$(CONFIG_IPSEC_AUTH_HMAC_MD5) += ipsec_hw_md5c.o
obj-$(CONFIG_IPSEC_AUTH_HMAC_SHA1) += ipsec_hw_sha1.o
obj-$(CONFIG_IPSEC_IPCOMP) += ipcomp.o zlib/zlib.a
subdir-$(CONFIG_IPSEC_IPCOMP) += zlib
subdir-$(CONFIG_IPSEC) += libfreeswan
obj-y += libfreeswan/libkernel.a

CFLAGS_ipsec_sha1.o := -O0

# These rules translate from new to old makefile rules
# Translate to Rules.make lists.
multi-used      := $(filter $(list-multi), $(obj-y) $(obj-m))
multi-objs      := $(foreach m, $(multi-used), $($(basename $(m))-objs))
active-objs     := $(sort $(multi-objs) $(obj-y) $(obj-m))
O_OBJS          := $(obj-y)
M_OBJS          := $(obj-m)
MIX_OBJS        := $(filter $(export-objs), $(active-objs))
#OX_OBJS := $(export-objs)
SUB_DIRS := $(subdir-y)
ALL_SUB_DIRS := $(subdir-y) $(subdir-m)
MOD_SUB_DIRS := $(subdir-m)

include $(TOPDIR)/Rules.make

$(obj-y) $(obj-m):  $(TOPDIR)/include/linux/config.h $(TOPDIR)/include/linux/autoconf.h

## XXX SRW there should be some way to make this cross-compile better
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 )
	( cd libdes && $(MAKE) CC='$(CC)' CFLAG='$(CFLAGS)' libdes.a)

libfreeswan/libkernel.a:
	$(MAKE) -C libfreeswan

zlib/zlib.a:
	$(MAKE) -C zlib

clean:
	-rm -f *.o

tags TAGS: *.c *.h libfreeswan/*.c libfreeswan/*.h
	find . -name '*.[ch]' |xargs etags
	find . -name '*.[ch]' |xargs ctags

tar:
		tar -cvf /dev/f1 .

