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