4 # gnu Makefile to build linux module for ipfw+dummynet
6 # Unless specified otherwise, variable names are arbitrary.
7 # Exceptions are the following:
9 # ccflags-y additional $(CC) flags
10 # M used by Kbuild, we must set it to `pwd`
11 # obj-m list of .o modules to build
12 # $(MOD)-y for each $MOD in obj-m, the list of objects
13 # obj-y same as above, for openwrt
14 # O_TARGET the link target, for openwrt
15 # EXTRA_CFLAGS as the name says... in openwrt
16 # EXTRA_CFLAGS is used in 2.6.22 module kernel compilation too
19 $(warning including dummynet/Makefile)
21 # lets default for 2.6 for planetlab builds
26 $(warning dummynet/Makefile doing openwrt)
28 obj-y := ipfw2_mod.o bsd_compat.o \
29 in_cksum.o ip_dummynet.o ip_fw2.o ip_fw_pfil.o
30 O_TARGET := ipfw_mod.o
32 xcflags-y += -O1 -DLINUX_24
33 xcflags-y += -DIPFIREWALL_DEFAULT_TO_ACCEPT
35 xcflags-y += -D_BSD_SOURCE # enable __FAVOR_BSD (udp/tcp bsd struct over posix)
36 xcflags-y += -DKERNEL_MODULE # linux kernel module
37 xcflags-y += -I include_e -I include
38 xcflags-y += -include ../glue.h # headers
40 EXTRA_CFLAGS := $(xcflags-y)
42 # we should not export anything
43 #export-objs := ipfw2_mod.o
44 -include $(TOPDIR)/Rules.make
49 ifneq ($(shell echo $(VER)|grep '2.4'),)
50 $(warning "---- Building for Version $(VER)")
51 KERNELDIR := -isystem /usr/src/linux-2.4.35.4/include
52 # replace the system include directory
53 WARN += -nostdinc -isystem /usr/lib/gcc/i486-linux-gnu/4.2.4/include
54 #WARN = -Wp,-MD,/home/luigi/ports-luigi/dummynet-branches/ipfw_mod/dummynet/.ipfw2_mod.o.d
55 #WARN += -Iinclude -include include/linux/autoconf.h
58 WARN += -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
59 WARN += -fno-common -Werror-implicit-function-declaration
60 # WARN += -O2 -fno-stack-protector -m32 -msoft-float -mregparm=3
61 # -mregparm=3 gives a printk error
62 WARN += -m32 -msoft-float # -mregparm=3
63 #WARN += -freg-struct-return -mpreferred-stack-boundary=2
64 WARN += -Wno-sign-compare
65 WARN += -Wdeclaration-after-statement -Wno-pointer-sign
67 ccflags-y += -O1 -DLINUX_24
68 CFLAGS = -DMODULE -D__KERNEL__ ${KERNELDIR} ${ccflags-y}
73 # KERNELDIR is where the kernel headers reside
74 # XXX on Planetlab, KERNELDIR must be same as KERNELPATH
75 KERNELDIR ?= $(KERNELPATH)
76 # KERNELDIR := /home/luigi/linux-2.6.25.17/
78 #KERNELDIR := /usr/src/linux-2.6.24 # not with v.2237
79 #KERNELDIR := /usr/src/linux-2.6.26
80 #KERNELDIR := /usr/src/linux-2.6.22
81 #KERNELDIR := /usr/src/linux-source-2.6.26
82 #KERNELDIR := /lib/modules/`uname -r`/build
83 $(warning "---- Building Version 2.6 $(VER) in $(KERNELDIR)")
84 WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
87 # Required by kernel <= 2.6.22, ccflags-y is used on newer version
88 LINUX_VERSION_CODE := $(shell grep LINUX_VERSION_CODE $(KERNELDIR)/include/linux/version.h|cut -d " " -f3)
89 ifeq ($(LINUX_VERSION_CODE),132630)
90 EXTRA_CFLAGS += $(ccflags-y)
94 $(MAKE) -C $(KERNELDIR) V=1 M=`pwd` modules
97 #-- back to the common section of code
99 # the list of objects used to build the module
100 ipfw_mod-y = $(IPFW_SRCS:%.c=%.o)
102 # Original ipfw and dummynet sources + FreeBSD stuff,
103 IPFW_SRCS = ip_fw2.c ip_dummynet.c ip_fw_pfil.c in_cksum.c
105 # Module glue and functions missing in linux
106 IPFW_SRCS += ipfw2_mod.c bsd_compat.c
109 # additional $(CC) flags
111 ccflags-y += -DIPFIREWALL_DEFAULT_TO_ACCEPT
113 ccflags-y += -D_BSD_SOURCE # enable __FAVOR_BSD (udp/tcp bsd structure over posix)
114 ccflags-y += -DKERNEL_MODULE # linux kernel module
115 ccflags-y += -I $(M)/include_e -I $(M)/include
116 ccflags-y += -include $(M)/../glue.h # headers
118 mod24: include_e $(obj-m)
120 $(obj-m): $(ipfw_mod-y)
121 $(LD) $(LDFLAGS) -m elf_i386 -r -o $@ $^
123 -rm -f *.o *.ko Module.symvers *.mod.c
126 -rm -f .*cmd modules.order opt_*
127 -rm -rf .tmp_versions include_e
128 -rm -rf .ip_dummynet.o.d
130 # support to create empty dirs and files in include_e/
131 # EDIRS is the list of directories, EFILES is the list of files.
133 EDIRS= altq arpa machine net netinet netinet6 sys
135 EFILES += opt_inet6.h opt_ipfw.h opt_ipsec.h opt_mac.h
136 EFILES += opt_mbuf_stress_test.h opt_param.h
138 EFILES += altq/if_altq.h
139 EFILES += arpa/inet.h
140 EFILES += machine/in_cksum.h
141 EFILES += net/ethernet.h net/netisr.h net/pf_mtag.h net/radix.h
143 EFILES += netinet/ether.h netinet/icmp6.h netinet/if_ether.h
144 EFILES += netinet/in.h netinet/in_pcb.h netinet/in_var.h
145 EFILES += netinet/ip_carp.h netinet/ip_var.h netinet/pim.h
146 EFILES += netinet/sctp.h netinet/tcp_timer.h netinet/tcpip.h
147 EFILES += netinet/udp_var.h
149 EFILES += netinet6/ip6_var.h
151 EFILES += sys/_lock.h sys/_mutex.h sys/jail.h
152 EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
153 EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
154 EFILES += sys/sysctl.h sys/time.h sys/ucred.h
159 -@rm -rf $(M)/include_e opt_*
160 -@mkdir -p $(M)/include_e
161 -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )