From 4e24e35fa9083cfe57d7b1fe7b51c5f2f6515f18 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Wed, 21 Jun 2006 02:16:37 +0000
Subject: [PATCH] build system cleanup. move shared include files into
 $(TOPDIR)/include, move lzma, mkfs.* into toolchain/

SVN-Revision: 4032
---
 openwrt/include/image.mk                      | 77 +++++++++++++++++++
 .../kernel.mk => include/kernel-build.mk}     | 33 ++++----
 .../linux/rules.mk => include/kernel.mk}      | 34 ++++----
 .../modules.mk => include/modules-2.4.mk}     |  2 +-
 .../modules.mk => include/modules-2.6.mk}     |  2 +-
 .../{target/linux => include}/netfilter.mk    |  0
 .../{package/rules.mk => include/package.mk}  |  0
 openwrt/package/alsa/Makefile                 |  4 +-
 openwrt/package/base-files/Makefile           |  4 +-
 openwrt/package/bridge/Makefile               |  2 +-
 openwrt/package/broadcom-wl/Makefile          |  4 +-
 openwrt/package/busybox/Makefile              |  2 +-
 openwrt/package/diag/Makefile                 |  4 +-
 openwrt/package/dnsmasq/Makefile              |  2 +-
 openwrt/package/dropbear/Makefile             |  2 +-
 openwrt/package/ebtables/Makefile             |  2 +-
 openwrt/package/fuse/Makefile                 |  4 +-
 openwrt/package/haserl/Makefile               |  2 +-
 openwrt/package/hostap/Makefile               |  4 +-
 openwrt/package/hostapd/Makefile              |  2 +-
 openwrt/package/iproute2/Makefile             |  2 +-
 openwrt/package/ipsec-tools/Makefile          |  2 +-
 openwrt/package/ipset/Makefile                |  2 +-
 openwrt/package/iptables/Makefile             |  6 +-
 openwrt/package/kernel.mk                     | 31 --------
 openwrt/package/libpcap/Makefile              |  2 +-
 openwrt/package/linux-atm/Makefile            |  2 +-
 openwrt/package/madwifi/Makefile              |  4 +-
 openwrt/package/mini_fo/Makefile              |  4 +-
 openwrt/package/mtd/Makefile                  |  2 +-
 openwrt/package/nvram/Makefile                |  2 +-
 openwrt/package/openssl/Makefile              |  2 +-
 openwrt/package/openswan/Makefile             |  4 +-
 openwrt/package/pcmcia-cs/Makefile            |  2 +-
 openwrt/package/ppp/Makefile                  |  2 +-
 openwrt/package/pptp/Makefile                 |  2 +-
 openwrt/package/robocfg/Makefile              |  2 +-
 openwrt/package/shfs/Makefile                 |  4 +-
 openwrt/package/spca5xx/Makefile              |  4 +-
 openwrt/package/switch/Makefile               |  4 +-
 openwrt/package/udev/Makefile                 |  2 +-
 openwrt/package/ueagle-atm/Makefile           |  4 +-
 openwrt/package/util-linux/Makefile           |  2 +-
 openwrt/package/wireless-tools/Makefile       |  2 +-
 openwrt/package/wlcompat/Makefile             |  4 +-
 openwrt/package/zd1211/Makefile               |  4 +-
 openwrt/package/zlib/Makefile                 |  2 +-
 openwrt/target/Makefile                       |  9 +--
 openwrt/target/linux/Config.in                |  4 +-
 openwrt/target/linux/Makefile                 |  1 +
 openwrt/target/linux/ar531x-2.4/Makefile      |  5 +-
 openwrt/target/linux/ar7-2.4/Makefile         |  5 +-
 openwrt/target/linux/aruba-2.6/Makefile       |  7 +-
 openwrt/target/linux/au1000-2.6/Makefile      |  7 +-
 openwrt/target/linux/brcm-2.4/Makefile        |  5 +-
 openwrt/target/linux/brcm-2.6/Makefile        |  6 +-
 openwrt/target/linux/image/ar7/Makefile       |  2 +-
 openwrt/target/linux/image/aruba/Makefile     |  2 +-
 openwrt/target/linux/image/au1000/Makefile    |  2 +-
 openwrt/target/linux/image/brcm/Makefile      |  2 +-
 openwrt/target/linux/image/generic/Makefile   |  2 +-
 openwrt/target/linux/image/image.mk           | 55 -------------
 openwrt/target/linux/image/jffs2.mk           | 30 --------
 openwrt/target/linux/image/rb532/Makefile     |  2 +-
 openwrt/target/linux/image/squashfs.mk        | 25 ------
 openwrt/target/linux/image/tgz.mk             |  3 -
 openwrt/target/linux/image/x86/Makefile       |  2 +-
 openwrt/target/linux/image/xscale/Makefile    |  2 +-
 openwrt/target/linux/rb532-2.6/Makefile       |  6 +-
 openwrt/target/linux/sibyte-2.6/Makefile      |  7 +-
 openwrt/target/linux/x86-2.4/Makefile         |  7 +-
 openwrt/target/linux/x86-2.6/Makefile         |  7 +-
 openwrt/target/linux/xscale-2.6/Makefile      |  7 +-
 openwrt/toolchain/Makefile                    |  3 +-
 .../linux/image => toolchain}/jffs2/Makefile  |  0
 .../jffs2/patches/100-gcc4_fix.patch}         |  0
 openwrt/{target => toolchain}/lzma/Makefile   |  2 +-
 .../lzma/patches/100-lzma_zlib.patch}         |  0
 .../image => toolchain}/squashfs/Makefile     |  0
 .../squashfs/patches/100-lzma.patch           |  0
 80 files changed, 204 insertions(+), 304 deletions(-)
 create mode 100644 openwrt/include/image.mk
 rename openwrt/{target/linux/kernel.mk => include/kernel-build.mk} (80%)
 rename openwrt/{target/linux/rules.mk => include/kernel.mk} (77%)
 rename openwrt/{target/linux/generic-2.4/modules.mk => include/modules-2.4.mk} (99%)
 rename openwrt/{target/linux/generic-2.6/modules.mk => include/modules-2.6.mk} (99%)
 rename openwrt/{target/linux => include}/netfilter.mk (100%)
 rename openwrt/{package/rules.mk => include/package.mk} (100%)
 delete mode 100644 openwrt/package/kernel.mk
 delete mode 100644 openwrt/target/linux/image/image.mk
 delete mode 100644 openwrt/target/linux/image/jffs2.mk
 delete mode 100644 openwrt/target/linux/image/squashfs.mk
 delete mode 100644 openwrt/target/linux/image/tgz.mk
 rename openwrt/{target/linux/image => toolchain}/jffs2/Makefile (100%)
 rename openwrt/{target/linux/image/jffs2/patches/gcc4-fix.patch => toolchain/jffs2/patches/100-gcc4_fix.patch} (100%)
 rename openwrt/{target => toolchain}/lzma/Makefile (96%)
 rename openwrt/{target/lzma/lzma-zlib.patch => toolchain/lzma/patches/100-lzma_zlib.patch} (100%)
 rename openwrt/{target/linux/image => toolchain}/squashfs/Makefile (100%)
 rename openwrt/{target/linux/image => toolchain}/squashfs/patches/100-lzma.patch (100%)

diff --git a/openwrt/include/image.mk b/openwrt/include/image.mk
new file mode 100644
index 0000000000..f30f0997ee
--- /dev/null
+++ b/openwrt/include/image.mk
@@ -0,0 +1,77 @@
+include $(TOPDIR)/rules.mk
+
+KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
+
+ifneq ($(CONFIG_BIG_ENDIAN),y)
+JFFS2OPTS     :=  --pad --little-endian --squash
+SQUASHFS_OPTS :=  -le
+else
+JFFS2OPTS     :=  --pad --big-endian --squash
+SQUASHFS_OPTS :=  -be
+endif
+
+ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
+  ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y)
+    define Image/mkfs/jffs2
+		rm -rf $(BUILD_DIR)/root/jffs
+		
+		$(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x10000 -o $(KDIR)/root.jffs2-64k -d $(BUILD_DIR)/root
+		$(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x20000 -o $(KDIR)/root.jffs2-128k -d $(BUILD_DIR)/root
+	
+		$(call Image/Build,jffs2-64k)
+		$(call Image/Build,jffs2-128k)
+    endef
+  endif
+    
+  ifeq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),y)
+    define Image/mkfs/squashfs
+		@mkdir -p $(BUILD_DIR)/root/jffs
+		$(STAGING_DIR)/bin/mksquashfs-lzma $(BUILD_DIR)/root $(KDIR)/root.squashfs -nopad -noappend -root-owned $(SQUASHFS_OPTS)
+		$(call Image/Build,squashfs)
+    endef
+  endif
+    
+  ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y)
+    define Image/mkfs/tgz
+		tar -zcf $(BIN_DIR)/openwrt-rootfs.tgz --owner=root --group=root -C $(BUILD_DIR)/root/ .
+    endef
+  endif
+endif
+
+define Image/mkfs/prepare/default
+	find $(BUILD_DIR)/root -type f -not -perm +0100 | xargs chmod 0644
+	find $(BUILD_DIR)/root -type f -perm +0100 | xargs chmod 0755
+	find $(BUILD_DIR)/root -type d | xargs chmod 0755
+	mkdir -p $(BUILD_DIR)/root/tmp
+	chmod 0777 $(BUILD_DIR)/root/tmp
+endef
+
+define Image/mkfs/prepare
+	$(call Image/mkfs/prepare/default)
+endef
+
+define BuildImage
+compile:
+	$(call Build/Compile)
+
+install:
+	$(call Image/Prepare)
+	$(call Image/mkfs/prepare)
+	$(call Image/BuildKernel)
+	$(call Image/mkfs/jffs2)
+	$(call Image/mkfs/squashfs)
+	$(call Image/mkfs/tgz)
+	
+clean:
+	$(call Build/Clean)
+endef
+
+compile-targets:
+install-targets:
+clean-targets:
+
+source:
+prepare:
+compile: compile-targets
+install: compile install-targets
+clean: clean-targets
diff --git a/openwrt/target/linux/kernel.mk b/openwrt/include/kernel-build.mk
similarity index 80%
rename from openwrt/target/linux/kernel.mk
rename to openwrt/include/kernel-build.mk
index cd74fccfb8..9fbbe4504c 100644
--- a/openwrt/target/linux/kernel.mk
+++ b/openwrt/include/kernel-build.mk
@@ -1,10 +1,14 @@
-LINUX_SOURCE:=$(LINUX_NAME).tar.bz2
+include $(TOPDIR)/include/modules-$(KERNEL).mk
+
+LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.bz2
 LINUX_SITE=http://www.us.kernel.org/pub/linux/kernel/v$(KERNEL) \
            http://www.us.kernel.org/pub/linux/kernel/v$(KERNEL) \
            http://www.kernel.org/pub/linux/kernel/v$(KERNEL) \
            http://www.de.kernel.org/pub/linux/kernel/v$(KERNEL)
 
-KERNEL_IDIR:=$(LINUX_BUILD_DIR)/kernel-ipkg
+KERNEL_IDIR:=$(KERNEL_BUILD_DIR)/kernel-ipkg
+KERNEL_IPKG:=$(KERNEL_BUILD_DIR)/kernel_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
+INSTALL_TARGETS += $(KERNEL_IPKG)
 
 $(TARGETS): $(PACKAGE_DIR)
 
@@ -19,8 +23,8 @@ $(DL_DIR)/$(LINUX_SOURCE):
 	$(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
 
 $(LINUX_DIR)/.unpacked: $(DL_DIR)/$(LINUX_SOURCE)
-	-mkdir -p $(LINUX_BUILD_DIR)
-	bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(LINUX_BUILD_DIR) $(TAR_OPTIONS) -
+	-mkdir -p $(KERNEL_BUILD_DIR)
+	bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS) -
 	touch $@
 
 ifeq ($(KERNEL),2.4)
@@ -65,14 +69,14 @@ $(LINUX_KERNEL): $(LINUX_DIR)/vmlinux
 	touch -c $(LINUX_KERNEL)
 
 $(LINUX_DIR)/.modules_done:
-	rm -rf $(LINUX_BUILD_DIR)/modules
+	rm -rf $(KERNEL_BUILD_DIR)/modules
 	$(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) PATH="$(TARGET_PATH)" modules
-	$(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" DEPMOD=true INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules modules_install
+	$(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
 	touch $(LINUX_DIR)/.modules_done
 
 $(STAMP_DIR)/.linux-compile:
 	@$(MAKE) $(LINUX_DIR)/.modules_done $(TARGETS) $(KERNEL_IPKG)
-	ln -sf $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
+	ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
 	touch $@
 
 $(KERNEL_IPKG):
@@ -82,11 +86,10 @@ $(KERNEL_IPKG):
 	if [ -f ./config/$(BOARD).modules ]; then \
 		cp ./config/$(BOARD).modules $(KERNEL_IDIR)/etc/modules; \
 	fi
-	$(IPKG_BUILD) $(KERNEL_IDIR) $(LINUX_BUILD_DIR)
+	$(IPKG_BUILD) $(KERNEL_IDIR) $(KERNEL_BUILD_DIR)
 
-$(BUILD_DIR)/kernel.mk: $(LINUX_DIR) FORCE
+$(TOPDIR)/.kernel.mk:
 	echo "BOARD:=$(BOARD)" > $@
-	echo "LINUX_NAME:=$(LINUX_NAME)" >> $@
 	echo "LINUX_VERSION:=$(LINUX_VERSION)" >> $@
 	echo "LINUX_RELEASE:=$(LINUX_RELEASE)" >> $@
 
@@ -94,7 +97,7 @@ pkg-install: FORCE
 	@{ [ "$(INSTALL_TARGETS)" != "" ] && $(IPKG) install $(INSTALL_TARGETS) || true; }
 
 source: $(DL_DIR)/$(LINUX_SOURCE)
-prepare: $(BUILD_DIR)/kernel.mk
+prepare:
 	@mkdir -p $(STAMP_DIR) $(PACKAGE_DIR)
 	@$(MAKE) $(LINUX_DIR)/.configured
 
@@ -104,9 +107,9 @@ install: compile $(LINUX_KERNEL)
 
 mostlyclean: FORCE
 	rm -f $(STAMP_DIR)/.linux-compile
-	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 $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
+	rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
+	$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
 	rm -f $(LINUX_KERNEL)
 
 rebuild: FORCE
@@ -118,5 +121,5 @@ rebuild: FORCE
 
 clean: FORCE
 	rm -f $(STAMP_DIR)/.linux-compile
-	rm -rf $(LINUX_BUILD_DIR)
+	rm -rf $(KERNEL_BUILD_DIR)
 	rm -f $(TARGETS)
diff --git a/openwrt/target/linux/rules.mk b/openwrt/include/kernel.mk
similarity index 77%
rename from openwrt/target/linux/rules.mk
rename to openwrt/include/kernel.mk
index 166bfe24b6..5c64ee4e12 100644
--- a/openwrt/target/linux/rules.mk
+++ b/openwrt/include/kernel.mk
@@ -1,22 +1,16 @@
+ifneq ($(DUMP),1)
+include $(TOPDIR)/.kernel.mk
+
 KERNEL:=unknown
 ifneq (,$(findstring 2.4.,$(LINUX_VERSION)))
 KERNEL:=2.4
+LINUX_KMOD_SUFFIX=o
 endif
 ifneq (,$(findstring 2.6.,$(LINUX_VERSION)))
 KERNEL:=2.6
+LINUX_KMOD_SUFFIX=ko
 endif
 
-MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
-
-LINUX_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
-ifeq ($(LINUX_NAME),)
-LINUX_NAME:=linux-$(LINUX_VERSION)
-endif
-LINUX_DIR := $(LINUX_BUILD_DIR)/$(LINUX_NAME)
-LINUX_KERNEL:=$(LINUX_BUILD_DIR)/vmlinux
-
-LINUX_TARGET_DIR:=$(LINUX_BUILD_DIR)/root
-
 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
 	-e 's/mipsel/mips/' \
 	-e 's/mipseb/mips/' \
@@ -25,16 +19,18 @@ LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
 	-e 's/armeb/arm/' \
 )
 
-KMOD_BUILD_DIR := $(LINUX_BUILD_DIR)/linux-modules
-MODULES_DIR := $(LINUX_BUILD_DIR)/modules/$(MODULES_SUBDIR)
+KERNEL_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
+LINUX_DIR := $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
+
+MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
+MODULES_DIR := $(KERNEL_BUILD_DIR)/modules/$(MODULES_SUBDIR)
 TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
+KMOD_BUILD_DIR := $(KERNEL_BUILD_DIR)/linux-modules
 
-ifeq ($(KERNEL),2.6)
-LINUX_KMOD_SUFFIX=ko
-else
-LINUX_KMOD_SUFFIX=o
+LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
 endif
 
+# FIXME: remove this crap
 define KMOD_template
 ifeq ($$(strip $(4)),)
 KDEPEND_$(1):=m
@@ -79,7 +75,3 @@ endif
 	$(IPKG_BUILD) $$(I_$(1)) $(PACKAGE_DIR)
 endef
 
-KERNEL_IPKG:=$(LINUX_BUILD_DIR)/kernel_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
-INSTALL_TARGETS := $(KERNEL_IPKG)
-TARGETS := 
-
diff --git a/openwrt/target/linux/generic-2.4/modules.mk b/openwrt/include/modules-2.4.mk
similarity index 99%
rename from openwrt/target/linux/generic-2.4/modules.mk
rename to openwrt/include/modules-2.4.mk
index 540ac715cc..71864ad8eb 100644
--- a/openwrt/target/linux/generic-2.4/modules.mk
+++ b/openwrt/include/modules-2.4.mk
@@ -1,4 +1,4 @@
-include ../netfilter.mk
+include $(TOPDIR)/include/netfilter.mk
 
 # Networking
 
diff --git a/openwrt/target/linux/generic-2.6/modules.mk b/openwrt/include/modules-2.6.mk
similarity index 99%
rename from openwrt/target/linux/generic-2.6/modules.mk
rename to openwrt/include/modules-2.6.mk
index b582400bd6..ec9f5da44f 100644
--- a/openwrt/target/linux/generic-2.6/modules.mk
+++ b/openwrt/include/modules-2.6.mk
@@ -1,5 +1,5 @@
 NF_2_6:=1
-include ../netfilter.mk
+include $(TOPDIR)/include/netfilter.mk
 
 # Networking
 
diff --git a/openwrt/target/linux/netfilter.mk b/openwrt/include/netfilter.mk
similarity index 100%
rename from openwrt/target/linux/netfilter.mk
rename to openwrt/include/netfilter.mk
diff --git a/openwrt/package/rules.mk b/openwrt/include/package.mk
similarity index 100%
rename from openwrt/package/rules.mk
rename to openwrt/include/package.mk
diff --git a/openwrt/package/alsa/Makefile b/openwrt/package/alsa/Makefile
index b1b9997c19..5f6a3305b5 100644
--- a/openwrt/package/alsa/Makefile
+++ b/openwrt/package/alsa/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=alsa-driver
 PKG_VERSION:=1.0.11
@@ -13,7 +13,7 @@ PKG_SOURCE_URL:=ftp://ftp.alsa-project.org/pub/driver/
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_CAT:=bzcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 ifeq ($(LINUX_KARCH),i386)
 KERNEL_C_INCS:= -I$(LINUX_DIR)/include/asm-i386/mach-generic -I$(LINUX_DIR)/include/asm-i386/mach-default
diff --git a/openwrt/package/base-files/Makefile b/openwrt/package/base-files/Makefile
index ec3dc88923..bb20894096 100644
--- a/openwrt/package/base-files/Makefile
+++ b/openwrt/package/base-files/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=base-files
 PKG_RELEASE:=8
@@ -12,7 +12,7 @@ ifeq ($(REV),)
 REV:=0
 endif
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 ifneq ($(DUMP),1)
 TARGET:=-$(BOARD)-$(KERNEL)
diff --git a/openwrt/package/bridge/Makefile b/openwrt/package/bridge/Makefile
index 65fd8358e8..f2b178a610 100644
--- a/openwrt/package/bridge/Makefile
+++ b/openwrt/package/bridge/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=@SF/bridge
 PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/bridge
 SECTION:=base
diff --git a/openwrt/package/broadcom-wl/Makefile b/openwrt/package/broadcom-wl/Makefile
index 227352b156..6fe22edb0f 100644
--- a/openwrt/package/broadcom-wl/Makefile
+++ b/openwrt/package/broadcom-wl/Makefile
@@ -1,7 +1,7 @@
 # $Id: Makefile 2480 2005-11-14 02:07:33Z nbd $
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=broadcom-wl
 PKG_VERSION:=4.80.9.2
@@ -14,7 +14,7 @@ PKG_SOURCE_URL:=http://downloads.openwrt.org/sources
 PKG_MD5SUM:=7d9fab2c611369bbe075c3924ea77450
 PKG_CAT:=bzcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-brcm-wl
   SECTION:=drivers
diff --git a/openwrt/package/busybox/Makefile b/openwrt/package/busybox/Makefile
index aac9d21e32..6b2e0c5be4 100644
--- a/openwrt/package/busybox/Makefile
+++ b/openwrt/package/busybox/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=http://www.busybox.net/downloads
 PKG_MD5SUM:=19a0b475169335f17e421cf644616fe7
 PKG_CAT:=bzcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/busybox
 SECTION:=base
diff --git a/openwrt/package/diag/Makefile b/openwrt/package/diag/Makefile
index 6fed3b51bf..ab28e7218e 100644
--- a/openwrt/package/diag/Makefile
+++ b/openwrt/package/diag/Makefile
@@ -1,14 +1,14 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=kmod-diag
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-diag
 SECTION:=drivers
diff --git a/openwrt/package/dnsmasq/Makefile b/openwrt/package/dnsmasq/Makefile
index 6efaf370a1..a05ec0e22c 100644
--- a/openwrt/package/dnsmasq/Makefile
+++ b/openwrt/package/dnsmasq/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq
 PKG_MD5SUM:=489198ec87101087043adc98bbe062dc
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/dnsmasq
 SECTION:=base
diff --git a/openwrt/package/dropbear/Makefile b/openwrt/package/dropbear/Makefile
index bda4d8fc91..0409e66dbf 100644
--- a/openwrt/package/dropbear/Makefile
+++ b/openwrt/package/dropbear/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=http://matt.ucc.asn.au/dropbear/releases/
 PKG_MD5SUM:=ca8e53a766faec831882831364568421
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/dropbear
 SECTION:=base
diff --git a/openwrt/package/ebtables/Makefile b/openwrt/package/ebtables/Makefile
index f4359a6675..814ac68a22 100644
--- a/openwrt/package/ebtables/Makefile
+++ b/openwrt/package/ebtables/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=@SF/ebtables
 PKG_MD5SUM:=f07111fcc1966be669278433c35dcc28
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/ebtables
 SECTION:=base
diff --git a/openwrt/package/fuse/Makefile b/openwrt/package/fuse/Makefile
index 91d4dd6074..b7084236df 100644
--- a/openwrt/package/fuse/Makefile
+++ b/openwrt/package/fuse/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=fuse
 PKG_VERSION:=2.5.3
@@ -15,7 +15,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-fuse
 SECTION:=drivers
diff --git a/openwrt/package/haserl/Makefile b/openwrt/package/haserl/Makefile
index e6215c9547..ec940ea437 100644
--- a/openwrt/package/haserl/Makefile
+++ b/openwrt/package/haserl/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=@SF/haserl
 PKG_MD5SUM:=bd9195d086566f56634c0bcbbbcbebea
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/haserl
 SECTION:=base
diff --git a/openwrt/package/hostap/Makefile b/openwrt/package/hostap/Makefile
index 80f820187b..21abfe256b 100644
--- a/openwrt/package/hostap/Makefile
+++ b/openwrt/package/hostap/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=hostap-driver
 PKG_VERSION:=0.4.9
@@ -15,7 +15,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-hostap
 SECTION:=drivers
diff --git a/openwrt/package/hostapd/Makefile b/openwrt/package/hostapd/Makefile
index 4a1c3f9265..867cda6922 100644
--- a/openwrt/package/hostapd/Makefile
+++ b/openwrt/package/hostapd/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=zcat
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/hostapd
 SECTION:=net
diff --git a/openwrt/package/iproute2/Makefile b/openwrt/package/iproute2/Makefile
index 1fa638d39d..9cf1eb9909 100644
--- a/openwrt/package/iproute2/Makefile
+++ b/openwrt/package/iproute2/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=http://developer.osdl.org/dev/iproute2/download/
 PKG_MD5SUM:=04f57a6d366d36426d276178b600f5c5
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/ip
 SECTION:=base
diff --git a/openwrt/package/ipsec-tools/Makefile b/openwrt/package/ipsec-tools/Makefile
index 58dccca62a..667884debe 100644
--- a/openwrt/package/ipsec-tools/Makefile
+++ b/openwrt/package/ipsec-tools/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=bzcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/ipsec-tools
 SECTION:=base
diff --git a/openwrt/package/ipset/Makefile b/openwrt/package/ipset/Makefile
index 456f8b6be4..d245090a68 100644
--- a/openwrt/package/ipset/Makefile
+++ b/openwrt/package/ipset/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=http://ipset.netfilter.org
 PKG_MD5SUM:=1709424cc2cdb925d4fb6fd5fcaefc26
 PKG_CAT:=bzcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/ipset
 SECTION:=base
diff --git a/openwrt/package/iptables/Makefile b/openwrt/package/iptables/Makefile
index 623a64ed84..7490277440 100644
--- a/openwrt/package/iptables/Makefile
+++ b/openwrt/package/iptables/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=iptables
 PKG_VERSION:=1.3.5
@@ -20,10 +20,10 @@ PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
 PKG_MENU:=IPv4 / IPv6 firewall administration
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 ifeq ($(DUMP),)
 include $(LINUX_DIR)/.config
-include $(TOPDIR)/target/linux/netfilter.mk
+include $(TOPDIR)/include/netfilter.mk
 endif
 
 define Package/iptables
diff --git a/openwrt/package/kernel.mk b/openwrt/package/kernel.mk
deleted file mode 100644
index 39f9cc0c9c..0000000000
--- a/openwrt/package/kernel.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-ifneq ($(DUMP),1)
-include $(BUILD_DIR)/kernel.mk
-
-KERNEL:=unknown
-ifneq (,$(findstring 2.4.,$(LINUX_VERSION)))
-KERNEL:=2.4
-LINUX_KMOD_SUFFIX=o
-endif
-ifneq (,$(findstring 2.6.,$(LINUX_VERSION)))
-KERNEL:=2.6
-LINUX_KMOD_SUFFIX=ko
-endif
-
-LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
-	-e 's/mipsel/mips/' \
-	-e 's/mipseb/mips/' \
-	-e 's/powerpc/ppc/' \
-	-e 's/sh[234]/sh/' \
-	-e 's/armeb/arm/' \
-)
-
-KERNEL_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
-ifeq ($(LINUX_NAME),)
-LINUX_NAME:=linux-$(LINUX_VERSION)
-endif
-LINUX_DIR := $(KERNEL_BUILD_DIR)/$(LINUX_NAME)
-
-KMOD_BUILD_DIR := $(KERNEL_BUILD_DIR)/linux-modules
-MODULES_DIR := $(KERNEL_BUILD_DIR)/modules/$(MODULES_SUBDIR)
-TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
-endif
diff --git a/openwrt/package/libpcap/Makefile b/openwrt/package/libpcap/Makefile
index d4d7e21672..2d7aecf551 100644
--- a/openwrt/package/libpcap/Makefile
+++ b/openwrt/package/libpcap/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/libpcap
 SECTION:=base
