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.
9 # Some variables need to have specific names, because they are used
10 # by the build infrastructure on Linux and OpenWrt. They are:
12 # ccflags-y additional $(CC) flags
13 # M used by Kbuild, we must set it to `pwd`
14 # obj-m list of .o modules to build
15 # $(MOD)-y for each $MOD in obj-m, the list of objects
16 # obj-y same as above, for openwrt
17 # O_TARGET the link target, for openwrt
18 # EXTRA_CFLAGS as the name says... in openwrt
19 # EXTRA_CFLAGS is used in 2.6.22 module kernel compilation too
20 # KERNELPATH the path to the kernel sources or headers
22 # Not sure about this (the name might be reserved)
23 # ipfw-cflags our flags for building the module
25 # Other variables are only private and can be renamed. They include:
27 # VER linux version we are building for (2.4 2.6 or openwrt)
30 $(warning including dummynet/Makefile)
32 # lets default for 2.6 for planetlab builds
35 #--- General values for all types of build ---
36 # obj-m is the target module
39 #-- the list of source files. IPFW_SRCS is our own name.
40 # Original ipfw and dummynet sources + FreeBSD stuff,
41 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
43 # Module glue and functions missing in linux
44 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
46 # generic cflags used on all systems
47 #ipfw-cflags += -DIPFW_HASHTABLES
48 ipfw-cflags += -DIPFIREWALL_DEFAULT_TO_ACCEPT
49 # _BSD_SOURCE enables __FAVOR_BSD (udp/tcp bsd structs instead of posix)
50 ipfw-cflags += -D_BSD_SOURCE
51 ipfw-cflags += -DKERNEL_MODULE # build linux kernel module
52 # the two header trees for empty and override files
53 ipfw-cflags += -I $(M)/include_e
54 ipfw-cflags += -I $(M)/include
55 ipfw-cflags += -include $(M)/../glue.h # headers
56 ipfw-cflags += -include $(M)/missing.h # headers
58 $(warning "---- Building dummynet kernel module for Version $(VER)")
60 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
63 #--- The Makefile section for openwrt ---
64 # We do not include a dependency on include_e as it is called
65 # by Makefile.openwrt in Build/Prepare
67 obj-y := $(IPFW_SRCS:%.c=%.o)
70 # xcflags-y is a temporary variable where we store build options
71 xcflags-y += -O1 -DLINUX_24
74 EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
76 # we should not export anything
77 #export-objs := ipfw2_mod.o
78 -include $(TOPDIR)/Rules.make
80 else # !openwrt, below we do linux builds for 2.4 and 2.6
82 # KERNELPATH is where the kernel headers reside. On PlanetLab
83 # it is set already by the build system.
84 # We can override it from the command line, or let the system guess.
86 ifneq ($(shell echo $(VER)|grep '2.4'),)
87 # Makefile section for the linux 2.4 version
88 # tested on linux-2.4.35.4, does not work with 2.4.37
90 # guess the kernel path -- or is it under /lib/modules ?
91 KERNELPATH ?= /usr/src/`uname -r`
93 # We need to figure out the gcc include directory, if not
94 # set by the user through MYGCC_INCLUDE
95 # Find compiler version (3rd field in last line returned by gcc -v)
96 # e.g. gcc version 4.3.2 (Debian 4.3.2-1.1)
97 MYGCC_VER ?= $(shell $(CC) -v 2>&1 |tail -n 1 | cut -d " " -f 3)
98 # We don't know the exact directory under /usr/lib/gcc so we guess
99 MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
100 $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
103 WARN += -Wall -Wundef
104 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
105 WARN += -fno-common -Werror-implicit-function-declaration
106 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
107 # -mregparm=3 gives a printk error
108 WARN += -m32 -msoft-float # -mregparm=3
109 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
110 WARN += -Wno-sign-compare
111 WARN += -Wdeclaration-after-statement
112 ifneq ($(MYGCC_VER),3.4.6)
113 WARN += -Wno-pointer-sign
116 ccflags-y += -O1 -DLINUX_24
117 CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
118 -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) \
125 # This is the Makefile section for Linux 2.6.x including planetlab
127 ifeq ($(IPFW_PLANETLAB),1)
128 $(warning "---- Building for PlanetLab")
129 ipfw-cflags += -DIPFW_PLANETLAB # PlanetLab compilation
131 # if not set, use the version from the installed system
132 KERNELPATH ?= /lib/modules/`uname -r`/build
133 # Otherwise, if you have kernel sources, try something like this:
134 #KERNELPATH = /usr/src/linux-2.6.22
135 $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
136 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
139 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
140 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
141 ifeq ($(shell if [ -z $(LINUX_VERSION_CODE) ] ; then echo "true"; fi),true)
142 $(warning "---- Perhaps you miss a (cd $(KERNELPATH); make oldconfig; make prepare; make scripts)");
144 ifeq ($(shell if [ $(LINUX_VERSION_CODE) -le 132630 ] ; then echo "true"; fi),true)
145 EXTRA_CFLAGS += $(ccflags-y)
149 $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
152 #-- back to the common section of code for Linux 2.4 and 2.6
154 # the list of objects used to build the module
155 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
157 # additional $(CC) flags
159 ccflags-y += $(ipfw-cflags)
160 # if we really want debug symbols...
163 mod24: include_e $(obj-m)
165 $(obj-m): $(ipfw_mod-y)
166 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
168 # M is the current directory, used in recursive builds
169 # so we allow it to be overridden
173 #--- various common targets
175 -rm -f *.o *.ko Module.symvers *.mod.c
179 -rm -f .*cmd modules.order opt_*
180 -rm -rf .tmp_versions include_e
183 # support to create empty dirs and files in include_e/
184 # EDIRS is the list of directories, EFILES is the list of files.
186 EDIRS= altq arpa machine net netinet netinet6 sys
188 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mpath.h
189 EFILES += opt_mbuf_stress_test.h opt_param.h
191 EFILES += altq/if_altq.h
192 EFILES += arpa/inet.h
193 EFILES += machine/in_cksum.h
194 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h
197 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
198 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
199 EFILES += netinet/in_systm.h
200 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
201 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
202 EFILES += netinet/udp_var.h
204 EFILES += netinet6/ip6_var.h
206 EFILES += sys/_lock.h sys/_rwlock.h sys/_mutex.h sys/jail.h
207 EFILES += sys/condvar.h sys/eventhandler.h sys/domain.h
208 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
209 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
210 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
214 -@rm -rf $(M)/include_e opt_*
215 -@mkdir -p $(M)/include_e
216 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
219 #--- some other targets for testing purposes
220 test_radix: test_radix.o radix.o
221 test_radix: CFLAGS=-Wall -Werror -O2