# Makefile for KLIPS kernel code as a module    for 2.4 kernels
#
# Makefile for KLIPS kernel code as a module
# Copyright (C) 1998, 1999, 2000,2001  Richard Guy Briggs.
# Copyright (C) 2002,2003	Michael Richardson <mcr@freeswan.org>
# Copyright (C) 2004		Michael Richardson <mcr@xelerance.com>
# 
# 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.
#
# 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).
#

ifeq ($(strip $(KLIPSMODULE)),)
LIBRESWANSRCDIR=.
else
LIBRESWANSRCDIR=../../..
endif
-include ${LIBRESWANSRCDIR}/Makefile.ver

ifeq ($(strip $(KLIPS_TOP)),)
KLIPS_TOP=../..
endif

ifneq ($(strip $(KLIPSMODULE)),)

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

endif

subdir-  := 
subdir-n := 
subdir-y :=
subdir-m :=
export-objs :=
exportobj-y :=

MOD_DESTDIR:=net/ipsec

export TOPDIR

all: ipsec.o

foo:
	echo KERNEL: ${KERNEL_CFLAGS}
	echo MODULE: ${MODULE_CFLAGS}

ipsec.o: foo

# always force it on
CONFIG_KLIPS_ESP:=y
CONFIG_KLIPS_IPIP:=y

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 ipsec_mast.o
obj-y += ipsec_tunnel.o ipsec_xmit.o ipsec_rcv.o ipsec_ipip.o
obj-y += sysctl_net_ipsec.o 
obj-y += ipsec_snprintf.o ipsec_kern24.o
obj-y += pfkey_v2.o pfkey_v2_parser.o pfkey_v2_ext_process.o 
obj-y += version.o
obj-$(CONFIG_KLIPS_ESP)     += ipsec_esp.o
obj-$(CONFIG_KLIPS_OCF)     += ipsec_ocf.o
obj-$(CONFIG_KLIPS_IPCOMP)  += ipsec_ipcomp.o

# AH, if you really think you need it.
obj-$(CONFIG_KLIPS_AH) += ipsec_ah.o

CFLAGS_ipsec_alg.o += -DEXPORT_SYMTAB 
obj-$(CONFIG_KLIPS_ALG)           += ipsec_alg.o

obj-$(CONFIG_KLIPS_ENC_AES)       += ipsec_alg_aes.o
obj-$(CONFIG_KLIPS_ENC_CRYPTOAPI) += ipsec_alg_cryptoapi.o

VPATH+=${KLIPS_TOP}/net/ipsec/des

obj-$(CONFIG_KLIPS_ENC_3DES) += ipsec_alg_3des.o
obj-$(CONFIG_KLIPS_ENC_3DES) += cbc_enc.o
obj-$(CONFIG_KLIPS_ENC_3DES) += ecb_enc.o
obj-$(CONFIG_KLIPS_ENC_3DES) += set_key.o


VPATH+=${KLIPS_TOP}/net/ipsec/aes
ASM-$(ARCH_ASM):=1
ASM_X86:=$(ASM-i586)$(ASM-i686)

ifneq ($(strip $(ASM_X86)),)
obj-$(CONFIG_KLIPS_ENC_AES) += aes-i586.o

# and use assembly version of zlib code.
CFLAGS+=-DASMV
else
obj-$(CONFIG_KLIPS_ENC_AES) += aes.o
endif

obj-$(CONFIG_KLIPS_ENC_AES) += aes_cbc.o
obj-$(CONFIG_KLIPS_ENC_AES) += aes_xcbc_mac.o

ifeq ($(strip ${SUBARCH}),)
SUBARCH:=${ARCH}
endif

ifeq (${SUBARCH},i386)
obj-$(CONFIG_KLIPS_ENC_3DES) += dx86unix.o
else
obj-$(CONFIG_KLIPS_ENC_3DES) += des_enc.o
endif

obj-y += satot.o
obj-y += addrtot.o
obj-y += ultot.o 
obj-y += addrtypeof.o
obj-y += anyaddr.o
obj-y += initaddr.o
obj-y += ultoa.o 
obj-y += addrtoa.o 
obj-y += subnettoa.o 
obj-y += subnetof.o 
obj-y += goodmask.o 
obj-y += datatot.o 
obj-y += rangetoa.o 
obj-y += prng.o 
obj-y += pfkey_v2_parse.o 
obj-y += pfkey_v2_build.o 
obj-y += pfkey_v2_debug.o 
obj-y += pfkey_v2_ext_bits.o 