diff --git a/openwrt/package/linux-atm/Makefile b/openwrt/package/linux-atm/Makefile
index e37d5bdceb..15b3f7d4da 100644
--- a/openwrt/package/linux-atm/Makefile
+++ b/openwrt/package/linux-atm/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=zcat
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/linux-atm
 SECTION:=libs
diff --git a/openwrt/package/madwifi/Makefile b/openwrt/package/madwifi/Makefile
index c689054811..7bdb7ec11a 100644
--- a/openwrt/package/madwifi/Makefile
+++ b/openwrt/package/madwifi/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=madwifi
 PKG_VERSION:=0.9.0
@@ -54,7 +54,7 @@ MADWIFI_MAKEOPTS= -C $(PKG_BUILD_DIR) \
 		LDOPTS="" \
 		DOMULTI=1
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 ifeq ($(findstring AHB,$(BUS)),AHB)
 define Build/Compile/ahb
diff --git a/openwrt/package/mini_fo/Makefile b/openwrt/package/mini_fo/Makefile
index f2c46c9ec3..0180f81c31 100644
--- a/openwrt/package/mini_fo/Makefile
+++ b/openwrt/package/mini_fo/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=mini_fo
 PKG_VERSION:=0.6.2pre1
@@ -13,7 +13,7 @@ PKG_SOURCE_URL:=http://www.denx.de/twiki/pub/Know/MiniFOHome/
 PKG_SOURCE:=mini_fo-0-6-2-pre1.tar.bz2
 PKG_CAT:=bzcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-mini-fo
 SECTION:=drivers
diff --git a/openwrt/package/mtd/Makefile b/openwrt/package/mtd/Makefile
index f6e94303af..01dfcd6b54 100644
--- a/openwrt/package/mtd/Makefile
+++ b/openwrt/package/mtd/Makefile
@@ -7,7 +7,7 @@ PKG_RELEASE:=4
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/mtd
 SECTION:=base
diff --git a/openwrt/package/nvram/Makefile b/openwrt/package/nvram/Makefile
index 019800a0c6..cf76c7c812 100644
--- a/openwrt/package/nvram/Makefile
+++ b/openwrt/package/nvram/Makefile
@@ -7,7 +7,7 @@ PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/nvram
 SECTION:=base
diff --git a/openwrt/package/openssl/Makefile b/openwrt/package/openssl/Makefile
index 82f20d6b0d..39fe6b4c3d 100644
--- a/openwrt/package/openssl/Makefile
+++ b/openwrt/package/openssl/Makefile
@@ -20,7 +20,7 @@ PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 OPENSSL_NO_CIPHERS:= no-idea no-md2 no-mdc2 no-rc5 no-sha0 no-rmd160 no-aes192
 OPENSSL_OPTIONS:= shared no-ec no-err no-fips no-hw no-krb5 no-threads zlib-dynamic no-engines
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/libopenssl
 SECTION:=base
diff --git a/openwrt/package/openswan/Makefile b/openwrt/package/openswan/Makefile
index 4a1a42cc07..f81096547b 100644
--- a/openwrt/package/openswan/Makefile
+++ b/openwrt/package/openswan/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=openswan
 PKG_VERSION:=2.4.5
@@ -13,7 +13,7 @@ PKG_SOURCE_URL:=http://www.openswan.org/download
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-openswan
 SECTION:=drivers
diff --git a/openwrt/package/pcmcia-cs/Makefile b/openwrt/package/pcmcia-cs/Makefile
index a389fd63e1..2c7b229781 100644
--- a/openwrt/package/pcmcia-cs/Makefile
+++ b/openwrt/package/pcmcia-cs/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/pcmcia-cs
 SECTION:=base
diff --git a/openwrt/package/ppp/Makefile b/openwrt/package/ppp/Makefile
index 55986f95c0..edd9a5ea86 100644
--- a/openwrt/package/ppp/Makefile
+++ b/openwrt/package/ppp/Makefile
@@ -15,7 +15,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/ppp
 SECTION:=net
diff --git a/openwrt/package/pptp/Makefile b/openwrt/package/pptp/Makefile
index 08cb43a7c2..6d01ce19f3 100644
--- a/openwrt/package/pptp/Makefile
+++ b/openwrt/package/pptp/Makefile
@@ -12,7 +12,7 @@ PKG_SOURCE_URL:=@SF/pptpclient
 PKG_MD5SUM:=9a706327fb9827541d7c86d48ceb9631
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/pptp
 SECTION:=base
diff --git a/openwrt/package/robocfg/Makefile b/openwrt/package/robocfg/Makefile
index 49f6005699..ca0f83d3dd 100644
--- a/openwrt/package/robocfg/Makefile
+++ b/openwrt/package/robocfg/Makefile
@@ -8,7 +8,7 @@ PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/robocfg
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/robocfg
 SECTION:=base
diff --git a/openwrt/package/shfs/Makefile b/openwrt/package/shfs/Makefile
index 69f8d83a46..057358b34d 100644
--- a/openwrt/package/shfs/Makefile
+++ b/openwrt/package/shfs/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=shfs
 PKG_VERSION:=0.35
@@ -15,7 +15,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-shfs
 SECTION:=drivers
diff --git a/openwrt/package/spca5xx/Makefile b/openwrt/package/spca5xx/Makefile
index 93eea633cd..86233fc64a 100644
--- a/openwrt/package/spca5xx/Makefile
+++ b/openwrt/package/spca5xx/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=spca5xx
 PKG_VERSION:=20060301
@@ -13,7 +13,7 @@ PKG_SOURCE_URL:=http://mxhaard.free.fr/spca50x/Download/
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 #FIXME: add proper dependency handling on kmod-usb-core & kmod-videodev packages
 define Package/kmod-spca5xx
diff --git a/openwrt/package/switch/Makefile b/openwrt/package/switch/Makefile
index e8aa6a02a4..cb5f346748 100644
--- a/openwrt/package/switch/Makefile
+++ b/openwrt/package/switch/Makefile
@@ -1,14 +1,14 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=kmod-switch
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-switch
 SECTION:=drivers
diff --git a/openwrt/package/udev/Makefile b/openwrt/package/udev/Makefile
index 54e06dcff6..5d397161b1 100644
--- a/openwrt/package/udev/Makefile
+++ b/openwrt/package/udev/Makefile
@@ -19,7 +19,7 @@ PKG_CAT:=bzcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/udev
 SECTION:=base
diff --git a/openwrt/package/ueagle-atm/Makefile b/openwrt/package/ueagle-atm/Makefile
index 6f227a1bf4..6d003f6c0d 100644
--- a/openwrt/package/ueagle-atm/Makefile
+++ b/openwrt/package/ueagle-atm/Makefile
@@ -1,7 +1,7 @@
 # $Id: Makefile 2767 2005-12-25 02:10:14Z wbx $
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=ueagle-atm
 PKG_VERSION:=1.0d1
@@ -15,7 +15,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 #FIXME: add dependency on kmod-usb-core
 define Package/kmod-ueagle-atm
diff --git a/openwrt/package/util-linux/Makefile b/openwrt/package/util-linux/Makefile
index ef28bdb69e..673ade433f 100644
--- a/openwrt/package/util-linux/Makefile
+++ b/openwrt/package/util-linux/Makefile
@@ -16,7 +16,7 @@ PKG_CAT:=zcat
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/fdisk
 SECTION:=base
diff --git a/openwrt/package/wireless-tools/Makefile b/openwrt/package/wireless-tools/Makefile
index ad4eddab8c..368d3ebb01 100644
--- a/openwrt/package/wireless-tools/Makefile
+++ b/openwrt/package/wireless-tools/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=zcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/wireless-tools
 SECTION:=base
diff --git a/openwrt/package/wlcompat/Makefile b/openwrt/package/wlcompat/Makefile
index af1f07593f..d5feede6c9 100644
--- a/openwrt/package/wlcompat/Makefile
+++ b/openwrt/package/wlcompat/Makefile
@@ -1,14 +1,14 @@
 # $Id$
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=kmod-wlcompat
 PKG_RELEASE:=3
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/kmod-wlcompat
 SECTION:=drivers
