4 # gnu Makefile to build linux module for ipfw+dummynet
6 # Unless specified otherwise, variable names are arbitrary.
7 # Exceptions are the following:
9 # ccflags-y additional $(CC) flags
10 # M used by Kbuild, we must set it to `pwd`
11 # obj-m list of .o modules to build
12 # $(MOD)-y for each $MOD in obj-m, the list of objects
13 # obj-y same as above, for openwrt
14 # O_TARGET the link target, for openwrt
15 # EXTRA_CFLAGS as the name says... in openwrt
16 # EXTRA_CFLAGS are used in 2.6.22 module kernel compilation too
19 $(warning including dummynet/Makefile)
21 # lets default for 2.6 for planetlab builds
26 $(warning dummynet/Makefile doing openwrt)
28 obj-y := ipfw2_mod.o bsd_compat.o \
29 in_cksum.o ip_dummynet.o ip_fw2.o ip_fw_pfil.o
30 O_TARGET := ipfw_mod.o
32 xcflags-y += -O1 -DLINUX_24
33 xcflags-y += -DIPFIREWALL_DEFAULT_TO_ACCEPT
35 xcflags-y += -D_BSD_SOURCE # enable __FAVOR_BSD (udp/tcp bsd struct over posix)
36 xcflags-y += -DKERNEL_MODULE # linux kernel module
37 xcflags-y += -I include_e -I include
38 xcflags-y += -include ../glue.h # headers
40 EXTRA_CFLAGS := $(xcflags-y)
42 # we should not export anything
43 #export-objs := ipfw2_mod.o
44 -include $(TOPDIR)/Rules.make
49 ifneq ($(shell echo $(VER)|grep '2.4'),)
50 $(warning "---- Building for Version $(VER)")
51 KERNELDIR := -isystem /usr/src/linux-2.4.35.4/include
52 # replace the system include directory
53 WARN += -nostdinc -isystem /usr/lib/gcc/i486-linux-gnu/4.2.4/include
54 #WARN = -Wp,-MD,/home/luigi/ports-luigi/dummynet-branches/ipfw_mod/dummynet/.ipfw2_mod.o.d
55 #WARN += -Iinclude -include include/linux/autoconf.h
57 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
58 WARN += -fno-common -Werror-implicit-function-declaration
59 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
60 # -mregparm=3 gives a printk error
61 WARN += -m32 -msoft-float # -mregparm=3
62 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
63 WARN += -Wno-sign-compare
64 WARN += -Wdeclaration-after-statement -Wno-pointer-sign
66 ccflags-y += -O1 -DLINUX_24
67 CFLAGS = -DMODULE -D__KERNEL__ ${KERNELDIR} ${ccflags-y}
72 # KERNELDIR is where the kernel headers reside
73 # XXX on Planetlab, KERNELDIR must be same as KERNELPATH
74 KERNELDIR ?= $(KERNELPATH)
75 # KERNELDIR := /home/luigi/linux-2.6.25.17/
77 #KERNELDIR := /usr/src/linux-2.6.24 # not with v.2237
78 #KERNELDIR := /usr/src/linux-2.6.26
79 #KERNELDIR := /usr/src/linux-2.6.22
80 #KERNELDIR := /usr/src/linux-source-2.6.26
81 #KERNELDIR := /lib/modules/`uname -r`/build
82 $(warning "---- Building Version 2.6 $(VER) in $(KERNELDIR)")
83 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
86 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
87 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELDIR)/include/linux/version.h|cut -d " " -f3)
88 ifeq ($(LINUX_VERSION_CODE),132630)
89 EXTRA_CFLAGS += $(ccflags-y)
93 $(MAKE) -C $(KERNELDIR) V=1 M=`pwd` modules
96 # the list of object use to build the module
97 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
99 # Original ipfw + dummynet + FreeBSD stuff,
100 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
102 # module glue and functions missing in linux
103 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
106 # additional $(CC) flags
108 ccflags-y += -DIPFIREWALL_DEFAULT_TO_ACCEPT
110 ccflags-y += -D_BSD_SOURCE # enable __FAVOR_BSD (udp/tcp bsd structure over posix)
111 ccflags-y += -DKERNEL_MODULE # linux kernel module
112 ccflags-y += -I $(M)/include_e -I $(M)/include
113 ccflags-y += -include $(M)/../glue.h # headers
115 mod24: include_e $(obj-m)
117 $(obj-m): $(ipfw_mod-y)
118 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
120 -rm -f *.o *.ko Module.symvers *.mod.c
123 -rm -f .*cmd modules.order opt_*
124 -rm -rf .tmp_versions include_e
126 # support to create empty dirs and files in include_e/
127 # EDIRS is the list of directories, EFILES is the list of files.
129 EDIRS= altq arpa machine net netinet netinet6 sys
131 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mac.h
132 EFILES += opt_mbuf_stress_test.h opt_param.h
134 EFILES += altq/if_altq.h
135 EFILES += arpa/inet.h
136 EFILES += machine/in_cksum.h
137 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h net/radix.h
139 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
140 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
141 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
142 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
143 EFILES += netinet/udp_var.h
145 EFILES += netinet6/ip6_var.h
147 EFILES += sys/_lock.h sys/_mutex.h sys/jail.h
148 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
149 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
150 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
155 -@rm -rf $(M)/include_e opt_*
156 -@mkdir -p $(M)/include_e
157 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )