This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / ipfw / Makefile
index 7b4a272..4800b4a 100644 (file)
 #
-# $Id$
+# $Id: Makefile 11277 2012-06-10 17:44:15Z marta $
 #
-# GNUMakefile to build the userland part of ipfw on Linux
+# GNUMakefile to build the userland part of ipfw on Linux and Windows
 #
 # enable extra debugging information
 # Do not set with = or := so we can inherit from the caller
-$(warning Building userland ipfw for $(VER))
+XOSARCH := $(shell uname)
+OSARCH ?= $(XOSARCH)
+OSARCH := $(shell uname)
+OSARCH := $(findstring $(OSARCH),FreeBSD Linux Darwin)
+ifeq ($(OSARCH),)
+    OSARCH := Windows
+endif
+
+$(warning Building userland ipfw for $(VER) $(OSARCH))
+
+#TCC=c:/tesi/tcc
+
+# common flags
 EXTRA_CFLAGS += -O1
-EXTRA_CFLAGS += -Wall -Werror
+EXTRA_CFLAGS += -Wall
 EXTRA_CFLAGS += -include ../glue.h
 EXTRA_CFLAGS += -I ./include_e -I ./include
 
+TARGET := ipfw
 ifneq ($(VER),openwrt)
-OSARCH := $(shell uname)
 ifeq ($(OSARCH),Linux)
     EXTRA_CFLAGS += -D__BSD_VISIBLE
+    EXTRA_CFLAGS += -Werror
+    # Required by GCC 4.6
+    EXTRA_CFLAGS += -Wno-unused-but-set-variable
+endif
+ifeq ($(OSARCH),FreeBSD)
+    EXTRA_CFLAGS += -D__BSD_VISIBLE
+    EXTRA_CFLAGS += -Werror
+endif
+ifeq ($(OSARCH),Darwin)
+    EXTRA_CFLAGS += -D__BSD_VISIBLE
+    EXTRA_CFLAGS += -Werror
+endif
+# must be Cygwin ?
+ifeq ($(OSARCH),Windows)
+ifeq ($(TCC),)
+    EXTRA_CFLAGS += -I/cygdrive/c/WinDDK/7600.16385.0/inc/ddk
+    EXTRA_CFLAGS += -I .
+    EXTRA_CFLAGS += -pipe -Wall
 else
-    HAVE_NAT := $(shell grep O_NAT /usr/include/netinet/ip_fw.h)
-    # EXTRA_CFLAGS += ...
+    # TCC points to the root of tcc tree
+    CC=$(TCC)/tcc.exe
+    EXTRA_CFLAGS += -DTCC -I..
+    EXTRA_CFLAGS += -I$(TCC)/include/winapi -I$(TCC)/include
+    EXTRA_CFLAGS += -nostdinc
+
+    EDIRS  += arpa net netinet sys
+    EFILES += err.h grp.h netdb.h pwd.h sysexits.h
+    EFILES += arpa/inet.h
+    EFILES += net/if.h
+    EFILES += netinet/in.h netinet/in_systm.h netinet/ip.h
+    EFILES += netinet/ip_icmp.h
+    EFILES += sys/cdefs.h sys/wait.h
+    EFILES += sys/ioctl.h sys/socket.h
+
+endif
+    # EXTRA_CFLAGS += -D_WIN32 # see who defines it
+    EXTRA_CFLAGS += -Dsetsockopt=wnd_setsockopt
+    EXTRA_CFLAGS += -Dgetsockopt=wnd_getsockopt
+    EXTRA_CFLAGS += -DEMULATE_SYSCTL
+    EDIRS  += net netinet
+    EFILES += net/ethernet.h net/route.h
+    EFILES += netinet/ether.h netinet/icmp6.h
+    EFILES += sys/sysctl.h
+    TARGET := ipfw.exe
 endif
 endif # !openwrt
 
 CFLAGS += $(EXTRA_CFLAGS)
 # Location of OS headers and libraries. After our stuff.
 USRDIR?= /usr
-CFLAGS += -I$(USRDIR)/include
-LDFLAGS += -L$(USRDIR)/lib
-
-OBJS = ipfw2.o dummynet.o main.o ipv6.o altq.o qsort_r.o
-OBJS += expand_number.o humanize_number.o
-ifneq ($(HAVE_NAT),)
-    OBJS += nat.o
-    EXTRA_CFLAGS += -DHAVE_NAT
+ifeq ($(TCC),)
+    CFLAGS += -I$(USRDIR)/include
+    LDFLAGS += -L$(USRDIR)/lib
+else
+    LDFLAGS += -L. -L$(TCC)/lib -lws2_32
 endif
-OBJS += glue.o
 
-all: ipfw
-       echo "VER is $(VER)"
+OBJS = ipfw2.o dummynet.o main.o ipv6.o qsort_r.o
+OBJS += expand_number.o humanize_number.o glue.o
+
+# we don't use ALTQ
+CFLAGS += -DNO_ALTQ
+#OBJS += altq.o
 
-ipfw: $(OBJS)
+all: $(TARGET)
+       echo "Done build for $(OSARCH) VER $(VER)"
+
+$(TARGET): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $^
 
-$(OBJS) : ipfw2.h ../glue.h include/netinet include_e
+$(OBJS) : ipfw2.h ../glue.h include_e
 
 # support to create empty dirs and files in include_e/
 # EDIRS is the list of directories, EFILES is the list of files.
-EDIRS   = sys
+EDIRS   += sys netinet
+EFILES  += sys/sockio.h libutil.h
 
-EFILES  = sys/sockio.h libutil.h
 M ?= $(shell pwd)
 
 include_e:
@@ -56,14 +111,10 @@ include_e:
        -@rm -rf $(M)/include_e opt_*
        -@mkdir -p $(M)/include_e
        -@(cd $(M)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
-
-include/netinet:
-       -@rm -rf include/netinet
-       -@mkdir -p include/netinet
-       -(cd include/netinet; \
+       -@(cd $(M)/include_e/netinet; \
                for i in ip_fw.h ip_dummynet.h tcp.h; do \
-               ln -s ../../../dummynet/include/netinet/$$i; done; )
+               cp ../../../dummynet2/include/netinet/$$i .; done; )
 
 clean distclean:
-       -rm -f $(OBJS) ipfw
-       -rm -rf include/netinet/
+       -rm -f $(OBJS) $(TARGET)
+       -rm -rf include/netinet/ include_e