diff --git a/openwrt/package/zd1211/Makefile b/openwrt/package/zd1211/Makefile
index a71873b9f7..1c79922cfc 100644
--- a/openwrt/package/zd1211/Makefile
+++ b/openwrt/package/zd1211/Makefile
@@ -1,7 +1,7 @@
 # $Id: Makefile 3297 2006-03-02 23:42:52Z florian $
 
 include $(TOPDIR)/rules.mk
-include $(TOPDIR)/package/kernel.mk
+include $(TOPDIR)/include/kernel.mk
 
 PKG_NAME:=zd1211
 PKG_VERSION:=r69
@@ -13,7 +13,7 @@ PKG_SOURCE_URL:=http://zd1211.ath.cx/download/
 PKG_SOURCE:=$(PKG_NAME)-driver-$(PKG_VERSION).tgz
 PKG_CAT:=zcat
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 #FIXME: add proper dependency handling on kmod-usb-core packages
 define Package/kmod-zd1211
diff --git a/openwrt/package/zlib/Makefile b/openwrt/package/zlib/Makefile
index 02659bb9ac..8e497c2f28 100644
--- a/openwrt/package/zlib/Makefile
+++ b/openwrt/package/zlib/Makefile
@@ -14,7 +14,7 @@ PKG_CAT:=bzcat
 
 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
 
-include $(TOPDIR)/package/rules.mk
+include $(TOPDIR)/include/package.mk
 
 define Package/zlib
 SECTION:=base
diff --git a/openwrt/target/Makefile b/openwrt/target/Makefile
index d64053cbd4..9205f5b986 100644
--- a/openwrt/target/Makefile
+++ b/openwrt/target/Makefile
@@ -5,9 +5,9 @@ all: install
 $(BIN_DIR):
 	mkdir -p $(BIN_DIR)
 
-TARGETS:=linux utils lzma
+TARGETS:=linux utils
 
-linux-compile: utils-install lzma-install
+linux-compile: utils-install
 linux-install: $(BIN_DIR)
 
 download: $(patsubst %,%-source,$(TARGETS))
@@ -27,11 +27,6 @@ image_clean: FORCE
 	$(MAKE) -C $(patsubst %-prepare,%,$@) prepare
 %-compile: %-prepare
 	$(MAKE) -C $(patsubst %-compile,%,$@) compile
-%-rebuild: FORCE
-	$(MAKE) -C $(patsubst %-rebuild,%,$@) rebuild
 %-install: %-compile
 	$(MAKE) -C $(patsubst %-install,%,$@) install
-linux-imagebuilder: FORCE
-	$(MAKE) -C linux imagebuilder
-
 
diff --git a/openwrt/target/linux/Config.in b/openwrt/target/linux/Config.in
index 946ace3204..23c96b76df 100644
--- a/openwrt/target/linux/Config.in
+++ b/openwrt/target/linux/Config.in
@@ -13,8 +13,8 @@ menu "Target Root Filesystem"
 		help
 		  Build a jffs2 root filesystem
 
-	config TARGET_ROOTFS_SQUASHFS_LZMA
-		bool "squashfs-lzma"
+	config TARGET_ROOTFS_SQUASHFS
+		bool "squashfs"
 		default y
 		depends !LINUX_2_6_ARUBA
 		depends !LINUX_2_6_XSCALE
diff --git a/openwrt/target/linux/Makefile b/openwrt/target/linux/Makefile
index 2caee31b36..e1a314d1d8 100644
--- a/openwrt/target/linux/Makefile
+++ b/openwrt/target/linux/Makefile
@@ -30,6 +30,7 @@ source:
 	$(MAKE) -C image/$(BOARD) source
 
 prepare:
+	rm -f $(TOPDIR)/.kernel.mk
 	$(MAKE) -C $(BOARD)-$(KERNEL) prepare
 
 compile:
diff --git a/openwrt/target/linux/ar531x-2.4/Makefile b/openwrt/target/linux/ar531x-2.4/Makefile
index 3abb30d487..96a32848e7 100644
--- a/openwrt/target/linux/ar531x-2.4/Makefile
+++ b/openwrt/target/linux/ar531x-2.4/Makefile
@@ -4,10 +4,9 @@ LINUX_VERSION:=2.4.32
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=38f4d0830e95a20f4bfed17622d5557c
 
-include ../rules.mk
 include ./config
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/ar7-2.4/Makefile b/openwrt/target/linux/ar7-2.4/Makefile
index 20ad3523ac..c8688da044 100644
--- a/openwrt/target/linux/ar7-2.4/Makefile
+++ b/openwrt/target/linux/ar7-2.4/Makefile
@@ -4,8 +4,8 @@ LINUX_VERSION:=2.4.32
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=38f4d0830e95a20f4bfed17622d5557c
 
-include ../rules.mk
 include ./config
+include $(TOPDIR)/include/kernel.mk
 
 ATM_FIRMWARE_VERSION:=0.4
 ATM_FIRMWARE_DIR=sangam-atm-firmware-$(ATM_FIRMWARE_VERSION)
@@ -26,8 +26,7 @@ $(eval $(call KMOD_template,CPMAC,cpmac,\
 	$(MODULES_DIR)/kernel/drivers/net/avalanche_cpmac/avalanche_cpmac.o \
 ,CONFIG_MIPS_AVALANCHE_CPMAC,,10,avalanche_cpmac))
 
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
diff --git a/openwrt/target/linux/aruba-2.6/Makefile b/openwrt/target/linux/aruba-2.6/Makefile
index 1f68614254..652e4b9132 100644
--- a/openwrt/target/linux/aruba-2.6/Makefile
+++ b/openwrt/target/linux/aruba-2.6/Makefile
@@ -4,12 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches $(MAKE_TRACE)
diff --git a/openwrt/target/linux/au1000-2.6/Makefile b/openwrt/target/linux/au1000-2.6/Makefile
index 39d8d4c8b0..b1ca0fee34 100644
--- a/openwrt/target/linux/au1000-2.6/Makefile
+++ b/openwrt/target/linux/au1000-2.6/Makefile
@@ -4,12 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/brcm-2.4/Makefile b/openwrt/target/linux/brcm-2.4/Makefile
index 022f3352c5..20a6210666 100644
--- a/openwrt/target/linux/brcm-2.4/Makefile
+++ b/openwrt/target/linux/brcm-2.4/Makefile
@@ -4,8 +4,8 @@ LINUX_VERSION:=2.4.32
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=38f4d0830e95a20f4bfed17622d5557c
 
-include ../rules.mk
 include ./config
