2 # GNUMakefile to build the userland part of ipfw on Linux and Windows
4 # enable extra debugging information
5 # Do not set with = or := so we can inherit from the caller
6 XOSARCH := $(shell uname)
8 $(warning Building userland ipfw for $(VER) $(OSARCH))
10 # utility to figure if gcc has a given option
11 #################### extract from Kbuild.include
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; \
23 rm -f "$$TMP" "$$TMPO")
26 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
28 cc-option = $(call try-run,\
29 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2))
37 EXTRA_CFLAGS += -include ../glue.h
38 EXTRA_CFLAGS += -I ./include_e -I ./include
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 ?
48 EXTRA_CFLAGS += -I/cygdrive/c/WinDDK/7600.16385.0/inc/ddk
50 EXTRA_CFLAGS += -pipe -Wall
52 # TCC points to the root of tcc tree
54 EXTRA_CFLAGS += -DTCC -I..
55 EXTRA_CFLAGS += -I$(TCC)/include/winapi -I$(TCC)/include
56 EXTRA_CFLAGS += -nostdinc
58 EDIRS += arpa net netinet sys
59 EFILES += err.h grp.h netdb.h pwd.h sysexits.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
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
72 EFILES += net/ethernet.h net/route.h
73 EFILES += netinet/ether.h netinet/icmp6.h
74 EFILES += sys/sysctl.h
79 CFLAGS += $(EXTRA_CFLAGS)
80 # Location of OS headers and libraries. After our stuff.
83 CFLAGS += -I$(USRDIR)/include
84 LDFLAGS += -L$(USRDIR)/lib
86 LDFLAGS += -L. -lws2_32
89 OBJS = ipfw2.o dummynet.o main.o ipv6.o qsort_r.o
90 OBJS += expand_number.o humanize_number.o glue.o
97 echo "Done build for $(OSARCH) VER $(VER)"
100 $(CC) $(LDFLAGS) -o $@ $^
102 $(OBJS) : ipfw2.h ../glue.h include_e
104 # support to create empty dirs and files in include_e/
105 # EDIRS is the list of directories, EFILES is the list of files.
107 EFILES += sys/sockio.h libutil.h
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; )
121 -rm -f $(OBJS) $(TARGET)
122 -rm -rf include/netinet/ include_e