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 += -DIPFIREWALL_DEFAULT_TO_ACCEPT -DTRACE
41 # _BSD_SOURCE enables __FAVOR_BSD (udp/tcp bsd structs instead of posix)
42 ipfw-cflags += -D_BSD_SOURCE
43 ipfw-cflags += -DKERNEL_MODULE # build linux kernel module
44 # the two header trees for empty and override files
45 ipfw-cflags += -I $(M)/include_e -I $(M)/include
46 ipfw-cflags += -include $(M)/../glue.h # headers
48 $(warning "---- Building dummynet kernel module for Version $(VER)")
49 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
53 obj-y := ipfw2_mod.o bsd_compat.o \
54 in_cksum.o ip_dummynet.o ip_fw2.o ip_fw_pfil.o
55 O_TARGET := ipfw_mod.o
57 # xcflags-y is a temporary variable where we store build options
58 xcflags-y += -O1 -DLINUX_24
61 EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
63 # we should not export anything
64 #export-objs := ipfw2_mod.o
65 -include $(TOPDIR)/Rules.make
67 else # !openwrt, below we do linux builds for 2.4 and 2.6
69 # KERNELPATH is where the kernel headers reside. On PlanetLab
70 # it is set already by the build system.
71 # We can override it from the command line, or let the system guess.
73 ifneq ($(shell echo $(VER)|grep '2.4'),)
74 # The linux 2.4 version
75 # guess the kernel path -- or is it under /lib/modules ?
76 KERNELPATH ?= /usr/src/`uname -r`/build
78 # Guess the gcc include directory
79 # The gcc version is in the last line returned by gcc -v
80 # gcc version 4.3.2 (Debian 4.3.2-1.1)
81 MYGCC_VER ?= $(shell gcc -v 2>&1 |tail -n 1 | cut -d " " -f 3)
82 # We don't know the exact directory unde /usr/lib/gcc so we guess
83 MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
84 $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
87 #WARN = -Wp,-MD,/home/luigi/ports-luigi/dummynet-branches/ipfw_mod/dummynet/.ipfw2_mod.o.d
88 #WARN += -Iinclude -include include/linux/autoconf.h
91 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
92 WARN += -fno-common -Werror-implicit-function-declaration
93 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
94 # -mregparm=3 gives a printk error
95 WARN += -m32 -msoft-float # -mregparm=3
96 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
97 WARN += -Wno-sign-compare
98 WARN += -Wdeclaration-after-statement -Wno-pointer-sign
100 ccflags-y += -O1 -DLINUX_24
101 CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
102 -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) ${ccflags-y}
107 ifeq ($(IPFW_PLANETLAB),1)
108 $(warning "---- Building for PlanetLab")
109 ipfw-cflags += -DIPFW_PLANETLAB # PlanetLab compilation
111 # if not set, use the version from the installed system
112 KERNELPATH ?= /lib/modules/`uname -r`/build
114 #KERNELPATH = /usr/src/linux-2.6.22
115 $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
116 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
119 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
120 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
121 ifeq ($(LINUX_VERSION_CODE),132630)
122 EXTRA_CFLAGS += $(ccflags-y)
126 $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
129 #-- back to the common section of code
131 # the list of objects used to build the module
132 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
134 # Original ipfw and dummynet sources + FreeBSD stuff,
135 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
137 # Module glue and functions missing in linux
138 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
140 # additional $(CC) flags
142 ccflags-y += $(ipfw-cflags)
145 mod24: include_e $(obj-m)
147 $(obj-m): $(ipfw_mod-y)
148 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
150 -rm -f *.o *.ko Module.symvers *.mod.c
153 -rm -f .*cmd modules.order opt_*
154 -rm -rf .tmp_versions include_e
155 -rm -rf .ip_dummynet.o.d
157 # support to create empty dirs and files in include_e/
158 # EDIRS is the list of directories, EFILES is the list of files.
160 EDIRS= altq arpa machine net netinet netinet6 sys
162 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mac.h
163 EFILES += opt_mbuf_stress_test.h opt_param.h
165 EFILES += altq/if_altq.h
166 EFILES += arpa/inet.h
167 EFILES += machine/in_cksum.h
168 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h net/radix.h
170 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
171 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
172 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
173 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
174 EFILES += netinet/udp_var.h
176 EFILES += netinet6/ip6_var.h
178 EFILES += sys/_lock.h sys/_mutex.h sys/jail.h
179 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
180 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
181 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
186 -@rm -rf $(M)/include_e opt_*
187 -@mkdir -p $(M)/include_e
188 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )