make string_to_number() static
[jleu-ebtables.git] / Makefile
blob96568842a1d71cb5ee3946c661c4d09b45cbef55
1 # ebtables Makefile
3 PROGNAME:=ebtables
4 PROGRELEASE:=1
5 PROGVERSION_:=2.0.8
6 PROGVERSION:=$(PROGVERSION_)-$(PROGRELEASE)
7 PROGDATE:=May\ 2007
9 # default paths
10 LIBDIR:=/usr/lib
11 MANDIR:=/usr/local/man
12 BINDIR:=/usr/local/sbin
13 ETCDIR:=/etc
14 INITDIR:=/etc/rc.d/init.d
15 SYSCONFIGDIR:=/etc/sysconfig
16 DESTDIR:=
18 CFLAGS:=-Wall -Wunused
19 CFLAGS_SH_LIB:=-fPIC
20 CC:=gcc
21 LD:=ld
23 ifeq ($(shell uname -m),sparc64)
24 CFLAGS+=-DEBT_MIN_ALIGN=8 -DKERNEL_64_USERSPACE_32
25 endif
27 include extensions/Makefile
29 OBJECTS2:=getethertype.o communication.o libebtc.o \
30 useful_functions.o ebtables.o
32 OBJECTS:=$(OBJECTS2) $(EXT_OBJS) $(EXT_LIBS)
34 KERNEL_INCLUDES?=include/
36 ETHERTYPESPATH?=$(ETCDIR)
37 ETHERTYPESFILE:=$(ETHERTYPESPATH)/ethertypes
39 PIPE_DIR?=/tmp/$(PROGNAME)-v$(PROGVERSION)
40 PIPE=$(PIPE_DIR)/ebtablesd_pipe
41 EBTD_CMDLINE_MAXLN?=2048
42 EBTD_ARGC_MAX?=50
44 PROGSPECS:=-DPROGVERSION=\"$(PROGVERSION)\" \
45 -DPROGNAME=\"$(PROGNAME)\" \
46 -DPROGDATE=\"$(PROGDATE)\" \
47 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
48 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
49 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN)
51 # You can probably ignore this, ebtables{u,d} are normally not used
52 PROGSPECSD:=-DPROGVERSION=\"$(PROGVERSION)\" \
53 -DPROGNAME=\"$(PROGNAME)\" \
54 -DPROGDATE=\"$(PROGDATE)\" \
55 -D_PATH_ETHERTYPES=\"$(ETHERTYPESFILE)\" \
56 -DEBTD_CMDLINE_MAXLN=$(EBTD_CMDLINE_MAXLN) \
57 -DEBTD_ARGC_MAX=$(EBTD_ARGC_MAX) \
58 -DEBTD_PIPE=\"$(PIPE)\" \
59 -DEBTD_PIPE_DIR=\"$(PIPE_DIR)\"
61 # Uncomment for debugging (slower)
62 #PROGSPECS+=-DEBT_DEBUG
63 #PROGSPECSD+=-DEBT_DEBUG
64 #CFLAGS+=-ggdb
66 all: ebtables ebtables-restore
68 communication.o: communication.c include/ebtables_u.h
69 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
71 libebtc.o: libebtc.c include/ebtables_u.h
72 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
74 useful_functions.o: useful_functions.c include/ebtables_u.h
75 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
77 getethertype.o: getethertype.c include/ethernetdb.h
78 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -Iinclude/
80 ebtables.o: ebtables.c include/ebtables_u.h
81 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c -o $@ $< -I$(KERNEL_INCLUDES)
83 ebtables-standalone.o: ebtables-standalone.c include/ebtables_u.h
84 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
86 .PHONY: libebtc
87 libebtc: $(OBJECTS2)
88 $(LD) -shared -soname libebtc.so -o libebtc.so -lc $(OBJECTS2)
90 ebtables: $(OBJECTS) ebtables-standalone.o libebtc
91 $(CC) $(CFLAGS) $(CFLAGS_SH_LIB) -o $@ ebtables-standalone.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
92 -Wl,-rpath,$(LIBDIR)
94 ebtablesu: ebtablesu.c
95 $(CC) $(CFLAGS) $(PROGSPECSD) $< -o $@
97 ebtablesd.o: ebtablesd.c include/ebtables_u.h
98 $(CC) $(CFLAGS) $(PROGSPECSD) -c $< -o $@ -I$(KERNEL_INCLUDES)
100 ebtablesd: $(OBJECTS) ebtablesd.o libebtc
101 $(CC) $(CFLAGS) -o $@ ebtablesd.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
102 -Wl,-rpath,$(LIBDIR)
104 ebtables-restore.o: ebtables-restore.c include/ebtables_u.h
105 $(CC) $(CFLAGS) $(PROGSPECS) -c $< -o $@ -I$(KERNEL_INCLUDES)
107 ebtables-restore: $(OBJECTS) ebtables-restore.o libebtc
108 $(CC) $(CFLAGS) -o $@ ebtables-restore.o -I$(KERNEL_INCLUDES) -L. -Lextensions -lebtc $(EXT_LIBSI) \
109 -Wl,-rpath,$(LIBDIR)
111 .PHONY: daemon
112 daemon: ebtablesd ebtablesu
114 # a little scripting for a static binary, making one for ebtables-restore
115 # should be completely analogous
116 static: extensions/ebt_*.c extensions/ebtable_*.c ebtables.c communication.c ebtables-standalone.c getethertype.c libebtc.c useful_functions.c
117 cp ebtables-standalone.c ebtables-standalone.c_ ; \
118 cp include/ebtables_u.h include/ebtables_u.h_ ; \
119 sed "s/ main(/ pseudomain(/" ebtables-standalone.c > ebtables-standalone.c__ ; \
120 mv ebtables-standalone.c__ ebtables-standalone.c ; \
121 printf "\nint main(int argc, char *argv[])\n{\n " >> ebtables-standalone.c ; \
122 for arg in $(EXT_FUNC) \
123 ; do \
124 sed s/_init/_$${arg}_init/ extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
125 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
126 printf "\t%s();\n" _$${arg}_init >> ebtables-standalone.c ; \
127 printf "extern void %s();\n" _$${arg}_init >> include/ebtables_u.h ; \
128 done ; \
129 for arg in $(EXT_TABLES) \
130 ; do \
131 sed s/_init/_t_$${arg}_init/ extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
132 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
133 printf "\t%s();\n" _t_$${arg}_init >> ebtables-standalone.c ; \
134 printf "extern void %s();\n" _t_$${arg}_init >> include/ebtables_u.h ; \
135 done ; \
136 printf "\n\tpseudomain(argc, argv);\n\treturn 0;\n}\n" >> ebtables-standalone.c ;\
137 $(CC) $(CFLAGS) $(PROGSPECS) -o $@ $^ -I$(KERNEL_INCLUDES) -Iinclude ; \
138 for arg in $(EXT_FUNC) \
139 ; do \
140 sed "s/ .*_init/ _init/" extensions/ebt_$${arg}.c > extensions/ebt_$${arg}.c_ ; \
141 mv extensions/ebt_$${arg}.c_ extensions/ebt_$${arg}.c ; \
142 done ; \
143 for arg in $(EXT_TABLES) \
144 ; do \
145 sed "s/ .*_init/ _init/" extensions/ebtable_$${arg}.c > extensions/ebtable_$${arg}.c_ ; \
146 mv extensions/ebtable_$${arg}.c_ extensions/ebtable_$${arg}.c ; \
147 done ; \
148 mv ebtables-standalone.c_ ebtables-standalone.c ; \
149 mv include/ebtables_u.h_ include/ebtables_u.h
151 tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g')
152 tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g')
153 tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g')
154 .PHONY: scripts
155 scripts: ebtables-save ebtables.sysv ebtables-config
156 cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_
157 install -m 0755 -o root -g root ebtables-save_ $(DESTDIR)$(BINDIR)/ebtables-save
158 cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_
159 install -m 0755 -o root -g root ebtables.sysv_ $(DESTDIR)$(INITDIR)/ebtables
160 cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables-config_
161 install -m 0600 -o root -g root ebtables-config_ $(DESTDIR)$(SYSCONFIGDIR)/ebtables-config
162 rm -f ebtables-save_ ebtables.sysv_ ebtables-config_
164 $(MANDIR)/man8/ebtables.8: ebtables.8
165 mkdir -p $(DESTDIR)$(@D)
166 sed 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8 | sed 's/$$(DATE)/$(PROGDATE)/' > ebtables.8_
167 install -m 0644 -o root -g root ebtables.8_ $(DESTDIR)$@
168 rm -f ebtables.8_
170 $(ETHERTYPESFILE): ethertypes
171 mkdir -p $(DESTDIR)$(@D)
172 install -m 0644 -o root -g root $< $(DESTDIR)$@
174 .PHONY: exec
175 exec: ebtables ebtables-restore
176 mkdir -p $(DESTDIR)$(BINDIR)
177 install -m 0755 -o root -g root $(PROGNAME) $(DESTDIR)$(BINDIR)/$(PROGNAME)
178 install -m 0755 -o root -g root ebtables-restore $(DESTDIR)$(BINDIR)/ebtables-restore
180 .PHONY: install
181 install: $(MANDIR)/man8/ebtables.8 $(ETHERTYPESFILE) exec scripts
182 mkdir -p $(DESTDIR)$(LIBDIR)
183 install -m 0755 extensions/*.so $(DESTDIR)$(LIBDIR)
184 install -m 0755 *.so $(DESTDIR)$(LIBDIR)
186 .PHONY: clean
187 clean:
188 rm -f ebtables ebtables-restore ebtablesd ebtablesu static
189 rm -f *.o *~ *.so
190 rm -f extensions/*.o extensions/*.c~ extensions/*.so include/*~
192 DIR:=$(PROGNAME)-v$(PROGVERSION)
193 CVSDIRS:=CVS extensions/CVS examples/CVS examples/perf_test/CVS \
194 examples/ulog/CVS include/CVS
195 # This is used to make a new userspace release, some files are altered so
196 # do this on a temporary version
197 .PHONY: release
198 release:
199 rm -f extensions/ebt_inat.c
200 rm -rf $(CVSDIRS)
201 mkdir -p include/linux/netfilter_bridge
202 install -m 0644 -o root -g root \
203 $(KERNEL_INCLUDES)/linux/netfilter_bridge.h include/linux/
204 # To keep possible compile error complaints about undefined ETH_P_8021Q
205 # off my back
206 install -m 0644 -o root -g root \
207 $(KERNEL_INCLUDES)/linux/if_ether.h include/linux/
208 install -m 0644 -o root -g root \
209 $(KERNEL_INCLUDES)/linux/types.h include/linux/
210 install -m 0644 -o root -g root \
211 $(KERNEL_INCLUDES)/linux/netfilter_bridge/*.h \
212 include/linux/netfilter_bridge/
213 install -m 0644 -o root -g root \
214 include/ebtables.h include/linux/netfilter_bridge/
215 make clean
216 touch *
217 touch extensions/*
218 touch include/*
219 touch include/linux/*
220 touch include/linux/netfilter_bridge/*
221 sed -i 's/$$(VERSION)/$(PROGVERSION)/' ebtables.8
222 sed -i 's/$$(DATE)/$(PROGDATE)/' ebtables.8
223 sed -i 's/$$(VERSION)/$(PROGVERSION_)/' ebtables.spec
224 sed -i 's/$$(RELEASE)/$(PROGRELEASE)/' ebtables.spec
225 cd ..;tar -c $(DIR) | gzip >$(DIR).tar.gz; cd -
226 rm -rf include/linux
228 # This will make the rpm and put it in /usr/src/redhat/RPMS
229 # (do this as root after make release)
230 .PHONY: rpmbuild
231 rpmbuild:
232 cp ../$(DIR).tar.gz /usr/src/redhat/SOURCES/
233 rpmbuild --buildroot $(shell mktemp -td $(DIR)-XXXXX) -bb ebtables.spec
235 .PHONY: test_ulog
236 test_ulog: examples/ulog/test_ulog.c getethertype.o
237 $(CC) $(CFLAGS) $< -o test_ulog -I$(KERNEL_INCLUDES) -lc \
238 getethertype.o
239 mv test_ulog examples/ulog/
241 .PHONY: examples
242 examples: test_ulog