Added spec file comments.
[ipfw.git] / dummynet / Makefile
1 #
2 # $Id$
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
10 # Some variables need to have specific names, because they are used
11 # by the build infrastructure on Linux and OpenWrt. They are:
12
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
22 #
23 # Not sure about this (the name might be reserved)
24 #   ipfw-cflags         our flags for building the module
25 #
26 # Other variables are only private and can be renamed. They include:
27 #
28 #   VER         linux version we are building for (2.4 2.6 or openwrt)
29 #---
30
31 $(warning including dummynet/Makefile)
32
33 # lets default for 2.6 for planetlab builds
34 VER ?= 2.6
35
36 # General values
37 obj-m := ipfw_mod.o
38
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
47
48 $(warning "---- Building dummynet kernel module for Version $(VER)")
49 # We have three sections for OpenWrt, Linux 2.4 and Linux 2.6
50 #
51 ifeq ($(VER),openwrt)
52   M=.
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
56
57   # xcflags-y is a temporary variable where we store build options
58   xcflags-y += -O1 -DLINUX_24
59   xcflags-y += -g
60
61   EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags)
62
63   # we should not export anything
64   #export-objs := ipfw2_mod.o
65 -include $(TOPDIR)/Rules.make
66
67 else    # !openwrt, below we do linux builds for 2.4 and 2.6
68
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.
72
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
77
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)")
85
86   # additional warning
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
89
90   WARN += -Wall -Wundef
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
99
100   ccflags-y += -O1 -DLINUX_24
101   CFLAGS = -DMODULE -D__KERNEL__ -nostdinc \
102         -isystem ${KERNELPATH}/include -isystem $(MYGCC_INCLUDE) ${ccflags-y}
103   # The Main target
104 all: mod24
105
106 else
107 ifeq ($(IPFW_PLANETLAB),1)
108   $(warning "---- Building for PlanetLab")
109   ipfw-cflags += -DIPFW_PLANETLAB        # PlanetLab compilation
110 endif
111   # if not set, use the version from the installed system
112   KERNELPATH ?= /lib/modules/`uname -r`/build
113   # the latest kernel
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
117   # The main target
118
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)
123   endif
124
125 all: include_e
126         $(MAKE) -C $(KERNELPATH) V=1 M=`pwd` modules
127 endif
128
129 #-- back to the common section of code
130
131 # the list of objects used to build the module
132 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
133
134 # Original ipfw and dummynet sources + FreeBSD stuff,
135 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
136
137 # Module glue and functions missing in linux
138 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
139
140 # additional $(CC) flags
141 ccflags-y += $(WARN)
142 ccflags-y += $(ipfw-cflags)
143 ccflags-y += -g
144
145 mod24: include_e $(obj-m)
146
147 $(obj-m): $(ipfw_mod-y)
148         $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
149 clean:
150         -rm -f *.o *.ko Module.symvers *.mod.c
151
152 distclean: clean
153         -rm -f .*cmd modules.order opt_*
154         -rm -rf .tmp_versions include_e
155         -rm -rf .ip_dummynet.o.d
156
157 # support to create empty dirs and files in include_e/
158 # EDIRS is the list of directories, EFILES is the list of files.
159
160 EDIRS= altq arpa machine net netinet netinet6 sys
161
162 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mac.h
163 EFILES += opt_mbuf_stress_test.h opt_param.h
164
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
169
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
175
176 EFILES += netinet6/ip6_var.h
177
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
182
183 M ?= $(shell pwd)
184 include_e:
185         echo "running in $M"
186         -@rm -rf $(M)/include_e opt_*
187         -@mkdir -p $(M)/include_e
188         -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
189
190 endif # !openwrt