From 09ea27343a1168b977f728f056d345712cba0ffc Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@iet.unipi.it>
Date: Mon, 6 Oct 2014 11:12:32 -0700
Subject: [PATCH] rearrange openwrt Makefile

---
 Makefile.openwrt | 68 +++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/Makefile.openwrt b/Makefile.openwrt
index a1d62e5..0ad86a4 100644
--- a/Makefile.openwrt
+++ b/Makefile.openwrt
@@ -8,10 +8,10 @@ IPFW_DIR := $(TOPDIR)/../qemu-misc/ipfw3
 include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
-PKG_NAME:=kmod-ipfw3
+PKG_NAME:=ipfw3
 PKG_RELEASE:=1
 
-# MV is undefined
+# MV is undefined, we use it in the internal Makefiles
 MV ?= mv
 
 include $(INCLUDE_DIR)/package.mk
@@ -30,21 +30,41 @@ else
     IPFW_SRC_DIR:=M
 endif
 
+define Package/ipfw3
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE := /sbin/ipfw
+  DEPENDS := +libc +libgcc
+  FILES := $(PKG_BUILD_DIR)/ipfw/ipfw
+  $(warning --- build dir is $(PKG_BUILD_DIR) ---)
+endef
+
+define Package/ipfw3/description
+  Control program for ipfw and dummynet
+endef
+
+# XXX not entirely clear why the install entry for userland works,
+# given that /sbin/ipfw is in KernelPackage/ipfw3
+
+define Package/ipfw3/install
+	$(INSTALL_DIR) $(1) /sbin
+endef
+
 # Description for the package.
 # The names KernelPackage/ipfw3 must match the arguments to the
 # call $(eval $(call KernelPackage,ipfw3)) used to build it
 
 define KernelPackage/ipfw3
- SUBMENU:=Other modules
- 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)/kipfw-mod/$(IPFW_MOD) $(PKG_BUILD_DIR)/ipfw/ipfw
- # AUTOLOAD:=$(call AutoLoad,80,ipfw_mod)
+  SUBMENU:=Other modules
+  TITLE:= IPFW and dummynet
+  # FILES is what makes up the module, both kernel and userland
+  # It must be in the KernelPackage section XXX
+  FILES := $(PKG_BUILD_DIR)/kipfw-mod/$(IPFW_MOD)
+  # AUTOLOAD:=$(call AutoLoad,80,ipfw_mod)
 endef
 
-define KernelPackage/ipfw3/description
- This package contains the ipfw and dummynet module
+define KernelPackage/kmod-ipfw3/description
+  ipfw and dummynet kernel module
 endef
 
 # Standard entries for the openwrt builds: Build/Prepare and Build/Compile
@@ -54,7 +74,7 @@ endef
 # We copy the entire subtree, then build include_e/ which
 # contains empty headers used by the kernel sources.
 define Build/Prepare
-  # $(warning Preparing ipfw sources)
+  # $(warning --- Preparing ipfw sources ---)
 	mkdir -p $(PKG_BUILD_DIR)
 	$(CP) -Rp $(IPFW_DIR)/* $(PKG_BUILD_DIR)/
 	# The kernel sources are spread in multiple places,
@@ -69,13 +89,13 @@ endef
 
 define Build/Compile
 	# XXX check whether we need all linux_dir etc.
+	$(warning --- compile the user part for ipfw/openwrt ---)
 	$(MAKE) -C $(PKG_BUILD_DIR)/ipfw \
 		LINUX_DIR=$(LINUX_DIR) \
 		$(TARGET_CONFIGURE_OPTS) \
 		CFLAGS="$(TARGET_CFLAGS) $(CFLAGS_WRT) -I./include_e -I./include -include ../glue.h -DNO_ALTQ -D__BSD_VISIBLE" \
 		_VER=$(VERS) all
-	$(warning  compile the kernel part for ipfw/openwrt)
-	# compile the kernel part for openwrt
+	$(warning --- compile the kernel part for ipfw/openwrt ---)
 	$(MAKE) -C "$(LINUX_DIR)" \
 		CROSS_COMPILE="$(TARGET_CROSS)" \
 		LINUX_DIR=$(LINUX_DIR) \
@@ -84,27 +104,9 @@ define Build/Compile
 		$(IPFW_SRC_DIR)="$(PKG_BUILD_DIR)/kipfw-mod" \
 		IPFW3_ROOT="$(PKG_BUILD_DIR)" \
 		_VER=$(VERS) modules
+	$(warning +++ done compile the kernel part for ipfw/openwrt ---)
 endef
 
-define Build/Compile_new
-	$(call Build/Compile/Default)
-	$(call Build/Compile/Default,modules)
-endef
-
-define Package/ipfw3-userland
-  SECTION:=utils
-  CATEGORY:=Utilities
-  TITLE := /sbin/ipfw
-  DESCRIPTION := This is the control program for ipfw and dummynet
-  DEPENDS := +libc +libgcc
-endef
-
-define Package/ipfw3-userland/install
-	$(INSTALL_DIR) $(1) /sbin
-endef
-
-# XXX not entirely clear why the install entry for userland works,
-# given that /sbin/ipfw is in KernelPackage/ipfw3
 
-$(eval $(call Package,ipfw3-userland))
+$(eval $(call BuildPackage,ipfw3))
 $(eval $(call KernelPackage,ipfw3))
-- 
2.47.0