+include $(TOPDIR)/include/kernel.mk
 
 # broadcom specific kmod packages
 $(eval $(call KMOD_template,LP,lp,\
@@ -15,8 +15,7 @@ $(eval $(call KMOD_template,LP,lp,\
 	$(MODULES_DIR)/kernel/drivers/char/ppdev.o \
 ,CONFIG_PARPORT,,50,parport parport_splink lp))
 
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
diff --git a/openwrt/target/linux/brcm-2.6/Makefile b/openwrt/target/linux/brcm-2.6/Makefile
index 1f68614254..a3b8177c20 100644
--- a/openwrt/target/linux/brcm-2.6/Makefile
+++ b/openwrt/target/linux/brcm-2.6/Makefile
@@ -4,11 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
diff --git a/openwrt/target/linux/image/ar7/Makefile b/openwrt/target/linux/image/ar7/Makefile
index 4ac6d3015f..4b22f90df2 100644
--- a/openwrt/target/linux/image/ar7/Makefile
+++ b/openwrt/target/linux/image/ar7/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/ar7loader
 
diff --git a/openwrt/target/linux/image/aruba/Makefile b/openwrt/target/linux/image/aruba/Makefile
index c8dab056a0..5091d3f40c 100644
--- a/openwrt/target/linux/image/aruba/Makefile
+++ b/openwrt/target/linux/image/aruba/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 LOADADDR = 0x81000000		# RAM start + 16M 
 KERNEL_ENTRY = 0x80100000
diff --git a/openwrt/target/linux/image/au1000/Makefile b/openwrt/target/linux/image/au1000/Makefile
index 2607ed9eb3..682670a22c 100644
--- a/openwrt/target/linux/image/au1000/Makefile
+++ b/openwrt/target/linux/image/au1000/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 LOADADDR = 0x8108c8f4		# RAM start + 16M 
 KERNEL_ENTRY = 0x80100000	# Default kernel entry in arch/mips/Makefile
diff --git a/openwrt/target/linux/image/brcm/Makefile b/openwrt/target/linux/image/brcm/Makefile
index df2a42ea5c..d219dc354b 100644
--- a/openwrt/target/linux/image/brcm/Makefile
+++ b/openwrt/target/linux/image/brcm/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 define Build/Compile
 	rm -f $(KDIR)/loader.gz
diff --git a/openwrt/target/linux/image/generic/Makefile b/openwrt/target/linux/image/generic/Makefile
index f87fb116dd..b9efc95b9b 100644
--- a/openwrt/target/linux/image/generic/Makefile
+++ b/openwrt/target/linux/image/generic/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 # use default targets for everything
 
diff --git a/openwrt/target/linux/image/image.mk b/openwrt/target/linux/image/image.mk
deleted file mode 100644
index 92143d64e8..0000000000
--- a/openwrt/target/linux/image/image.mk
+++ /dev/null
@@ -1,55 +0,0 @@
-include $(TOPDIR)/rules.mk
-
-KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
-
-ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
-ifeq ($(CONFIG_TARGET_ROOTFS_JFFS2),y)
-include $(TOPDIR)/target/linux/image/jffs2.mk
-endif
-
-ifeq ($(CONFIG_TARGET_ROOTFS_SQUASHFS_LZMA),y)
-include $(TOPDIR)/target/linux/image/squashfs.mk
-endif
-
-ifeq ($(CONFIG_TARGET_ROOTFS_TGZ),y)
-include $(TOPDIR)/target/linux/image/tgz.mk
-endif
-endif
-
-define Image/mkfs/prepare/default
-	find $(BUILD_DIR)/root -type f -not -perm +0100 | xargs chmod 0644
-	find $(BUILD_DIR)/root -type f -perm +0100 | xargs chmod 0755
-	find $(BUILD_DIR)/root -type d | xargs chmod 0755
-	mkdir -p $(BUILD_DIR)/root/tmp
-	chmod 0777 $(BUILD_DIR)/root/tmp
-endef
-
-define Image/mkfs/prepare
-	$(call Image/mkfs/prepare/default)
-endef
-
-define BuildImage
-compile:
-	$(call Build/Compile)
-
-install:
-	$(call Image/Prepare)
-	$(call Image/mkfs/prepare)
-	$(call Image/BuildKernel)
-	$(call Image/mkfs/jffs2)
-	$(call Image/mkfs/squashfs)
-	$(call Image/mkfs/tgz)
-	
-clean:
-	$(call Build/Clean)
-endef
-
-compile-targets:
-install-targets:
-clean-targets:
-
-source:
-prepare:
-compile: compile-targets
-install: compile install-targets
-clean: clean-targets
diff --git a/openwrt/target/linux/image/jffs2.mk b/openwrt/target/linux/image/jffs2.mk
deleted file mode 100644
index a0e14daa90..0000000000
--- a/openwrt/target/linux/image/jffs2.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-ifneq ($(CONFIG_BIG_ENDIAN),y)
-JFFS2OPTS :=  --pad --little-endian --squash
-else
-JFFS2OPTS :=  --pad --big-endian --squash
-endif
-
-define Image/mkfs/jffs2
-	rm -rf $(BUILD_DIR)/root/jffs
-	
-	$(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x10000 -o $(KDIR)/root.jffs2-64k -d $(BUILD_DIR)/root
-	$(STAGING_DIR)/bin/mkfs.jffs2 $(JFFS2OPTS) -e 0x20000 -o $(KDIR)/root.jffs2-128k -d $(BUILD_DIR)/root
-
-	$(call Image/Build,jffs2-64k)
-	$(call Image/Build,jffs2-128k)
-endef
-
-jffs2-source: FORCE
-	$(MAKE) -C $(TOPDIR)/target/linux/image/jffs2 source
-
-$(STAGING_DIR)/bin/mkfs.jffs2:
-	$(MAKE) -C $(TOPDIR)/target/linux/image/jffs2 compile
-
-jffs2-clean: FORCE
-	$(MAKE) -C $(TOPDIR)/target/linux/image/jffs2 clean
-	rm -f $(KDIR)/root.jffs2*
-
-source: jffs2-source
-compile-targets: $(STAGING_DIR)/bin/mkfs.jffs2
-clean-targets: jffs2-clean
-
diff --git a/openwrt/target/linux/image/rb532/Makefile b/openwrt/target/linux/image/rb532/Makefile
index ed419c8c6d..53adfc432f 100644
--- a/openwrt/target/linux/image/rb532/Makefile
+++ b/openwrt/target/linux/image/rb532/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 LOADADDR = 0x81000000		# RAM start + 16M 
 KERNEL_ENTRY = 0x80101000
diff --git a/openwrt/target/linux/image/squashfs.mk b/openwrt/target/linux/image/squashfs.mk
deleted file mode 100644
index e01766c0ca..0000000000
--- a/openwrt/target/linux/image/squashfs.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-ifneq ($(CONFIG_BIG_ENDIAN),y)
-ENDIAN := le
-else
-ENDIAN := be
-endif
-
-squashfs-source: FORCE
-	$(MAKE) -C $(TOPDIR)/target/linux/image/squashfs source
-
-$(STAGING_DIR)/bin/mksquashfs-lzma:
-	$(MAKE) -C $(TOPDIR)/target/linux/image/squashfs compile
-	
-squashfs-clean: FORCE
-	$(MAKE) -C $(TOPDIR)/target/linux/image/squashfs clean
-	rm -f $(KDIR)/root.squashfs
-
-define Image/mkfs/squashfs
-	@mkdir -p $(BUILD_DIR)/root/jffs
-	$(STAGING_DIR)/bin/mksquashfs-lzma $(BUILD_DIR)/root $(KDIR)/root.squashfs -nopad -noappend -root-owned -$(ENDIAN)
-	$(call Image/Build,squashfs)
-endef
-
-FILESYSTEMS += squashfs
-compile-targets: $(STAGING_DIR)/bin/mksquashfs-lzma
-clean-targets: squashfs-clean
diff --git a/openwrt/target/linux/image/tgz.mk b/openwrt/target/linux/image/tgz.mk
deleted file mode 100644
index 39adb69257..0000000000
--- a/openwrt/target/linux/image/tgz.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-define Image/mkfs/tgz
-	tar -zcf $(BIN_DIR)/openwrt-rootfs.tgz --owner=root --group=root -C $(BUILD_DIR)/root/ .
-endef
diff --git a/openwrt/target/linux/image/x86/Makefile b/openwrt/target/linux/image/x86/Makefile
index 69f9bf470e..d76294f150 100644
--- a/openwrt/target/linux/image/x86/Makefile
+++ b/openwrt/target/linux/image/x86/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 define Image/Build
 	cp $(KDIR)/root.$(1) $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(1).img
diff --git a/openwrt/target/linux/image/xscale/Makefile b/openwrt/target/linux/image/xscale/Makefile
index 09616d409f..d94d7f07ca 100644
--- a/openwrt/target/linux/image/xscale/Makefile
+++ b/openwrt/target/linux/image/xscale/Makefile
@@ -1,4 +1,4 @@
-include ../image.mk
+include $(TOPDIR)/include/image.mk
 
 define Image/Build
 ifneq ($(FS),jffs2-64k)
diff --git a/openwrt/target/linux/rb532-2.6/Makefile b/openwrt/target/linux/rb532-2.6/Makefile
index 9bb7bba71c..4b0901987f 100644
--- a/openwrt/target/linux/rb532-2.6/Makefile
+++ b/openwrt/target/linux/rb532-2.6/Makefile
@@ -4,11 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/sibyte-2.6/Makefile b/openwrt/target/linux/sibyte-2.6/Makefile
index 210c195adf..4b0901987f 100644
--- a/openwrt/target/linux/sibyte-2.6/Makefile
+++ b/openwrt/target/linux/sibyte-2.6/Makefile
@@ -4,12 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/x86-2.4/Makefile b/openwrt/target/linux/x86-2.4/Makefile
index bcc8bd05d2..a6208dbbbb 100644
--- a/openwrt/target/linux/x86-2.4/Makefile
+++ b/openwrt/target/linux/x86-2.4/Makefile
@@ -4,17 +4,14 @@ LINUX_VERSION:=2.4.32
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=38f4d0830e95a20f4bfed17622d5557c
 
-include ../rules.mk
 include ./config
+include $(TOPDIR)/include/kernel.mk
 
 $(eval $(call KMOD_template,WD1100,wd1100,\
 	$(MODULES_DIR)/kernel/drivers/char/wd1100.o \
 ,CONFIG_WD1100))
 
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/x86-2.6/Makefile b/openwrt/target/linux/x86-2.6/Makefile
index 7b2f1b068d..ab88d58dfb 100644
--- a/openwrt/target/linux/x86-2.6/Makefile
+++ b/openwrt/target/linux/x86-2.6/Makefile
@@ -4,12 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/target/linux/xscale-2.6/Makefile b/openwrt/target/linux/xscale-2.6/Makefile
index 608a49408b..a4d93efc5f 100644
--- a/openwrt/target/linux/xscale-2.6/Makefile
+++ b/openwrt/target/linux/xscale-2.6/Makefile
@@ -4,12 +4,9 @@ LINUX_VERSION:=2.6.17
 LINUX_RELEASE:=1
 LINUX_KERNEL_MD5SUM:=37ddefe96625502161f075b9d907f21e
 
-include ../rules.mk
 include ./config
-
-include ../generic-$(KERNEL)/modules.mk
-include ../kernel.mk
-
+include $(TOPDIR)/include/kernel.mk
+include $(TOPDIR)/include/kernel-build.mk
 
 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
 	[ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
diff --git a/openwrt/toolchain/Makefile b/openwrt/toolchain/Makefile
index fac0468285..f9fb3a54d6 100644
--- a/openwrt/toolchain/Makefile
+++ b/openwrt/toolchain/Makefile
@@ -1,6 +1,6 @@
 # Main makefile for the toolchain
 include $(TOPDIR)/rules.mk
-TARGETS-y:=sed kernel-headers utils binutils gcc uClibc ipkg-utils libnotimpl
+TARGETS-y:=sed kernel-headers utils binutils gcc uClibc ipkg-utils libnotimpl squashfs jffs2 lzma
 TARGETS-$(CONFIG_GDB) += gdb
 
 TARGETS_DOWNLOAD:=$(patsubst %,%-source,$(TARGETS-y))
@@ -17,6 +17,7 @@ binutils-prepare: uClibc-prepare
 gcc-prepare: binutils-install
 uClibc-compile: gcc-prepare
 gcc-compile: uClibc-install
+squashfs-compile: lzma-compile
 
 TOOLCHAIN_STAMP_DIR:=$(STAGING_DIR)/stampfiles
 
diff --git a/openwrt/target/linux/image/jffs2/Makefile b/openwrt/toolchain/jffs2/Makefile
similarity index 100%
rename from openwrt/target/linux/image/jffs2/Makefile
rename to openwrt/toolchain/jffs2/Makefile
diff --git a/openwrt/target/linux/image/jffs2/patches/gcc4-fix.patch b/openwrt/toolchain/jffs2/patches/100-gcc4_fix.patch
similarity index 100%
rename from openwrt/target/linux/image/jffs2/patches/gcc4-fix.patch
rename to openwrt/toolchain/jffs2/patches/100-gcc4_fix.patch
diff --git a/openwrt/target/lzma/Makefile b/openwrt/toolchain/lzma/Makefile
similarity index 96%
rename from openwrt/target/lzma/Makefile
rename to openwrt/toolchain/lzma/Makefile
index 214967a15d..cace2a4e2b 100644
--- a/openwrt/target/lzma/Makefile
+++ b/openwrt/toolchain/lzma/Makefile
@@ -22,7 +22,7 @@ $(DL_DIR)/$(LZMA_SOURCE):
 $(LZMA_DIR)/.unpacked: $(DL_DIR)/$(LZMA_SOURCE) 
 	@rm -rf $(LZMA_DIR) && mkdir -p $(LZMA_DIR)
 	tar xjf $^ -C $(LZMA_DIR)
-	patch -d $(LZMA_DIR) -p1 < lzma-zlib.patch
+	$(PATCH) $(LZMA_DIR) ./patches
 	touch $(LZMA_DIR)/.unpacked
 	
 $(LZMA_ALONE_DIR)/lzma $(LZMA_LIB_DIR)/liblzma.a: $(LZMA_DIR)/.built
diff --git a/openwrt/target/lzma/lzma-zlib.patch b/openwrt/toolchain/lzma/patches/100-lzma_zlib.patch
similarity index 100%
rename from openwrt/target/lzma/lzma-zlib.patch
rename to openwrt/toolchain/lzma/patches/100-lzma_zlib.patch
diff --git a/openwrt/target/linux/image/squashfs/Makefile b/openwrt/toolchain/squashfs/Makefile
similarity index 100%
rename from openwrt/target/linux/image/squashfs/Makefile
rename to openwrt/toolchain/squashfs/Makefile
diff --git a/openwrt/target/linux/image/squashfs/patches/100-lzma.patch b/openwrt/toolchain/squashfs/patches/100-lzma.patch
similarity index 100%
rename from openwrt/target/linux/image/squashfs/patches/100-lzma.patch
rename to openwrt/toolchain/squashfs/patches/100-lzma.patch
-- 
GitLab