From 910f49d7b9c08f9745bd5eb60cfb800c940899c3 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Sun, 24 Jul 2005 19:58:14 +0000
Subject: [PATCH] move wificonf and nvram stuff back to package/, remove
 build_mipsel/root, run install part of package/ for every board/kernel -
 fixes dependency mess

SVN-Revision: 1540
---
 openwrt/Makefile                              | 35 +-----------
 openwrt/package/Config.in                     |  2 +-
 openwrt/package/Makefile                      | 17 ++++--
 openwrt/package/base-files/Makefile           | 20 ++++---
 .../{target/linux => }/package/nvram/Makefile |  8 ++-
 .../package/nvram/ipkg/nvram.control          |  0
 .../linux => }/package/nvram/src/Makefile     |  0
 .../linux => }/package/nvram/src/bcmtimer.h   |  0
 .../linux => }/package/nvram/src/defaults.c   |  0
 .../package/nvram/src/linux_timer.c           |  0
 .../linux => }/package/nvram/src/main.c       |  0
 .../package/nvram/src/nvram_convert.c         |  0
 .../package/nvram/src/nvram_convert.h         |  0
 .../package/nvram/src/nvram_linux.c           |  0
 .../linux => }/package/nvram/src/shutils.c    |  0
 .../{target/linux => }/package/nvram/src/wl.c |  0
 .../linux => }/package/nvram/src/wl_linux.c   |  0
 openwrt/package/rules.mk                      |  4 ++
 openwrt/package/ser/Makefile                  | 55 ++++++-------------
 openwrt/package/ser/{ => ipkg}/ser.control    |  0
 .../linux => }/package/wificonf/Config.in     |  0
 .../linux => }/package/wificonf/Makefile      |  5 +-
 .../package/wificonf/ipkg/wificonf.control    |  0
 .../linux => }/package/wificonf/wificonf.c    |  0
 openwrt/rules.mk                              |  6 --
 openwrt/target/linux/linux-2.4/Makefile       | 20 +++----
 openwrt/target/linux/package/Makefile         |  6 +-
 openwrt/target/linux/package/openwrt/Makefile | 12 ++--
 28 files changed, 78 insertions(+), 112 deletions(-)
 rename openwrt/{target/linux => }/package/nvram/Makefile (88%)
 rename openwrt/{target/linux => }/package/nvram/ipkg/nvram.control (100%)
 rename openwrt/{target/linux => }/package/nvram/src/Makefile (100%)
 rename openwrt/{target/linux => }/package/nvram/src/bcmtimer.h (100%)
 rename openwrt/{target/linux => }/package/nvram/src/defaults.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/linux_timer.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/main.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/nvram_convert.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/nvram_convert.h (100%)
 rename openwrt/{target/linux => }/package/nvram/src/nvram_linux.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/shutils.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/wl.c (100%)
 rename openwrt/{target/linux => }/package/nvram/src/wl_linux.c (100%)
 rename openwrt/package/ser/{ => ipkg}/ser.control (100%)
 rename openwrt/{target/linux => }/package/wificonf/Config.in (100%)
 rename openwrt/{target/linux => }/package/wificonf/Makefile (92%)
 rename openwrt/{target/linux => }/package/wificonf/ipkg/wificonf.control (100%)
 rename openwrt/{target/linux => }/package/wificonf/wificonf.c (100%)

diff --git a/openwrt/Makefile b/openwrt/Makefile
index 45a9ba7ffb..d478227523 100644
--- a/openwrt/Makefile
+++ b/openwrt/Makefile
@@ -1,6 +1,6 @@
 # Makefile for OpenWRT
 #
-# Copyright (C) 2005 by Felix Fietkau <nbd@vd-s.ath.cx>
+# Copyright (C) 2005 by Felix Fietkau <openwrt@nbd.name>
 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -47,26 +47,6 @@ all: world
 
 .NOTPARALLEL:
 
-##############################################################
-#
-# Build the toolchain
-#
-##############################################################
-toolchain_install:
-	$(MAKE) -C toolchain install
-
-##############################################################
-#
-# Make all packages
-#
-##############################################################
-
-package_compile: target_compile
-	$(MAKE) -C package compile
-
-package_install: package_compile toolchain
-	$(MAKE) -C package install
-
 #############################################################
 #
 # You should probably leave this stuff alone unless you know
@@ -77,9 +57,9 @@ package_install: package_compile toolchain
 # In this section, we need .config
 include .config.cmd
 
-world: $(DL_DIR) $(BUILD_DIR) configtest toolchain_install package_install target_install package_index
+world: $(DL_DIR) $(BUILD_DIR) configtest toolchain/install target/compile package/compile target/install package_index
 
-.PHONY: all world clean dirclean distclean image_clean target_clean source target_install toolchain_install package_install configtest
+.PHONY: all world clean dirclean distclean image_clean target_clean source configtest
 
 configtest:
 	-cp .config .config.test
@@ -90,12 +70,6 @@ package_index:
 		$(STAGING_DIR)/usr/bin/ipkg-make-index . > Packages \
 	)
 
-target_compile:
-	$(MAKE) -C target compile
-
-target_install:
-	$(MAKE) -C target install
-
 $(DL_DIR):
 	@mkdir -p $(DL_DIR)
 
@@ -125,7 +99,6 @@ image_clean:
 	rm -rf $(BIN_DIR)
 	
 target_clean: image_clean
-	rm -rf $(TARGET_DIR)
 	rm -rf $(BUILD_DIR)/linux-*/root
 
 clean: target_clean
@@ -188,8 +161,6 @@ randconfig: $(CONFIG)/conf
 	-./scripts/configtest.pl
 
 allyesconfig: $(CONFIG)/conf
-	#@$(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
-	#sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
 	-touch .config
 	-cp .config .config.test
 	@$(CONFIG)/conf -o $(CONFIG_CONFIG_IN)
diff --git a/openwrt/package/Config.in b/openwrt/package/Config.in
index 52c98588ae..93e55e73a7 100644
--- a/openwrt/package/Config.in
+++ b/openwrt/package/Config.in
@@ -98,7 +98,7 @@ source "package/wol/Config.in"
 source "package/wpa_supplicant/Config.in"
 source "package/wput/Config.in"
 source "package/xinetd/Config.in"
-source "target/linux/package/wificonf/Config.in"
+source "package/wificonf/Config.in"
 
 comment "Libraries"
 source "package/glib/Config.in"
diff --git a/openwrt/package/Makefile b/openwrt/package/Makefile
index 8e3a29e317..b002876139 100644
--- a/openwrt/package/Makefile
+++ b/openwrt/package/Makefile
@@ -2,6 +2,7 @@
 include $(TOPDIR)/rules.mk
 
 package-:=tcp_wrappers
+package-y:=nvram
 package-$(BR2_PACKAGE_AICCU) += aiccu
 package-$(BR2_PACKAGE_AMWALL) += amwall
 package-$(BR2_PACKAGE_ARPTABLES) += arptables
@@ -134,6 +135,7 @@ package-$(BR2_PACKAGE_ULOGD) += ulogd
 package-$(BR2_PACKAGE_USBUTILS) += usbutils
 package-$(BR2_PACKAGE_VTUN) += vtun
 package-$(BR2_PACKAGE_VSFTPD) += vsftpd
+package-$(BR2_PACKAGE_WIFICONF) += wificonf
 package-$(BR2_PACKAGE_WIRELESS_TOOLS) += wireless-tools
 package-$(BR2_PACKAGE_WOL) += wol
 package-$(BR2_PACKAGE_WPA_SUPPLICANT) += wpa_supplicant
@@ -141,19 +143,19 @@ package-$(BR2_PACKAGE_WPUT) += wput
 package-$(BR2_PACKAGE_XINETD) += xinetd
 package-$(BR2_PACKAGE_ZLIB) += zlib
 
-DEV_LIBS:=tcp_wrappers glib ncurses openssl pcre popt zlib libnet libpcap mysql postgresql iptables matrixssl lzo gmp fuse portmap libelf uclibc++ speex libpng libgd wireless-tools
+DEV_LIBS:=tcp_wrappers glib ncurses openssl pcre popt zlib libnet libpcap mysql postgresql iptables matrixssl lzo gmp fuse portmap libelf uclibc++ speex libpng libgd wireless-tools nvram
 DEV_LIBS_COMPILE:=$(patsubst %,%-compile,$(DEV_LIBS))
 SDK_DEFAULT_PACKAGES:=busybox dnsmasq iptables wireless-tools dropbear bridge ipkg ppp
 SDK_DEFAULT_COMPILE:=$(patsubst %,%-compile,$(SDK_DEFAULT_PACKAGES))
 COMPILE_PACKAGES:=$(patsubst %,%-compile,$(package-y) $(package-m))
 INSTALL_PACKAGES:=$(patsubst %,%-install,$(package-y))
 
-all: compile install
+all: compile
 clean: $(patsubst %,%-clean,$(package-) $(package-y) $(package-m))
 compile: $(COMPILE_PACKAGES)
 install: base-files-install $(INSTALL_PACKAGES)
 
-$(COMPILE_PACKAGES): base-files-install
+$(COMPILE_PACKAGES): base-files-compile
 $(INSTALL_PACKAGES): base-files-install
 
 amwall-compile: libamsel-compile
@@ -199,7 +201,7 @@ tinc-compile: zlib-compile openssl-compile lzo-compile
 tor-compile: libevent-compile openssl-compile zlib-compile
 usbutils-compile: libusb-compile
 vtun-compile: zlib-compile openssl-compile lzo-compile
-wificonf-compile: wireless-tools-compile
+wificonf-compile: wireless-tools-compile nvram-compile
 wpa_supplicant-compile: openssl-compile
 
 asterisk-compile: ncurses-compile openssl-compile
@@ -292,8 +294,11 @@ $(STAMP_DIR):
 	@touch $(STAMP_DIR)/.$@
 
 %-install: %-compile
-	@[ -f $(STAMP_DIR)/.$@ ] || $(MAKE) -C $(patsubst %-install,%,$@) install
-	@touch $(STAMP_DIR)/.$@
+	@$(MAKE) -C $(patsubst %-install,%,$@) \
+		TARGET_DIR="$(TARGET_DIR)" \
+		IPKG_CONF="$(IPKG_CONF)" \
+		BOARD="$(BOARD)" \
+		install
 
 %-rebuild: 
 	@rm -f $(STAMP_DIR)/.$(patsubst %-rebuild,%,$@)-*
diff --git a/openwrt/package/base-files/Makefile b/openwrt/package/base-files/Makefile
index c8f8f67196..e2c47b51c2 100644
--- a/openwrt/package/base-files/Makefile
+++ b/openwrt/package/base-files/Makefile
@@ -4,23 +4,29 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=base-files
 PKG_RELEASE:=1
+PKG_BUILD_DIR:=$(BUILD_DIR)/base-files
 
-IDIR_BASE:=$(BUILD_DIR)/base-files
+include $(TOPDIR)/package/rules.mk
+
+IDIR_BASE:=$(PKG_BUILD_DIR)/base-files
 IPKG_BASE:=$(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_RELEASE)_$(ARCH).ipk
 
 LIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version}
-IDIR_LIBC:=$(BUILD_DIR)/uclibc
+IDIR_LIBC:=$(PKG_BUILD_DIR)/uclibc
 IPKG_LIBC:=$(PACKAGE_DIR)/uclibc_$(LIBC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
 
 GCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version}
-IDIR_GCC:=$(BUILD_DIR)/libgcc
+IDIR_GCC:=$(PKG_BUILD_DIR)/libgcc
 IPKG_GCC:=$(PACKAGE_DIR)/libgcc_$(GCC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
 
 PACKAGES:=$(IPKG_BASE) $(IPKG_LIBC) $(IPKG_GCC)
 
-$(PACKAGES): $(PACKAGE_DIR)
-$(PACKAGE_DIR):
-	mkdir -p $@
+$(PKG_BUILD_DIR)/.prepared:
+	mkdir -p $(PKG_BUILD_DIR) $(PACKAGE_DIR)
+	touch $@
+
+$(PKG_BUILD_DIR)/.built:
+	touch $@
 
 $(IPKG_BASE):
 	$(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_BASE) ipkg/$(PKG_NAME).control $(PKG_RELEASE) $(ARCH)
@@ -63,5 +69,3 @@ compile: $(PACKAGES)
 install: compile
 	mkdir -p $(TARGET_DIR)
 	$(IPKG) install $(PACKAGES)
-clean:
-	rm -rf $(IDIR_BASE) $(IDIR_LIBC) $(IDIR_GCC)
diff --git a/openwrt/target/linux/package/nvram/Makefile b/openwrt/package/nvram/Makefile
similarity index 88%
rename from openwrt/target/linux/package/nvram/Makefile
rename to openwrt/package/nvram/Makefile
index 3e5263b34a..9885f99089 100644
--- a/openwrt/target/linux/package/nvram/Makefile
+++ b/openwrt/package/nvram/Makefile
@@ -9,7 +9,13 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
 include $(TOPDIR)/package/rules.mk
 
-BR2_PACKAGE_NVRAM:=y	# does not depend on menuconfig
+# does not depend on menuconfig
+ifneq ($(BOARD),brcm)
+BR2_PACKAGE_NVRAM:=m
+else
+BR2_PACKAGE_NVRAM:=y
+endif
+
 $(eval $(call PKG_template,NVRAM,nvram,$(PKG_RELEASE),$(ARCH)))
 
 $(PKG_BUILD_DIR)/.prepared:
diff --git a/openwrt/target/linux/package/nvram/ipkg/nvram.control b/openwrt/package/nvram/ipkg/nvram.control
similarity index 100%
rename from openwrt/target/linux/package/nvram/ipkg/nvram.control
rename to openwrt/package/nvram/ipkg/nvram.control
diff --git a/openwrt/target/linux/package/nvram/src/Makefile b/openwrt/package/nvram/src/Makefile
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/Makefile
rename to openwrt/package/nvram/src/Makefile
diff --git a/openwrt/target/linux/package/nvram/src/bcmtimer.h b/openwrt/package/nvram/src/bcmtimer.h
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/bcmtimer.h
rename to openwrt/package/nvram/src/bcmtimer.h
diff --git a/openwrt/target/linux/package/nvram/src/defaults.c b/openwrt/package/nvram/src/defaults.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/defaults.c
rename to openwrt/package/nvram/src/defaults.c
diff --git a/openwrt/target/linux/package/nvram/src/linux_timer.c b/openwrt/package/nvram/src/linux_timer.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/linux_timer.c
rename to openwrt/package/nvram/src/linux_timer.c
diff --git a/openwrt/target/linux/package/nvram/src/main.c b/openwrt/package/nvram/src/main.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/main.c
rename to openwrt/package/nvram/src/main.c
diff --git a/openwrt/target/linux/package/nvram/src/nvram_convert.c b/openwrt/package/nvram/src/nvram_convert.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/nvram_convert.c
rename to openwrt/package/nvram/src/nvram_convert.c
diff --git a/openwrt/target/linux/package/nvram/src/nvram_convert.h b/openwrt/package/nvram/src/nvram_convert.h
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/nvram_convert.h
rename to openwrt/package/nvram/src/nvram_convert.h
diff --git a/openwrt/target/linux/package/nvram/src/nvram_linux.c b/openwrt/package/nvram/src/nvram_linux.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/nvram_linux.c
rename to openwrt/package/nvram/src/nvram_linux.c
diff --git a/openwrt/target/linux/package/nvram/src/shutils.c b/openwrt/package/nvram/src/shutils.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/shutils.c
rename to openwrt/package/nvram/src/shutils.c
diff --git a/openwrt/target/linux/package/nvram/src/wl.c b/openwrt/package/nvram/src/wl.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/wl.c
rename to openwrt/package/nvram/src/wl.c
diff --git a/openwrt/target/linux/package/nvram/src/wl_linux.c b/openwrt/package/nvram/src/wl_linux.c
similarity index 100%
rename from openwrt/target/linux/package/nvram/src/wl_linux.c
rename to openwrt/package/nvram/src/wl_linux.c
diff --git a/openwrt/package/rules.mk b/openwrt/package/rules.mk
index a95c4e421b..f7b81c62af 100644
--- a/openwrt/package/rules.mk
+++ b/openwrt/package/rules.mk
@@ -1,3 +1,7 @@
+# invoke ipkg with configuration in $(STAGING_DIR)/etc/ipkg.conf 
+IPKG := IPKG_INSTROOT=$(TARGET_DIR) IPKG_CONF_DIR=$(IPKG_CONF) $(SCRIPT_DIR)/ipkg -force-defaults -force-depends
+IPKG_STATE_DIR := $(TARGET_DIR)/usr/lib/ipkg
+
 define PKG_template
 IPKG_$(1):=$(PACKAGE_DIR)/$(2)_$(3)_$(4).ipk
 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(2)
diff --git a/openwrt/package/ser/Makefile b/openwrt/package/ser/Makefile
index 81cb347dcc..603d4bceed 100644
--- a/openwrt/package/ser/Makefile
+++ b/openwrt/package/ser/Makefile
@@ -11,55 +11,36 @@ PKG_SOURCE_URL:=ftp://ftp.berlios.de/pub/ser/$(PKG_VERSION)/src
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_src.tar.gz
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 PKG_CAT:=zcat
-PKG_IPK:=$(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
-PKG_IPK_DIR:=$(PKG_BUILD_DIR)/ipkg
+
+include $(TOPDIR)/package/rules.mk
+
+$(eval $(call PKG_template,SER,ser,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))
 
 SER_MODULES := sl tm rr maxfwd usrloc registrar dbtext textops nathelper
 
 SER_MODULE_FILES := $(foreach module,$(SER_MODULES),modules/$(module)/$(module).so)
 SER_MODULES := $(patsubst %,modules/%,$(SER_MODULES))
 
-$(DL_DIR)/$(PKG_SOURCE):
-	$(SCRIPT_DIR)/download.pl $(DL_DIR) $(PKG_SOURCE) $(PKG_MD5SUM) $(PKG_SOURCE_URL)
-
-$(PKG_BUILD_DIR)/.patched: $(DL_DIR)/$(PKG_SOURCE)
-	$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
-	$(PATCH) $(PKG_BUILD_DIR) ./patches
-	touch $(PKG_BUILD_DIR)/.patched
-
-$(PKG_BUILD_DIR)/$(PKG_NAME): $(PKG_BUILD_DIR)/.patched
+$(PKG_BUILD_DIR)/.built:
 	$(MAKE) -C $(PKG_BUILD_DIR) \
 		extra_defs="-DUSE_PTHREAD_MUTEX "  \
 		CC="$(TARGET_CC)" \
 		ARCH="$(ARCH)" \
 		CFLAGS="$(TARGET_CFLAGS)" \
 		modules all
-
-$(PKG_IPK): $(PKG_BUILD_DIR)/$(PKG_NAME)
-	$(SCRIPT_DIR)/make-ipkg-dir.sh $(PKG_IPK_DIR) $(PKG_NAME).control $(PKG_VERSION)-$(PKG_RELEASE) $(ARCH)
-	mkdir -p $(PKG_IPK_DIR)/usr/sbin
-	cp -a $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_IPK_DIR)/usr/sbin/
-	-$(STRIP) $(PKG_IPK_DIR)/usr/sbin/*
-	cp -a $(PKG_BUILD_DIR)/scripts/sc $(PKG_IPK_DIR)/usr/sbin/serctl
-	mkdir -p $(PKG_IPK_DIR)/usr/lib/ser/modules
+	touch $@
+
+$(IPKG_SER):
+	mkdir -p $(IDIR_SER)/usr/sbin
+	cp -a $(PKG_BUILD_DIR)/$(PKG_NAME) $(IDIR_SER)/usr/sbin/
+	-$(STRIP) $(IDIR_SER)/usr/sbin/*
+	cp -a $(PKG_BUILD_DIR)/scripts/sc $(IDIR_SER)/usr/sbin/serctl
+	mkdir -p $(IDIR_SER)/usr/lib/ser/modules
 	(cd $(PKG_BUILD_DIR);\
-		cp -a $(SER_MODULE_FILES) $(PKG_IPK_DIR)/usr/lib/ser/modules/; \
+		cp -a $(SER_MODULE_FILES) $(IDIR_SER)/usr/lib/ser/modules/; \
 	)
-	$(STRIP) $(PKG_IPK_DIR)/usr/lib/ser/modules/*
-	mkdir -p $(PKG_IPK_DIR)/etc/ser
-	cp -a $(PKG_BUILD_DIR)/etc/ser.cfg $(PKG_IPK_DIR)/etc/ser/
-	mkdir -p $(PACKAGE_DIR)
-	$(IPKG_BUILD) $(PKG_IPK_DIR) $(PACKAGE_DIR)
-
-$(IPKG_STATE_DIR)/info/$(PKG_NAME).list: $(PKG_IPK)
-	$(IPKG) install $(PKG_IPK)
-
-source: $(DL_DIR)/$(PKG_SOURCE)
-prepare: $(PKG_BUILD_DIR)/.patched
-compile: $(PKG_IPK)
-install: $(IPKG_STATE_DIR)/info/$(PKG_NAME).list
-
+	$(STRIP) $(IDIR_SER)/usr/lib/ser/modules/*
+	mkdir -p $(IDIR_SER)/etc/ser
+	cp -a $(PKG_BUILD_DIR)/etc/ser.cfg $(IDIR_SER)/etc/ser/
+	$(IPKG_BUILD) $(IDIR_SER) $(PACKAGE_DIR)
 
-clean:
-	rm -rf $(PKG_BUILD_DIR)
-	rm -f $(PKG_IPK)
diff --git a/openwrt/package/ser/ser.control b/openwrt/package/ser/ipkg/ser.control
similarity index 100%
rename from openwrt/package/ser/ser.control
rename to openwrt/package/ser/ipkg/ser.control
diff --git a/openwrt/target/linux/package/wificonf/Config.in b/openwrt/package/wificonf/Config.in
similarity index 100%
rename from openwrt/target/linux/package/wificonf/Config.in
rename to openwrt/package/wificonf/Config.in
diff --git a/openwrt/target/linux/package/wificonf/Makefile b/openwrt/package/wificonf/Makefile
similarity index 92%
rename from openwrt/target/linux/package/wificonf/Makefile
rename to openwrt/package/wificonf/Makefile
index aa03683a10..ed41e416c8 100644
--- a/openwrt/target/linux/package/wificonf/Makefile
+++ b/openwrt/package/wificonf/Makefile
@@ -9,8 +9,9 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/wificonf
 
 include $(TOPDIR)/package/rules.mk
 
-
-
+ifneq ($(BOARD),brcm)
+BR2_PACKAGE_WIFICONF:=m
+endif
 
 $(eval $(call PKG_template,WIFICONF,$(PKG_NAME),$(PKG_RELEASE),$(ARCH)))
 
diff --git a/openwrt/target/linux/package/wificonf/ipkg/wificonf.control b/openwrt/package/wificonf/ipkg/wificonf.control
similarity index 100%
rename from openwrt/target/linux/package/wificonf/ipkg/wificonf.control
rename to openwrt/package/wificonf/ipkg/wificonf.control
diff --git a/openwrt/target/linux/package/wificonf/wificonf.c b/openwrt/package/wificonf/wificonf.c
similarity index 100%
rename from openwrt/target/linux/package/wificonf/wificonf.c
rename to openwrt/package/wificonf/wificonf.c
diff --git a/openwrt/rules.mk b/openwrt/rules.mk
index e69654e0e1..57544ee5bf 100644
--- a/openwrt/rules.mk
+++ b/openwrt/rules.mk
@@ -52,7 +52,6 @@ SCRIPT_DIR:=$(BASE_DIR)/scripts
 BIN_DIR:=$(BASE_DIR)/bin
 STAMP_DIR:=$(BUILD_DIR)/stamp
 PACKAGE_DIR:=$(BIN_DIR)/packages
-TARGET_DIR:=$(BUILD_DIR)/root
 STAMP_DIR:=$(BUILD_DIR)/stamp
 TOOL_BUILD_DIR=$(BASE_DIR)/toolchain_build_$(ARCH)$(ARCH_FPU_SUFFIX)
 # Strip off the annoying quoting
@@ -106,11 +105,6 @@ ifeq ($(BR2_ENABLE_MULTILIB),y)
 MULTILIB:=--enable-multilib
 endif
 
-
-# invoke ipkg with configuration in $(STAGING_DIR)/etc/ipkg.conf 
-IPKG := IPKG_INSTROOT=$(TARGET_DIR) IPKG_CONF_DIR=$(STAGING_DIR)/etc $(SCRIPT_DIR)/ipkg -force-defaults -force-depends
-IPKG_STATE_DIR := $(TARGET_DIR)/usr/lib/ipkg
-
 # invoke ipkg-build with some default options
 IPKG_BUILD := PATH="$(TARGET_PATH)" ipkg-build -c -o root -g root
 
diff --git a/openwrt/target/linux/linux-2.4/Makefile b/openwrt/target/linux/linux-2.4/Makefile
index defa97824d..8305f9c263 100644
--- a/openwrt/target/linux/linux-2.4/Makefile
+++ b/openwrt/target/linux/linux-2.4/Makefile
@@ -13,11 +13,6 @@
 include $(TOPDIR)/rules.mk
 include ../rules.mk
 
-# for testing
-ifeq ($(BOARD),)
-BOARD:=brcm
-endif
-
 LINUX_VERSION:=2.4.30
 MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
 LINUX_KCONFIG:=./config/$(BOARD)
@@ -43,7 +38,7 @@ PKG_RELEASE := 2
 KERNEL_IPKG:=$(LINUX_BUILD_DIR)/kernel-$(LINUX_VERSION)-$(BOARD)_$(PKG_RELEASE)_$(ARCH).ipk
 KERNEL_IDIR:=$(LINUX_BUILD_DIR)/kernel-ipkg
 
-PKG_MAKEOPTS:=	IPKG="$(IPKG_KERNEL)" \
+KPKG_MAKEOPTS:=	IPKG="$(IPKG_KERNEL)" \
 		BOARD="$(BOARD)" \
 		TARGET_DIR="$(LINUX_TARGET_DIR)" \
 		BUILD_DIR="$(LINUX_BUILD_DIR)" \
@@ -238,20 +233,25 @@ prepare: $(LINUX_DIR)/.configured
 compile: $(LINUX_DIR)/.modules_done $(TARGETS)
 	ln -sf $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) $(LINUX_DIR)
 	$(MAKE) -C $(TOPDIR)/target/linux/package \
-		$(PKG_MAKEOPTS) \
+		$(KPKG_MAKEOPTS) \
 		compile
 
 install: compile $(TARGET_MODULES_DIR) $(KERNEL_IPKG)
 	rm -rf $(LINUX_BUILD_DIR)/root*
-	cp -a $(BUILD_DIR)/root $(LINUX_BUILD_DIR)/
 	echo -e 'dest root /\noption offline_root $(LINUX_BUILD_DIR)/root' > $(LINUX_BUILD_DIR)/ipkg.conf
 	[ "$(INSTALL_TARGETS)" != "" ] && $(IPKG_KERNEL) install $(INSTALL_TARGETS) || true
+	$(MAKE) -C $(TOPDIR)/package \
+		TARGET_DIR="$(LINUX_TARGET_DIR)" \
+		IPKG_CONF="$(LINUX_BUILD_DIR)" \
+		BOARD="$(BOARD)" \
+		install
 	$(MAKE) -C $(TOPDIR)/target/linux/package \
-		$(PKG_MAKEOPTS) \
+		$(KPKG_MAKEOPTS) \
 		install
 
 mostlyclean:
-	rm -f $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)/.{drivers-unpacked,modules_done}
+	rm -f $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
+	rm -f $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
 	$(MAKE) -C $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) clean
 	rm -f $(LINUX_KERNEL) $(LINUX_IMAGE)
 
diff --git a/openwrt/target/linux/package/Makefile b/openwrt/target/linux/package/Makefile
index 84402cce2e..43fbd60f22 100644
--- a/openwrt/target/linux/package/Makefile
+++ b/openwrt/target/linux/package/Makefile
@@ -8,14 +8,10 @@ package-$(BR2_PACKAGE_KMOD_OPENSWAN) += openswan
 package-y += openwrt
 
 ifeq ($(BOARD),brcm)
-package-$(BR2_PACKAGE_WIFICONF) += wificonf
-package-y += nvram
-
 ifeq ($(LINUX_VERSION),2.4.30)
 package-$(BR2_PACKAGE_KMOD_WLCOMPAT) += wlcompat
+wlcompat-compile: openwrt-compile
 endif
-
-nvram-compile: openwrt-compile
 endif
 
 all: compile install
diff --git a/openwrt/target/linux/package/openwrt/Makefile b/openwrt/target/linux/package/openwrt/Makefile
index 5d2ea199ec..75053b1485 100644
--- a/openwrt/target/linux/package/openwrt/Makefile
+++ b/openwrt/target/linux/package/openwrt/Makefile
@@ -4,12 +4,12 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME := base-files-arch
 PKG_RELEASE := 1
-PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(BOARD)
 
 include $(TOPDIR)/package/rules.mk
 
-BR2_PACKAGE_OPENWRT:=y		# ignore menuconfig
-$(eval $(call PKG_template,OPENWRT,$(PKG_NAME),$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))
+IDIR_OPENWRT:=$(PKG_BUILD_DIR)/ipkg
+IPKG_OPENWRT:=$(PACKAGE_DIR)/base-files-$(BOARD)_$(PKG_RELEASE)_$(ARCH).ipk
 
 $(PKG_BUILD_DIR)/.prepared:
 	mkdir -p $(PKG_BUILD_DIR)
@@ -30,8 +30,12 @@ endif
 
 $(PKG_BUILD_DIR)/.built:
 	touch $@
+	
+$(IDIR_OPENWRT):
+	$(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_OPENWRT) ipkg/base-files-arch.control $(PKG_RELEASE) $(ARCH)
+	$(SED) s,base-files-arch,base-files-$(BOARD),g $(IDIR_OPENWRT)/CONTROL/control
 
-$(IPKG_OPENWRT): 
+$(IPKG_OPENWRT):
 	mkdir -p $(IDIR_OPENWRT)/etc
 	cp files/network.overrides.$(BOARD) $(IDIR_OPENWRT)/etc/network.overrides
 	$(RSTRIP) $(IDIR_OPENWRT)
-- 
2.30.2