# IPcomp stuff
obj-$(CONFIG_KLIPS_IPCOMP) += ipcomp.o 

obj-$(CONFIG_KLIPS_IPCOMP) += adler32.o
obj-$(CONFIG_KLIPS_IPCOMP) += deflate.o
obj-$(CONFIG_KLIPS_IPCOMP) += infblock.o
obj-$(CONFIG_KLIPS_IPCOMP) += infcodes.o
obj-$(CONFIG_KLIPS_IPCOMP) += inffast.o
obj-$(CONFIG_KLIPS_IPCOMP) += inflate.o
obj-$(CONFIG_KLIPS_IPCOMP) += inftrees.o
obj-$(CONFIG_KLIPS_IPCOMP) += infutil.o
obj-$(CONFIG_KLIPS_IPCOMP) += trees.o
obj-$(CONFIG_KLIPS_IPCOMP) += zutil.o

asm-obj-$(CONFIG_M586)          += match586.o
asm-obj-$(CONFIG_M586TSC)       += match586.o
asm-obj-$(CONFIG_M586MMX)       += match586.o
asm-obj-$(CONFIG_M686)          += match686.o
asm-obj-$(CONFIG_MPENTIUMIII)   += match686.o
asm-obj-$(CONFIG_MPENTIUM4)     += match686.o
asm-obj-$(CONFIG_MK6)           += match586.o
asm-obj-$(CONFIG_MK7)           += match686.o
asm-obj-$(CONFIG_MCRUSOE)       += match586.o
asm-obj-$(CONFIG_MWINCHIPC6)    += match586.o
asm-obj-$(CONFIG_MWINCHIP2)     += match686.o
asm-obj-$(CONFIG_MWINCHIP3D)    += match686.o

obj-m += $(O_TARGET)


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

# MOST of these flags are in KERNEL_CFLAGS already!

# cannot use both -Wpointer-arith and -Werror with CONFIG_HIGHMEM
# include/linux/highmem.h has an inline function definition that uses void* arithmentic.
ifeq ($(CONFIG_NOHIGHMEM),y)
#EXTRA_CFLAGS += -Wpointer-arith 
endif
#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 
EXTRA_CFLAGS += -DIPCOMP_PREFIX
ifneq ($(wildcard ${TOPDIR}/crypto/ocf),)
EXTRA_CFLAGS += -I${TOPDIR}/crypto/ocf
endif
EXTRA_CFLAGS += -DKLIPS=1

ifneq ($(strip $(KLIPSMODULE)),)
# for when we aren't building in the kernel tree
EXTRA_CFLAGS += -DARCH=${ARCH} 
EXTRA_CFLAGS += -DMODVERSIONS
EXTRA_CFLAGS += -include ${TOPDIR}/include/linux/modversions.h
EXTRA_CFLAGS += ${MODULE_CFLAGS} 
endif

# GCC 3.2 (and we presume any other 3.x) wants -falign-functions
# in place of the traditional -malign-functions.  Getting this
# wrong leads to a warning, which is fatal due to our use of -Werror.
ifeq ($(patsubst 3.%,3,$(shell $(CC) -dumpversion)),3)
override CFLAGS:=$(subst -malign-functions=,-falign-functions=,$(CFLAGS))
endif


obj-$(CONFIG_KLIPS_AUTH_HMAC_MD5) += ipsec_md5c.o
obj-$(CONFIG_KLIPS_AUTH_HMAC_SHA1) += ipsec_sha1.o

# 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		:= $(filter-out $(export-objs), $(obj-y))
OX_OBJS		:= $(filter     $(export-objs), $(obj-y))
M_OBJS		:= $(sort $(filter-out $(export-objs), $(obj-m)))
MX_OBJS		:= $(sort $(filter     $(export-objs), $(obj-m)))

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

USE_STANDARD_AS_RULE=true

tags TAGS: *.c *.h libfreeswan/*.c libfreeswan/*.h
	etags *.c ../../include/*.h ../../include/freeswan/*.h
	ctags *.c ../../include/*.h ../../include/freeswan/*.h

baz:
	@echo OX: ${OX_OBJS}
	@echo MIX: ${MIX_OBJS}
	@echo O: ${O_OBJS}
	@echo M: ${M_OBJS}

tar:
		tar -cvf /dev/f1 .
