Added the new version for dummynet.
[ipfw.git] / dummynet2 / Makefile
1 #
2 # $Id: Makefile 4657 2010-01-04 11:20:53Z marta $
3 #
4 # gnu Makefile to build linux module for ipfw+dummynet.
5 #
6 # The defaults are set to build without modifications on PlanetLab
7 # and possibly 2.6 versions.
8
9 # Some variables need to have specific names, because they are used
10 # by the build infrastructure on Linux and OpenWrt. They are:
11
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
21 #
22 # Not sure about this (the name might be reserved)
23 #   ipfw-cflags         our flags for building the module
24 #
25 # Other variables are only private and can be renamed. They include:
26 #
27 #   VER         linux version we are building for (2.4 2.6 or openwrt)
28 #---
29
30 $(warning including dummynet/Makefile)
31
32 # lets default for 2.6 for planetlab builds
33 VER ?= 2.6
34
35 #--- General values for all types of build ---
36 # obj-m is the target module
37 obj-m := ipfw_mod.o
38
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
46
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 # XXX eventually ../dummynet/include will go away
57 ipfw-cflags += -I $(M)/../dummynet/include
58 ipfw-cflags += -include $(M)/../glue.h  # headers
59 ipfw-cflags += -include $(M)/missing.h  # headers
60
61 $(warning "---- Building dummynet kernel module for Version $(VER)")
62
63 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
64
65 ifeq ($(VER),openwrt)
66   #--- The Makefile section for openwrt ---
67   # We do not include a dependency on include_e as it is called
68   # by Makefile.openwrt in Build/Prepare
69   M=.
70   obj-y := $(IPFW_SRCS:%.c=%.o)
71   O_TARGET := $(obj-m)
72
73   # xcflags-y is a temporary variable where we store build options
74   xcflags-y += -O1 -DLINUX_24
75   xcflags-y += -g
76
77   EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
78
79   # we should not export anything
80   #export-objs := ipfw2_mod.o
81 -include $(TOPDIR)/Rules.make
82
83 else    # !openwrt, below we do linux builds for 2.4 and 2.6
84
85   # KERNELPATH is where the kernel headers reside. On PlanetLab
86   # it is set already by the build system.
87   # We can override it from the command line, or let the system guess.
88
89 ifneq ($(shell echo $(VER)|grep '2.4'),)
90   # Makefile section for the linux 2.4 version
91   # tested on linux-2.4.35.4, does not work with 2.4.37
92   #
93   # guess the kernel path -- or is it under /lib/modules ?
94   KERNELPATH ?= /usr/src/`uname -r`
95
96   # We need to figure out the gcc include directory, if not
97   # set by the user through MYGCC_INCLUDE
98   # Find compiler version (3rd field in last line returned by gcc -v)
99   # e.g.        gcc version 4.3.2 (Debian 4.3.2-1.1)
100   MYGCC_VER ?= $(shell $(CC) -v 2>&1 |tail -n 1 | cut -d " " -f 3)
101   # We don't know the exact directory under /usr/lib/gcc so we guess
102   MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
103   $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
104
105   # additional warning
106   WARN += -Wall -Wundef
107   WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
108   WARN += -fno-common -Werror-implicit-function-declaration
109   # WARN += -O2  -fno-stack-protector -m32 -msoft-float -mregparm=3
110   # -mregparm=3 gives a printk error
111   WARN += -m32 -msoft-float # -mregparm=3
112   #WARN += -freg-struct-return -mpreferred-stack-boundary=2
113   WARN += -Wno-sign-compare
114   WARN += -Wdeclaration-after-statement
115   ifneq ($(MYGCC_VER),3.4.6)
116         WARN += -Wno-pointer-sign
117   endif
118
119   ccflags-y += -O1 -DLINUX_24
120   CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
121         -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) \
122         ${ccflags-y}
123   # The Main target
124 all: mod24
125
126 else # !2.4 --
127
128   # This is the Makefile section for Linux 2.6.x including planetlab
129
130 ifeq ($(IPFW_PLANETLAB),1)
131   $(warning "---- Building for PlanetLab")
132   ipfw-cflags += -DIPFW_PLANETLAB        # PlanetLab compilation
133 endif
134   # if not set, use the version from the installed system
135   KERNELPATH ?= /lib/modules/`uname -r`/build
136   # Otherwise, if you have kernel sources, try something like this:
137   #KERNELPATH = /usr/src/linux-2.6.22
138   $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
139   WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
140   # The main target
141
142   # Required by kernel <= 2.6.22, ccflags-y is used on newer version
143   LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
144   ifeq ($(shell if [ -z $(LINUX_VERSION_CODE) ] ; then echo "true"; fi),true)
145     $(warning "---- Perhaps you miss a (cd $(KERNELPATH); make oldconfig; make prepare; make scripts)");
146   endif
147   ifeq ($(shell if [ $(LINUX_VERSION_CODE) -le 132630 ] ; then echo "true"; fi),true)
148     EXTRA_CFLAGS += $(ccflags-y)
149   endif
150
151 all: include_e
152         $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
153 endif # !2.4
154
155 #-- back to the common section of code for Linux 2.4 and 2.6
156
157 # the list of objects used to build the module
158 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
159
160 # additional $(CC) flags
161 ccflags-y += $(WARN)
162 ccflags-y += $(ipfw-cflags)
163 # if we really want debug symbols...
164 ccflags-y += -g
165
166 mod24: include_e $(obj-m)
167
168 $(obj-m): $(ipfw_mod-y)
169         $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
170
171 # M is the current directory, used in recursive builds
172 # so we allow it to be overridden
173 M ?= $(shell pwd)
174 endif # !openwrt
175
176 #--- various common targets
177 clean:
178         -rm -f *.o *.ko Module.symvers *.mod.c
179         -rm -rf include_e
180
181 distclean: clean
182         -rm -f .*cmd modules.order opt_*
183         -rm -rf .tmp_versions include_e
184         -rm -rf .*.o.d
185
186 # support to create empty dirs and files in include_e/
187 # EDIRS is the list of directories, EFILES is the list of files.
188
189 EDIRS= altq arpa machine net netinet netinet6 sys
190
191 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mpath.h
192 EFILES += opt_mbuf_stress_test.h opt_param.h
193
194 EFILES += altq/if_altq.h
195 EFILES += arpa/inet.h
196 EFILES += machine/in_cksum.h
197 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h
198 EFILES += net/bpf.h net/if_types.h
199 EFILES += net/vnet.h
200
201 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
202 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
203 EFILES += netinet/in_systm.h
204 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
205 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
206 EFILES += netinet/udp_var.h
207
208 EFILES += netinet6/ip6_var.h
209
210 EFILES += sys/_lock.h sys/_rwlock.h sys/_mutex.h sys/jail.h
211 EFILES += sys/condvar.h sys/eventhandler.h sys/domain.h
212 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
213 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
214 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
215
216 include_e:
217         echo "running in $M"
218         -@rm -rf $(M)/include_e opt_*
219         -@mkdir -p $(M)/include_e
220         -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
221
222
223 #--- some other targets for testing purposes
224 test_radix: test_radix.o radix.o
225 test_lookup: ip_fw_lookup.o
226 test_radix test_lookup: CFLAGS=-Wall -Werror -O1