This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / dummynet2 / Makefile
1 # $Id: Makefile 11277 2012-06-10 17:44:15Z marta $
2 # gnu Makefile to build linux/Windows module for ipfw+dummynet.
3 #
4 # The defaults are set to build without modifications on PlanetLab
5 # and possibly 2.6 versions.
6 # On Windows, we use gnu-make and MSC
7
8 # Some variables need to have specific names, because they are used
9 # by the build infrastructure on Linux and OpenWrt. They are:
10
11 #   ccflags-y   additional $(CC) flags
12 #   M           used by Kbuild, we must set it to `pwd`
13 #   obj-m       list of .o modules to build
14 #   $(MOD)-y    for each $MOD in obj-m, the list of objects
15 #   obj-y       same as above, for openwrt
16 #   O_TARGET    the link target, for openwrt
17 #   EXTRA_CFLAGS as the name says... in openwrt
18 #   EXTRA_CFLAGS is used in 2.6.22 module kernel compilation too
19 #   KERNELPATH  the path to the kernel sources or headers
20 #
21 # Not sure about this (the name might be reserved)
22 #   ipfw-cflags         our flags for building the module
23 #
24 # Other variables are only private and can be renamed. They include:
25 #
26 #   VER         linux version we are building for (2.4 2.6 or openwrt)
27 #---
28
29 UNAME:=$(shell uname)
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_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 IPFW_SRCS += ip_dummynet.c ip_dn_io.c ip_dn_glue.c
45 IPFW_SRCS += dn_heap.c
46 IPFW_SRCS += dn_sched_fifo.c dn_sched_wf2q.c
47 IPFW_SRCS += dn_sched_rr.c dn_sched_qfq.c
48 IPFW_SRCS += dn_sched_prio.c
49 # Module glue and functions missing in linux
50 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
51
52 # generic cflags used on all systems
53 #ipfw-cflags += -DIPFW_HASHTABLES
54 ipfw-cflags += -DIPFIREWALL_DEFAULT_TO_ACCEPT
55 # _BSD_SOURCE enables __FAVOR_BSD (udp/tcp bsd structs instead of posix)
56 ipfw-cflags += -D_BSD_SOURCE
57 ipfw-cflags += -DKERNEL_MODULE  # build linux kernel module
58 # the two header trees for empty and override files
59 ipfw-cflags += -I $(M)/include_e
60 ipfw-cflags += -I $(M)/include
61 ipfw-cflags += -include $(M)/../glue.h  # headers
62 ipfw-cflags += -include $(M)/missing.h  # headers
63
64 $(warning "---- Building dummynet kernel module for Version $(VER)")
65
66 ifneq (,$(findstring CYGWIN,$(shell uname)))
67     ISWIN=1
68 endif
69 ifneq ($(TCC),)
70     ISWIN=1
71 endif
72 ifeq ($(ISWIN),1)
73     M ?= $(shell pwd)
74     WIN_SRCS += md_win.c
75     WIN_SRCS += miniport.c protocol.c passthru.c debug.c
76     #compiler, linker, target, sources and objects
77     #DDK is exported from the root makefile
78     #DDK = C:/WinDDK/7600.16385.1
79     OBJDIR=objchk_wxp_x86/i386/
80
81     TARGET = ipfw
82
83     CSOURCES = $(IPFW_SRCS) $(WIN_SRCS)
84
85     COBJS := $(CSOURCES:.c=.obj)
86     COBJS := $(addprefix $(OBJDIR),$(COBJS))
87
88     #include paths
89     INCLUDE_PATHS = -Ii386 -Iinclude -Iinclude_e -I.
90     # INCLUDE_PATHS += -I$(OBJDIR)
91     INCLUDE_PATHS += -I$(DDK)/inc/api
92     INCLUDE_PATHS += -I$(DDK)/inc/ddk
93     INCLUDE_PATHS += -I$(DDK)/inc/crt
94
95     # #preprocessor MS defines
96     PREPROC  = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1
97     PREPROC += -DNT_UP=0 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 -DWINNT=1
98     PREPROC += -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 -D_WIN32_IE=0x0603
99     PREPROC += -DWIN32_LEAN_AND_MEAN=1 
100     PREPROC += -D__BUILDMACHINE__=WinDDK -DFPO=0 -D_DLL=1
101     PREPROC += -DNDIS_MINIPORT_DRIVER -DNDIS_WDM=1
102     PREPROC += -DNDIS51_MINIPORT=1 -DNDIS51=1
103     PREPROC += -DMSC_NOOPT -DNTDDI_VERSION=0x05010200
104     PREPROC += -DKMDF_MAJOR_VERSION_STRING=01 -DKMDF_MINOR_VERSION_STRING=009
105     #PREPROC += -DDBG=1 #debug
106     PREPROC += -DNDEBUG #always up, seems no effect, possibly no debug?
107     PREPROC += -DDEVL=1 #always up, seems no effect
108     #macroing module name, WARNING: must match the one in .inf files
109     PREPROC += -DMODULENAME=Ipfw 
110
111     #our defines
112     OUR_PREPROC  = -D_KERNEL -DKERNEL_MODULE -DKLD_MODULE
113     OUR_PREPROC += -D__BSD_VISIBLE -DIPFIREWALL_DEFAULT_TO_ACCEPT
114     OUR_PREPROC += -D__LITTLE_ENDIAN -DSYSCTL_NODE -DEMULATE_SYSCTL
115
116 ifeq ($(TCC),)
117     CC = $(DDK)/bin/x86/x86/cl.exe
118     LD = $(DDK)/bin/x86/x86/link.exe
119     # #complier options
120     CFLAGS  = -Fo$(OBJDIR)  -c -FC -Zc:wchar_t-
121     CFLAGS += -Zl -Zp8 -Gy -Gm- -GF -cbstring -Gz -hotpatch -EHs-c-
122     CFLAGS += -W2 # -W3 gives too many conversion errors
123     CFLAGS += -GR- -GF -GS -Zi  # XXX do we need this ?
124     CFLAGS += -Fd$(OBJDIR)
125     CFLAGS += -wd4603 -wd4627 -typedil-
126     CFLAGS += -FI $(DDK)/inc/api/warning.h
127     CFLAGS += -FI winmissing.h
128     CFLAGS += -FI missing.h     # headers
129     CFLAGS += -FI ../glue.h     # headers
130
131     #optimization options
132     OPTIMIZE = -Od -Oi -Oy-
133
134     #linker options
135     LDFLAGS  = /MERGE:_PAGE=PAGE /MERGE:_TEXT=.text
136     LDFLAGS += /SECTION:INIT,d /OPT:REF /OPT:ICF
137     LDFLAGS += /IGNORE:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221
138     LDFLAGS += /INCREMENTAL:NO /release /NODEFAULTLIB /WX
139     LDFLAGS += /debug /debugtype:cv,fixup,pdata
140     LDFLAGS += /version:6.1 /osversion:6.1 /functionpadmin:5
141     LDFLAGS += /safeseh /pdbcompress
142     LDFLAGS += /STACK:0x40000,0x1000 /driver /base:0x10000 /align:0x80
143     LDFLAGS += /stub:$(DDK)\\lib\\wxp\\stub512.com
144     LDFLAGS += /subsystem:native,5.01 /entry:GsDriverEntry@8
145     LDFLAGS += /out:$(OBJDIR)/ipfw.sys
146
147     #libraries to build against
148     LIBS  = $(DDK)/lib/wxp/i386/BufferOverflowK.lib
149     LIBS += $(DDK)/lib/wxp/i386/ntoskrnl.lib
150     LIBS += $(DDK)/lib/wxp/i386/hal.lib
151     LIBS += $(DDK)/lib/wxp/i386/wmilib.lib
152     LIBS += $(DDK)/lib/wxp/i386/ndis.lib
153     LIBS += $(DDK)/lib/wxp/i386/sehupd.lib
154 else
155     # TCC points to the root of tcc tree
156     CC=$(TCC)/bin/wintcc
157     EXTRA_CFLAGS += -DTCC -I..
158     EXTRA_CFLAGS += -I$(TCC)/include/winapi -I$(TCC)/include
159     EXTRA_CFLAGS += -nostdinc
160
161     CFLAGS += -include winmissing.h -include missing.h -include ../glue.h
162     CFLAGS += -I../../inc/api -I../../inc/ddk -I../../inc/crt
163     CFLAGS += -DRC_INVOKED
164 endif
165
166     #empty include directory to be built
167     M ?= $(shell pwd)
168     EDIRS += asm linux
169     EFILES += asm/div64.h
170     EFILES += linux/if.h linux/random.h linux/errno.h
171     EFILES += net/if_types.h net/inet_hashtables.h net/route.h
172
173     #targets
174 all: $(TARGET)
175
176 $(TARGET): include_e
177         rm -rf objchk_wxp_x86
178         mkdir -p objchk_wxp_x86/i386
179         $(CC) $(INCLUDE_PATHS) $(PREPROC) $(OUR_PREPROC) $(CFLAGS) $(OPTIMIZE) $(CSOURCES)
180         $(LD) $(LDFLAGS) $(COBJS) $(LIBS)
181
182 else # !windows
183
184 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
185
186 ifeq ($(VER),openwrt)
187   #--- The Makefile section for openwrt ---
188   # We do not include a dependency on include_e as it is called
189   # by Makefile.openwrt in Build/Prepare
190   M=.
191   obj-y := $(IPFW_SRCS:%.c=%.o)
192   O_TARGET := $(obj-m)
193
194   # xcflags-y is a temporary variable where we store build options
195   xcflags-y += -O1 -DLINUX_24
196   xcflags-y += -g
197
198   EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags) -DSYSCTL_NODE -DEMULATE_SYSCTL
199
200   # we should not export anything
201   #export-objs := ipfw2_mod.o
202 -include $(TOPDIR)/Rules.make
203
204 else    # !openwrt, below we do linux builds for 2.4 and 2.6
205
206   # KERNELPATH is where the kernel headers reside. On PlanetLab
207   # it is set already by the build system.
208   # We can override it from the command line, or let the system guess.
209
210 ifneq ($(shell echo $(VER)|grep '2.4'),)
211   # Makefile section for the linux 2.4 version
212   # tested on linux-2.4.35.4, does not work with 2.4.37
213   #
214   # guess the kernel path -- or is it under /lib/modules ?
215   KERNELPATH ?= /usr/src/`uname -r`
216
217   # We need to figure out the gcc include directory, if not
218   # set by the user through MYGCC_INCLUDE
219   # Find compiler version (3rd field in last line returned by gcc -v)
220   # e.g.        gcc version 4.3.2 (Debian 4.3.2-1.1)
221   MYGCC_VER ?= $(shell $(CC) -v 2>&1 |tail -n 1 | cut -d " " -f 3)
222   # We don't know the exact directory under /usr/lib/gcc so we guess
223   MYGCC_INCLUDE ?= $(shell echo /usr/lib/gcc/*/$(MYGCC_VER) | cut -d " " -f 1)/include
224   $(warning "---- gcc includes guessed to $(MYGCC_INCLUDE)")
225
226   # additional warning
227   WARN += -Wall -Wundef
228   WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
229   WARN += -fno-common -Werror-implicit-function-declaration
230   # WARN += -O2  -fno-stack-protector -m32 -msoft-float -mregparm=3
231   # -mregparm=3 gives a printk error
232   WARN += -m32 -msoft-float # -mregparm=3
233   #WARN += -freg-struct-return -mpreferred-stack-boundary=2
234   WARN += -Wno-sign-compare
235   WARN += -Wdeclaration-after-statement
236   ifneq ($(MYGCC_VER),3.4.6)
237         WARN += -Wno-pointer-sign
238   endif
239
240   ccflags-y += -O1 -DLINUX_24
241   CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
242         -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) \
243         ${ccflags-y}
244   # The Main target
245 all: mod24
246
247 else # !2.4 --
248
249   # This is the Makefile section for Linux 2.6.x including planetlab
250
251 ifeq ($(IPFW_PLANETLAB),1)
252   $(warning "---- Building for PlanetLab")
253   ipfw-cflags += -DIPFW_PLANETLAB        # PlanetLab compilation
254 endif
255   # if not set, use the version from the installed system
256   KERNELPATH ?= /lib/modules/`uname -r`/build
257   # Otherwise, if you have kernel sources, try something like this:
258   #KERNELPATH = /usr/src/linux-2.6.22
259   $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
260   WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
261   # The main target
262
263   # Required by GCC 4.6
264   ccflags-y += -Wno-unused-but-set-variable
265
266   # Required by kernel <= 2.6.22, ccflags-y is used on newer version
267   LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELPATH)/include/linux/version.h|cut -d " " -f3)
268   ifeq ($(shell if [ -z $(LINUX_VERSION_CODE) ] ; then echo "true"; fi),true)
269     $(warning "---- Perhaps you miss a (cd $(KERNELPATH); make oldconfig; make prepare; make scripts)");
270   endif
271   ifeq ($(shell if [ "$(LINUX_VERSION_CODE)" -le 132630 ] ; then echo "true"; fi),true)
272     EXTRA_CFLAGS += $(ccflags-y)
273   endif
274
275 all: include_e
276         $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
277 endif # !2.4
278
279 #-- back to the common section of code for Linux 2.4 and 2.6
280
281 # the list of objects used to build the module
282 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
283
284 # additional $(CC) flags
285 ccflags-y += $(WARN)
286 ccflags-y += $(ipfw-cflags)
287 # if we really want debug symbols...
288 ccflags-y += -g
289
290 mod24: include_e $(obj-m)
291
292 $(obj-m): $(ipfw_mod-y)
293         $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
294
295 # M is the current directory, used in recursive builds
296 # so we allow it to be overridden
297 M ?= $(shell pwd)
298 endif # !openwrt
299 endif # !windows
300
301 #--- various common targets
302 clean:
303         -rm -f *.o *.ko Module.symvers *.mod.c
304         -rm -rf objchk_wxp_x86
305         -rm -rf include_e
306
307 distclean: clean
308         -rm -f .*cmd modules.order opt_*
309         -rm -rf .tmp_versions include_e
310         -rm -rf .*.o.d _CL_*
311
312 # support to create empty dirs and files in include_e/
313 # EDIRS is the list of directories, EFILES is the list of files.
314
315 EDIRS  += altq arpa machine net netinet netinet6 sys
316
317 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mpath.h
318 EFILES += opt_mbuf_stress_test.h opt_param.h
319
320 EFILES += altq/if_altq.h
321 EFILES += arpa/inet.h
322 EFILES += machine/in_cksum.h
323 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h
324 EFILES += net/bpf.h net/if_types.h
325 EFILES += net/vnet.h
326
327 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
328 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
329 EFILES += netinet/in_systm.h
330 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
331 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
332 EFILES += netinet/udp_var.h
333
334 EFILES += netinet6/ip6_var.h
335
336 EFILES += sys/_lock.h sys/_rwlock.h sys/rmlock.h sys/_mutex.h sys/jail.h
337 EFILES += sys/condvar.h sys/eventhandler.h sys/domain.h
338 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
339 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
340 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
341
342 include_e:
343         echo "running in $M"
344         -@rm -rf $(M)/include_e opt_*
345         -@mkdir -p $(M)/include_e
346         -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
347
348
349 #--- some other targets for testing purposes
350 test_radix: test_radix.o radix.o
351 test_lookup: ip_fw_lookup.o
352 test_radix test_lookup: CFLAGS=-Wall -Werror -O1