439bed9958605c40e1e0e80a0bdb25344cd03618
[ipfw.git] / ipfw / Makefile
1 #
2 # GNUMakefile to build the userland part of ipfw on Linux and Windows
3 #
4 # enable extra debugging information
5 # Do not set with = or := so we can inherit from the caller
6 XOSARCH := $(shell uname)
7 OSARCH ?= $(XOSARCH)
8 $(warning Building userland ipfw for $(VER) $(OSARCH))
9
10 # utility to figure if gcc has a given option
11 #################### extract from Kbuild.include
12 # try-run
13 # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
14 # Exit code chooses option. "$$TMP" is can be used as temporary file and
15 # is automatically cleaned up.
16 try-run = $(shell set -e;               \
17         TMP="$(TMPOUT).$$$$.tmp";       \
18         TMPO="$(TMPOUT).$$$$.o";        \
19         if ($(1)) >/dev/null 2>&1;      \
20         then echo "$(2)";               \
21         else echo "$(3)";               \
22         fi;                             \
23         rm -f "$$TMP" "$$TMPO")
24
25 # cc-option
26 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
27
28 cc-option = $(call try-run,\
29         $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
30 #################### 
31
32 #TCC=c:/tesi/tcc
33
34 # common flags
35 EXTRA_CFLAGS += -O1
36 EXTRA_CFLAGS += -Wall
37 EXTRA_CFLAGS += -include ../glue.h
38 EXTRA_CFLAGS += -I ./include_e -I ./include
39
40 TARGET := ipfw
41 ifneq ($(VER),openwrt)
42 ifeq ($(OSARCH),Linux)
43     EXTRA_CFLAGS += -D__BSD_VISIBLE
44     EXTRA_CFLAGS += -Werror
45     EXTRA_CFLAGS += $(call cc-option, -Wno-unused-but-set-variable)
46 else # must be Cygwin ?
47 ifeq ($(TCC),)
48     EXTRA_CFLAGS += -I/cygdrive/c/WinDDK/7600.16385.0/inc/ddk
49     EXTRA_CFLAGS += -I .
50     EXTRA_CFLAGS += -pipe -Wall
51 else
52     # TCC points to the root of tcc tree
53     CC=$(TCC)/tcc.exe
54     EXTRA_CFLAGS += -DTCC -I..
55     EXTRA_CFLAGS += -I$(TCC)/include/winapi -I$(TCC)/include
56     EXTRA_CFLAGS += -nostdinc
57
58     EDIRS  += arpa net netinet sys
59     EFILES += err.h grp.h netdb.h pwd.h sysexits.h
60     EFILES += arpa/inet.h
61     EFILES += net/if.h
62     EFILES += netinet/in.h netinet/in_systm.h netinet/ip.h
63     EFILES += netinet/ip_icmp.h
64     EFILES += sys/cdefs.h sys/wait.h
65     EFILES += sys/ioctl.h sys/socket.h
66 endif
67     # EXTRA_CFLAGS += -D_WIN32 # see who defines it
68     EXTRA_CFLAGS += -Dsetsockopt=wnd_setsockopt
69     EXTRA_CFLAGS += -Dgetsockopt=wnd_getsockopt
70     EXTRA_CFLAGS += -DEMULATE_SYSCTL
71     EDIRS  += net netinet
72     EFILES += net/ethernet.h net/route.h
73     EFILES += netinet/ether.h netinet/icmp6.h
74     EFILES += sys/sysctl.h
75     TARGET := ipfw.exe
76 endif
77 endif # !openwrt
78
79 CFLAGS += $(EXTRA_CFLAGS)
80 # Location of OS headers and libraries. After our stuff.
81 USRDIR?= /usr
82 ifeq ($(TCC),)
83     CFLAGS += -I$(USRDIR)/include
84     LDFLAGS += -L$(USRDIR)/lib
85 else
86     LDFLAGS += -L. -lws2_32
87 endif
88
89 OBJS = ipfw2.o dummynet.o main.o ipv6.o qsort_r.o
90 OBJS += expand_number.o humanize_number.o glue.o
91
92 # we don't use ALTQ
93 CFLAGS += -DNO_ALTQ
94 #OBJS += altq.o
95
96 all: $(TARGET)
97         echo "Done build for $(OSARCH) VER $(VER)"
98
99 $(TARGET): $(OBJS)
100         $(CC) $(LDFLAGS) -o $@ $^
101
102 $(OBJS) : ipfw2.h ../glue.h include_e
103
104 # support to create empty dirs and files in include_e/
105 # EDIRS is the list of directories, EFILES is the list of files.
106 EDIRS   += sys netinet
107 EFILES  += sys/sockio.h libutil.h
108
109 M ?= $(shell pwd)
110
111 include_e:
112         echo "running in $M"
113         -@rm -rf $(M)/include_e opt_*
114         -@mkdir -p $(M)/include_e
115         -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
116         -@(cd $(M)/include_e/netinet; \
117                 for i in ip_fw.h ip_dummynet.h tcp.h; do \
118                 cp ../../../dummynet2/include/netinet/$$i .; done; )
119
120 clean distclean:
121         -rm -f $(OBJS) $(TARGET)
122         -rm -rf include/netinet/ include_e