From a1a8e1a56bb17ada1cc7f14412d6063240653eb3 Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@iet.unipi.it>
Date: Sun, 17 Aug 2014 14:46:56 -0700
Subject: [PATCH] userspace builds correctly

---
 Makefile.openwrt | 11 ++++++++---
 ipfw/Makefile    |  4 ++--
 kipfw/Makefile   |  3 ++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Makefile.openwrt b/Makefile.openwrt
index a916598..8c54bd7 100644
--- a/Makefile.openwrt
+++ b/Makefile.openwrt
@@ -17,7 +17,7 @@ MV ?= mv
 include $(INCLUDE_DIR)/package.mk
 
 #Stuff depending on kernel version
-$(warning -------- -kernel version $(KERNEL) -------)
+$(warning --- openwrt kernel version $(KERNEL) linux dir $(LINUX_DIR) -------)
 
 
 ifeq ($(KERNEL),2.4)
@@ -58,19 +58,24 @@ define Build/Prepare
   # $(warning Preparing ipfw sources)
 	mkdir -p $(PKG_BUILD_DIR)
 	$(CP) -Rp $(IPFW_DIR)/* $(PKG_BUILD_DIR)/
+	# we do not need cross parameters
 	(cd $(PKG_BUILD_DIR)/ipfw && $(MAKE) include_e )
 	(cd $(PKG_BUILD_DIR)/kipfw && $(MAKE) include_e )
 endef
 
 define Build/Compile
-	# compile the userland part for openwrt
+	$(warning  compile the userland 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
+		_VER=$(VERS) all
+	$(warning  compile the kernel part for ipfw/openwrt)
 	# compile the kernel part for openwrt
 	$(MAKE) -C "$(LINUX_DIR)" \
 		CROSS_COMPILE="$(TARGET_CROSS)" \
+		LINUX_DIR=$(LINUX_DIR) \
+		KERNELPATH=$(LINUX_DIR) \
 		ARCH="$(LINUX_KARCH)" \
 		$(IPFW_SRC_DIR)="$(PKG_BUILD_DIR)/kipfw" \
 		IPFW3_ROOT="$(PKG_BUILD_DIR)" \
diff --git a/ipfw/Makefile b/ipfw/Makefile
index a32d02a..358e462 100644
--- a/ipfw/Makefile
+++ b/ipfw/Makefile
@@ -6,6 +6,7 @@
 # Do not set with = or := so we can inherit from the caller
 
 include ../Makefile.inc
+TARGET := ipfw
 
 all: $(TARGET)
 
@@ -17,7 +18,6 @@ EXTRA_CFLAGS += -Wall
 EXTRA_CFLAGS += -include ../glue.h
 EXTRA_CFLAGS += -I ./include_e -I ./include
 
-TARGET := ipfw
 ifneq ($(VER),openwrt)
 ifeq ($(OSARCH),Linux)
     EXTRA_CFLAGS += -D__BSD_VISIBLE
@@ -88,7 +88,7 @@ CFLAGS += -DNO_ALTQ
 #OBJS += altq.o
 
 all: $(TARGET)
-	-@echo "Done build for $(OSARCH) VER $(VER)"
+	-@echo "Done build for $(OSARCH)"
 
 $(TARGET): $(OBJS)
 	$(MSG) "   LD  $@"
diff --git a/kipfw/Makefile b/kipfw/Makefile
index 431e1f9..697a370 100644
--- a/kipfw/Makefile
+++ b/kipfw/Makefile
@@ -42,7 +42,8 @@ TARGET = kipfw
 # lets default for 2.6 for planetlab builds
 VER ?= 2.6
 
-$(warning ########## linux dir is $(LINUX_DIR) ###########)
+# $(warning ########## linux dir is $(LINUX_DIR) ###########)
+# $(warning ########## KERNELPATH is $(KERNELPATH) ###########)
 #--- General values for all types of build ---
 # obj-m is the target module
 obj-m := ipfw_mod.o
-- 
2.47.0