4 # gnu Makefile to build linux module for ipfw+dummynet.
6 # The defaults are set to build without modifications on PlanetLab
7 # and possibly 2.6 versions.
10 # Some variables need to have specific names, because they are used
11 # by the build infrastructure on Linux and OpenWrt. They are:
13 # ccflags-y additional $(CC) flags
14 # M used by Kbuild, we must set it to `pwd`
15 # obj-m list of .o modules to build
16 # $(MOD)-y for each $MOD in obj-m, the list of objects
17 # obj-y same as above, for openwrt
18 # O_TARGET the link target, for openwrt
19 # EXTRA_CFLAGS as the name says... in openwrt
20 # EXTRA_CFLAGS is used in 2.6.22 module kernel compilation too
21 # KERNELPATH the path to the kernel sources or headers
23 # Not sure about this (the name might be reserved)
24 # ipfw-cflags our flags for building the module
26 # Other variables are only private and can be renamed. They include:
28 # VER linux version we are building for (2.4 2.6 or openwrt)
31 $(warning including dummynet/Makefile)
33 # lets default for 2.6 for planetlab builds
39 # generic cflags used on all systems
40 #ipfw-cflags += -DIPFW_HASHTABLES
41 ipfw-cflags += -DIPFIREWALL_DEFAULT_TO_ACCEPT -DTRACE
42 # _BSD_SOURCE enables __FAVOR_BSD (udp/tcp bsd structs instead of posix)
43 ipfw-cflags += -D_BSD_SOURCE
44 ipfw-cflags += -DKERNEL_MODULE # build linux kernel module
45 # the two header trees for empty and override files
46 ipfw-cflags += -I $(M)/include_e -I $(M)/include
47 ipfw-cflags += -include $(M)/../glue.h # headers
49 $(warning "---- Building dummynet kernel module for Version $(VER)")
50 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
54 obj-y := ipfw2_mod.o bsd_compat.o \
55 in_cksum.o ip_dummynet.o ip_fw2.o ip_fw_pfil.o radix.o
56 O_TARGET := ipfw_mod.o
58 # xcflags-y is a temporary variable where we store build options
59 xcflags-y += -O1 -DLINUX_24
62 EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
64 # we should not export anything
65 #export-objs := ipfw2_mod.o
66 -include $(TOPDIR)/Rules.make
68 else # !openwrt, below we do linux builds for 2.4 and 2.6
70 # KERNELPATH is where the kernel headers reside. On PlanetLab
71 # it is set already by the build system.
72 # We can override it from the command line, or let the system guess.
74 ifneq ($(shell echo $(VER)|grep '2.4'),)
75 # The linux 2.4 version
76 # guess the kernel path -- or is it under /lib/modules ?
77 KERNELPATH ?= /usr/src/`uname -r`/build
79 # Guess the gcc include directory
80 # The gcc version is in the last line returned by gcc -v
81 # gcc version 4.3.2 (Debian 4.3.2-1.1)
82 MYGCC_VER ?= $(shell gcc -v 2>&1 |tail -n 1 | cut -d " " -f 3)
83 # We don't know the exact directory unde /usr/lib/gcc so we guess
84 MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
85 $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
88 #WARN = -Wp,-MD,/home/luigi/ports-luigi/dummynet-branches/ipfw_mod/dummynet/.ipfw2_mod.o.d
89 #WARN += -Iinclude -include include/linux/autoconf.h
92 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
93 WARN += -fno-common -Werror-implicit-function-declaration
94 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
95 # -mregparm=3 gives a printk error
96 WARN += -m32 -msoft-float # -mregparm=3
97 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
98 WARN += -Wno-sign-compare
99 WARN += -Wdeclaration-after-statement -Wno-pointer-sign
101 ccflags-y += -O1 -DLINUX_24
102 CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
103 -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) ${ccflags-y}
108 ifeq ($(IPFW_PLANETLAB),1)
109 $(warning "---- Building for PlanetLab")
110 ipfw-cflags += -DIPFW_PLANETLAB # PlanetLab compilation
112 # if not set, use the version from the installed system
113 KERNELPATH ?= /lib/modules/`uname -r`/build
115 #KERNELPATH = /usr/src/linux-2.6.22
116 $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
117 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
120 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
121 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
122 ifeq ($(LINUX_VERSION_CODE),132630)
123 EXTRA_CFLAGS += $(ccflags-y)
127 $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
130 #-- back to the common section of code
132 # the list of objects used to build the module
133 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
135 # Original ipfw and dummynet sources + FreeBSD stuff,
136 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
138 # Module glue and functions missing in linux
139 IPFW_SRCS += ipfw2_mod.c bsd_compat.c hashtable.c
141 # additional $(CC) flags
143 ccflags-y += $(ipfw-cflags)
146 mod24: include_e $(obj-m)
148 $(obj-m): $(ipfw_mod-y)
149 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
151 -rm -f *.o *.ko Module.symvers *.mod.c
155 -rm -f .*cmd modules.order opt_*
156 -rm -rf .tmp_versions include_e
159 # support to create empty dirs and files in include_e/
160 # EDIRS is the list of directories, EFILES is the list of files.
162 EDIRS= altq arpa machine net netinet netinet6 sys
164 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mpath.h
165 EFILES += opt_mbuf_stress_test.h opt_param.h
167 EFILES += altq/if_altq.h
168 EFILES += arpa/inet.h
169 EFILES += machine/in_cksum.h
170 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h
173 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
174 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
175 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
176 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
177 EFILES += netinet/udp_var.h
179 EFILES += netinet6/ip6_var.h
181 EFILES += sys/_lock.h sys/_rwlock.h sys/_mutex.h sys/jail.h
182 EFILES += sys/condvar.h sys/eventhandler.h sys/domain.h
183 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
184 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
185 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
190 -@rm -rf $(M)/include_e opt_*
191 -@mkdir -p $(M)/include_e
192 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
196 test_radix: test_radix.o radix.o
197 test_radix: CFLAGS=-Wall -Werror -O1