play with the makefile to try and support openwrt
authorLuigi Rizzo <rizzo@iet.unipi.it>
Sun, 17 Aug 2014 16:30:21 +0000 (09:30 -0700)
committerLuigi Rizzo <rizzo@iet.unipi.it>
Sun, 17 Aug 2014 16:30:21 +0000 (09:30 -0700)
Makefile.openwrt
kipfw/Makefile

index 3c7be80..16f786f 100644 (file)
@@ -3,7 +3,7 @@
 #
 # Edit IPFW_DIR to point to the directory with the sources for ipfw
 
-IPFW_DIR := $(TOPDIR)/../ipfw3
+IPFW_DIR := $(TOPDIR)/../qemu-misc/ipfw3
 
 include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
@@ -41,7 +41,7 @@ define KernelPackage/ipfw3
  TITLE:= IPFW and dummynet
  # FILES is what makes up the module, both kernel and userland
  # It must be in the KernelPackage section
- FILES := $(PKG_BUILD_DIR)/dummynet2/$(IPFW_MOD) $(PKG_BUILD_DIR)/ipfw/ipfw
+ FILES := $(PKG_BUILD_DIR)/kipfw/$(IPFW_MOD) $(PKG_BUILD_DIR)/ipfw/ipfw
  # AUTOLOAD:=$(call AutoLoad,80,ipfw_mod)
 endef
 
