# 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.
#
# RCSID $Id: Makefile.fs2_4,v 1.9 2005/05/20 16:47:26 mcr 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).
#

ifeq ($(strip $(KLIPSMODULE)),)
OPENSWANSRCDIR=.
else
OPENSWANSRCDIR=../../..
endif
-include ${OPENSWANSRCDIR}/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
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_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_1DES) += ipsec_alg_1des.o
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 ($(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 .

#
# $Log: Makefile.fs2_4,v $
# Revision 1.9  2005/05/20 16:47:26  mcr
# 	added missing routines for 2.4 compilation.
#
# Revision 1.8  2005/05/20 03:19:18  mcr
# 	modifications for use on 2.4.30 kernel, with backported
# 	printk_ratelimit(). all warnings removed.
#
# Revision 1.7  2005/05/20 02:46:30  mcr
# 	compatibility for 2.4 kernel.
#
# Revision 1.6  2005/04/14 20:48:30  mcr
# 	added snprintf to build list for 2.4.
#
# Revision 1.5  2004/09/14 00:03:47  mcr
# 	use assembly code on i586/i686 for zlib.
#
# Revision 1.4  2004/07/22 02:09:12  mcr
# 	do not use export-objs on ipsec_alg.c, as the rule does not
# 	work with VPATH for silly reasons.
# 	Instead, define -DEXPORT_SYMTAB directly.
#
# Revision 1.3  2004/07/19 01:48:54  mcr
# 	adjustment of Makefile to use split OX/O_OBJS.
#
# Revision 1.2  2004/07/18 16:17:10  mcr
# 	list ipsec_alg.o as both an export object and an object
# 	that has to be compiled.
#
# Revision 1.1  2004/07/10 19:11:18  mcr
# 	CONFIG_IPSEC -> CONFIG_KLIPS.
#
# Revision 1.3  2004/02/24 17:17:04  mcr
# 	s/CONFIG_IPSEC/CONFIG_KLIPS/ as 26sec uses "CONFIG_IPSEC" to
# 	turn it on/off as well.
#
# Revision 1.2  2004/02/22 06:50:42  mcr
# 	kernel 2.6 port - merged with 2.4 code.
#
# Revision 1.1  2004/02/14 21:59:19  mcr
# 	split up Makefile into kernel specific versions.
#
# Revision 1.68  2003/12/15 20:38:11  mcr
# 	make sure that IPIP is always on.
#
# Revision 1.67  2003/12/15 15:42:27  mcr
# 	make sure that ESP is always on, and AH is no more.
#
# Revision 1.66  2003/12/13 04:09:21  mcr
# 	AH transform removed.
#
# Revision 1.65  2003/12/11 20:15:04  mcr
# 	refactored the xmit code, to move all encapsulation
# 	code into protocol functions. Note that all functions
# 	are essentially done by a single function, which is probably
# 	wrong.
# 	the rcv_functions structures are renamed xform_functions.
#
# Revision 1.64  2003/12/06 21:21:38  mcr
# 	split up receive path into per-transform files, for
# 	easier later removal.
#
# Revision 1.63  2003/11/07 02:58:06  mcr
# 	backout of port-selector and X.509 patches
#
# Revision 1.61  2003/06/22 21:07:46  mcr
# 	adjusted TAGS target in makefile to be useful in 2.00 source layout.
#
# Revision 1.60  2003/05/03 23:45:23  mcr
# 	rm .o.flags and generated version.c file.
#
# Revision 1.59  2003/02/12 19:32:47  rgb
# Added ipsec_xmit to the list of object files.
#
# Revision 1.58  2003/01/03 00:36:44  rgb
#
# Added emacs compile-command.
#
# Revision 1.57  2002/11/08 23:49:53  mcr
# 	use KERNEL_CFLAGS and MODULE_CFLAGS to get proper list
# 	of include directories.
# 	This also eliminates some of the guesswork in the kernel
# 	configuration file.
#
# Revision 1.56  2002/11/08 23:23:18  mcr
# 	attempt to guess kernel compilation flags (i.e. list of -I)
# 	by using some magic targets in the kernel makefile.
#
# Revision 1.55  2002/11/08 10:13:33  mcr
# 	added additional include directories for module builds for 2.4.19.
#
# Revision 1.54  2002/10/20 06:10:30  build
# CONFIG_NOHIGHMEM for -Wpointer-arith RPM building issues.
#
# Revision 1.53  2002/10/17 16:32:01  mcr
# 	enable standard AS rules.
#
# Revision 1.52  2002/10/06 06:13:44  sam
# Altering order of includes, so that architecture-specific header files,
# used for building RPM modules specifically, are processed first.
#
# Revision 1.51  2002/10/05 15:06:38  dhr
#
# - To allow for gcc3.2 (used in Red Hat Linux 8.0):  adjust CFLAGS (set
#   by kernel machinery) to use -falign-functions= in place of
#   -malign-functions=.  Eliminates a warning (fatal with -Werror).
#
# - When CONFIG_HIGHMEM is on, -Wpointer-arith will warn about
#   include/linux/highmem.h.  Since this is fatal with -Werror, we
#   suppress -Wpointer-arith if CONFIG_HIGHMEM is set.
#
# Revision 1.50  2002/09/16 21:19:45  mcr
# 	enable -Werror for production - this helps a lot (found a bug in ipsec_rcv.c)
#
# Revision 1.49  2002/07/29 05:12:39  mcr
# 	get rid of some extraneous stuff, now handled by a prefix
# 	Makefile when building as a module.
#
# Revision 1.48  2002/07/28 23:13:49  mcr
# 	set KLIPS_TOP and use it instead of ../..
# 	if KLIPSMODULE, then include a bunch of stuff defined in Makefile.inc
# 	that gets us the "typical" configuration that we want.
#
# Revision 1.47  2002/06/02 21:51:41  mcr
# 	changed TOPDIR->FREESWANSRCDIR in all Makefiles.
# 	(note that linux/net/ipsec/Makefile uses TOPDIR because this is the
# 	kernel sense.)
#
# Revision 1.46  2002/05/14 02:35:51  rgb
# Added file pfkey_v2_ext_process.c.
#
# Revision 1.45  2002/05/13 17:21:40  mcr
# 	mkdep dies when given a -I to a directory that does not exist.
# 	arch/${ARCH}/include is for UM arch only, so include it for that
# 	ARCH only.
#
# Revision 1.44  2002/04/24 20:38:12  mcr
# 	moved more stuff behind $KLIPSMODULE=y to get static linking to work.
#
# Revision 1.43  2002/04/24 09:16:18  mcr
# 	include local Makefile.ver as well as FS_rootdir version.
#
# Revision 1.42  2002/04/24 08:50:08  mcr
# 	critical patch is to set TOPDIR with :=.
#
# Revision 1.40  2002/04/24 00:41:07  mcr
# Moved from ./klips/net/ipsec/Makefile,v
#
# Revision 1.39  2002/01/17 04:39:40  rgb
# Take compile options from top level Makefile.inc
#
# [..elided..]
#
# Local Variables:
# compile-command: "(cd ../../.. && source umlsetup.sh && make -C ${POOLSPACE} module/ipsec.o)"
# End Variables:
#

