2 # $Id: Makefile 4657 2010-01-04 11:20:53Z marta $
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 ip_fw_sockopt.c
42 IPFW_SRCS += ip_fw_dynamic.c ip_fw_table.c ip_fw_log.c
43 IPFW_SRCS += radix.c in_cksum.c
44 # Module glue and functions missing in linux
45 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
47 # generic cflags used on all systems
48 #ipfw-cflags += -DIPFW_HASHTABLES
49 ipfw-cflags += -DIPFIREWALL_DEFAULT_TO_ACCEPT
50 # _BSD_SOURCE enables __FAVOR_BSD (udp/tcp bsd structs instead of posix)
51 ipfw-cflags += -D_BSD_SOURCE
52 ipfw-cflags += -DKERNEL_MODULE # build linux kernel module
53 # the two header trees for empty and override files
54 ipfw-cflags += -I $(M)/include_e
55 ipfw-cflags += -I $(M)/include
56 ipfw-cflags += -include $(M)/../glue.h # headers
57 ipfw-cflags += -include $(M)/missing.h # headers
59 $(warning "---- Building dummynet kernel module for Version $(VER)")
61 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
64 #--- The Makefile section for openwrt ---
65 # We do not include a dependency on include_e as it is called
66 # by Makefile.openwrt in Build/Prepare
68 obj-y := $(IPFW_SRCS:%.c=%.o)
71 # xcflags-y is a temporary variable where we store build options
72 xcflags-y += -O1 -DLINUX_24
75 EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
77 # we should not export anything
78 #export-objs := ipfw2_mod.o
79 -include $(TOPDIR)/Rules.make
81 else # !openwrt, below we do linux builds for 2.4 and 2.6
83 # KERNELPATH is where the kernel headers reside. On PlanetLab
84 # it is set already by the build system.
85 # We can override it from the command line, or let the system guess.
87 ifneq ($(shell echo $(VER)|grep '2.4'),)
88 # Makefile section for the linux 2.4 version
89 # tested on linux-2.4.35.4, does not work with 2.4.37
91 # guess the kernel path -- or is it under /lib/modules ?
92 KERNELPATH ?= /usr/src/`uname -r`
94 # We need to figure out the gcc include directory, if not
95 # set by the user through MYGCC_INCLUDE
96 # Find compiler version (3rd field in last line returned by gcc -v)
97 # e.g. gcc version 4.3.2 (Debian 4.3.2-1.1)
98 MYGCC_VER ?= $(shell $(CC) -v 2>&1 |tail -n 1 | cut -d " " -f 3)
99 # We don't know the exact directory under /usr/lib/gcc so we guess
100 MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
101 $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
104 WARN += -Wall -Wundef
105 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
106 WARN += -fno-common -Werror-implicit-function-declaration
107 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
108 # -mregparm=3 gives a printk error
109 WARN += -m32 -msoft-float # -mregparm=3
110 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
111 WARN += -Wno-sign-compare
112 WARN += -Wdeclaration-after-statement
113 ifneq ($(MYGCC_VER),3.4.6)
114 WARN += -Wno-pointer-sign
117 ccflags-y += -O1 -DLINUX_24
118 CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
119 -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) \
126 # This is the Makefile section for Linux 2.6.x including planetlab
128 ifeq ($(IPFW_PLANETLAB),1)
129 $(warning "---- Building for PlanetLab")
130 ipfw-cflags += -DIPFW_PLANETLAB # PlanetLab compilation
132 # if not set, use the version from the installed system
133 KERNELPATH ?= /lib/modules/`uname -r`/build
134 # Otherwise, if you have kernel sources, try something like this:
135 #KERNELPATH = /usr/src/linux-2.6.22
136 $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
137 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
140 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
141 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
142 ifeq ($(shell if [ -z $(LINUX_VERSION_CODE) ] ; then echo "true"; fi),true)
143 $(warning "---- Perhaps you miss a (cd $(KERNELPATH); make oldconfig; make prepare; make scripts)");
145 ifeq ($(shell if [ $(LINUX_VERSION_CODE) -le 132630 ] ; then echo "true"; fi),true)
146 EXTRA_CFLAGS += $(ccflags-y)
150 $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
153 #-- back to the common section of code for Linux 2.4 and 2.6
155 # the list of objects used to build the module
156 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
158 # additional $(CC) flags
160 ccflags-y += $(ipfw-cflags)
161 # if we really want debug symbols...
164 mod24: include_e $(obj-m)
166 $(obj-m): $(ipfw_mod-y)
167 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
169 # M is the current directory, used in recursive builds
170 # so we allow it to be overridden
174 #--- various common targets
176 -rm -f *.o *.ko Module.symvers *.mod.c
180 -rm -f .*cmd modules.order opt_*
181 -rm -rf .tmp_versions include_e
184 # support to create empty dirs and files in include_e/
185 # EDIRS is the list of directories, EFILES is the list of files.
187 EDIRS= altq arpa machine net netinet netinet6 sys
189 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mpath.h
190 EFILES += opt_mbuf_stress_test.h opt_param.h
192 EFILES += altq/if_altq.h
193 EFILES += arpa/inet.h
194 EFILES += machine/in_cksum.h
195 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h
196 EFILES += net/bpf.h net/if_types.h
199 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
200 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
201 EFILES += netinet/in_systm.h
202 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
203 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
204 EFILES += netinet/udp_var.h
206 EFILES += netinet6/ip6_var.h
208 EFILES += sys/_lock.h sys/_rwlock.h sys/_mutex.h sys/jail.h
209 EFILES += sys/condvar.h sys/eventhandler.h sys/domain.h
210 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
211 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
212 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
216 -@rm -rf $(M)/include_e opt_*
217 -@mkdir -p $(M)/include_e
218 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
221 #--- some other targets for testing purposes
222 test_radix: test_radix.o radix.o
223 test_lookup: ip_fw_lookup.o
224 test_radix test_lookup: CFLAGS=-Wall -Werror -O1