@@ -60,7 +60,7 @@ define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        $(CP) -Rp $(IPFW_DIR)/* $(PKG_BUILD_DIR)/
        (cd $(PKG_BUILD_DIR)/ipfw && $(MAKE) include_e )
-       (cd $(PKG_BUILD_DIR)/dummynet2 && $(MAKE) include_e )
+       (cd $(PKG_BUILD_DIR)/kipfw && $(MAKE) include_e )
 endef
 
 define Build/Compile
@@ -68,13 +68,14 @@ define Build/Compile
        $(MAKE) -C "$(LINUX_DIR)" \
                CROSS_COMPILE="$(TARGET_CROSS)" \
                ARCH="$(LINUX_KARCH)" \
-               $(IPFW_SRC_DIR)="$(PKG_BUILD_DIR)/dummynet2" \
-               VER=$(VERS) modules
+               $(IPFW_SRC_DIR)="$(PKG_BUILD_DIR)/kipfw" \
+               IPFW3_ROOT="$(PKG_BUILD_DIR)" \
+               _VER=$(VERS) modules
        # compile the userland part for openwrt
        $(MAKE) -C $(PKG_BUILD_DIR)/ipfw \
                $(TARGET_CONFIGURE_OPTS) \
                CFLAGS="$(TARGET_CFLAGS) $(CFLAGS_WRT) -I./include_e -I./include -include ../glue.h -DNO_ALTQ -D__BSD_VISIBLE" \
-               VER=$(VERS) all
+               _VER=$(VERS) all
 endef
 
 define Package/ipfw3-userland
index 6ca0562..b80d9ae 100644 (file)
@@ -34,7 +34,8 @@
 # examples found in the $(DDK)/src/network/ndis/passthru/driver/
 # They can be re-created using the 'ndis-glue' target in the 
 
-include $(PWD)/../Makefile.inc
+IPFW3_ROOT ?= $(PWD)/..
+include $(IPFW3_ROOT)/Makefile.inc
 
 TARGET = kipfw
 
@@ -70,6 +71,8 @@ ipfw-cflags += -I $(M)/../sys
 ipfw-cflags += -include $(M)/../glue.h # headers
 ipfw-cflags += -include $(M)/missing.h # headers
 
+$(warning ------ arch $(OSARCH) goals $(MAKECMDGOALS) -----------)
+
 ifeq ($(OSARCH),Windows)       #--- {  Windows block
 ifeq ($(VER),win64)
     $(warning ---- building for 64-bit windows ---)
@@ -186,9 +189,21 @@ $(TARGET): include_e
 
 else # } { linux variables and targets
 
+  # extract version number (hex, aXXYY). Newer linuxes have a different dir
+  # if not set, use the version from the installed system
+  KERNELPATH ?= $(KSRC)
+  LIN_VER := $(shell V=linux/version.h; G=. ; \
+        [ -f $(KERNELPATH)/include/$${V} ] || G=generated/uapi ;\
+        grep LINUX_VERSION_CODE $(KERNELPATH)/include/$${G}/linux/version.h | \
+        awk '{printf "%03x%02x", $$3/256, $$3%256} ')
+
+  #     awk '{printf "%d %03x%02d", $$3, $$3/256, $$3%256} ')
+  # $(warning version $(LINUX_VERSION_CODE))
+  $(warning ------------- linux 2.6 and newer $(LIN_VER) ------------)
 # We have three sections: OpenWrt, Linux 2.4 and Linux 2.6
 
-ifeq ($(VER),openwrt)  #--- { The Makefile section for openwrt ---
+ifeq ($(LIN_VER),openwrt)      #--- { The Makefile section for openwrt ---
+ $(error ------ build on openwrt ---------- )
   # We do not include a dependency on include_e as it is called
   # by Makefile.openwrt in Build/Prepare
   M=.
@@ -207,7 +222,7 @@ ifeq ($(VER),openwrt)       #--- { The Makefile section for openwrt ---
 endif # ---- } end openwrt version
 
 
-ifneq ($(shell echo $(VER)|grep '2.4'),)       #--- {
+ifneq ($(shell echo $(LIN_VER)|grep '2.4'),)   #--- {
   # Makefile section for the linux 2.4 version
   # tested on linux-2.4.35.4, does not work with 2.4.37
   #
@@ -245,6 +260,7 @@ ifneq ($(shell echo $(VER)|grep '2.4'),)    #--- {
 all: mod24
 
 else # --- } {  linux 2.6 and newer
+  $(warning --- build 2.6 and newer target $(TARGET) ----)
 
   # This is the Makefile section for Linux 2.6.x including planetlab
 
@@ -252,8 +268,6 @@ ifeq ($(IPFW_PLANETLAB),1)
   $(warning "---- Building for PlanetLab")
   ipfw-cflags += -DIPFW_PLANETLAB        # PlanetLab compilation
 endif
-  # if not set, use the version from the installed system
-  KERNELPATH ?= $(KSRC)
 #  $(warning "---- Building Version 2.6 $(VER) in $(KERNELPATH)")
   WARN := -O1 -Wall -Werror -DDEBUG_SPINLOCK -DDEBUG_MUTEXES
   # The main target
@@ -261,33 +275,40 @@ endif
   # Required by GCC 4.6
   ccflags-y += -Wno-unused-but-set-variable
 
-  # extract version number (decimal). Newer linuxes have a different dir
-  LINUX_VERSION_CODE := $(shell V=linux/version.h; G=. ; \
-        [ -f $(KERNELPATH)/include/$${V} ] || G=generated/uapi ;\
-        grep LINUX_VERSION_CODE $(KERNELPATH)/include/$${G}/linux/version.h | \
-        awk '{printf "%d", $$3} ')
-
-  #     awk '{printf "%d %03x%02d", $$3, $$3/256, $$3%256} ')
-  # $(warning version $(LINUX_VERSION_CODE))
 
-  ifeq ($(shell if [ -z $(LINUX_VERSION_CODE) ] ; then echo "true"; fi),true)
+  ifeq ($(shell if [ -z $(LIN_VER) ] ; then echo "true"; fi),true)
     $(warning "---- Perhaps you miss a (cd $(KERNELPATH); make oldconfig; make prepare; make scripts)");
   endif
 
-  # Required by kernel <= 2.6.22, ccflags-y is used on newer version
-  ifeq ($(shell if [ "$(LINUX_VERSION_CODE)" -le 132630 ] ; then echo "true"; fi),true)
+  # Required by kernel < 2.6.23, ccflags-y is used on newer version
+  ifeq ($(shell if [ "$(LIN_VER)" \< "20617" ] ; then echo "true"; fi),true)
     EXTRA_CFLAGS += $(ccflags-y)
   endif
 
-  $(warning $(shell [ "$(LINUX_VERSION_CODE)" -le 132635 ] && \
+  $(warning $(shell [ "$(LIN_VER)" \< "2061c" ] && \
        [ `$(MAKE) -version | head -1 | cut -d " " -f 3` != '3.81' ] && \
        echo "****   need make 3.81 *****") )
   # $(warning make is $(MAKE) version is $(shell $(MAKE) -version | head -1) )
 
+  #--- openwrt ?
+  ifeq ($(_VER),openwrt)
+    M=.
+    obj-y := $(IPFW_SRCS:%.c=%.o)
+    O_TARGET := $(obj-m)
+
+    # xcflags-y is a temporary variable where we store build options
+    xcflags-y += -O1
+    xcflags-y += -g
+
+    EXTRA_CFLAGS := $(xcflags-y) $(ipfw-cflags) -DSYSCTL_NODE -DEMULATE_SYSCTL
+  endif #---- end openwrt
+
 all: $(TARGET)
 $(TARGET):     include_e
+       echo "xxxxxxxxxxxxx $(MAKE) -C $(KERNELPATH) V=$(V) M=`pwd` modules"
        $(MAKE) -C $(KERNELPATH) V=$(V) M=`pwd` modules
 
+
 endif # } --- linux 2.6 and newer
 
 #-- back to the common section for linux