2 # Copyright (C) 2006 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
9 include $(INCLUDE_DIR)/prereq.mk
12 ifneq ($(CONFIG_ATM),)
15 ifneq ($(CONFIG_PCI),)
18 ifneq ($(CONFIG_USB),)
21 ifneq ($(CONFIG_PCMCIA),)
26 FEATURES:=$(sort $(FEATURES))
28 # For target profile selection - the default set
29 DEFAULT_PACKAGES:=base-files libgcc uclibc bridge busybox dnsmasq dropbear iptables mtd ppp ppp-mod-pppoe mtd
36 KERNEL:=2.$(word 2,$(subst ., ,$(strip $(LINUX_VERSION))))
38 include $(INCLUDE_DIR)/host.mk
39 include $(INCLUDE_DIR)/kernel.mk
41 LINUX_CONFIG:=./config
43 ifneq (,$(findstring uml,$(BOARD)))
46 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
56 ifneq (,$(findstring x86,$(BOARD)))
59 ifneq (,$(findstring ppc,$(BOARD)))
64 define Kernel/Prepare/Default
65 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
66 [ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
67 [ -d ./patches ] && $(PATCH) $(LINUX_DIR) ./patches
70 $(call Kernel/Prepare/Default)
74 define Kernel/Configure/2.4
75 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
76 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
77 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
79 define Kernel/Configure/2.6
80 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
82 define Kernel/Configure/Default
83 @$(CP) $(LINUX_CONFIG) $(LINUX_DIR)/.config
84 $(call Kernel/Configure/$(KERNEL))
86 define Kernel/Configure
87 $(call Kernel/Configure/Default)
91 define Kernel/CompileModules/Default
92 $(MAKE) -j$(CONFIG_JLEVEL) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
93 $(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
95 define Kernel/CompileModules
96 $(call Kernel/CompileModules/Default)
101 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
102 define Kernel/SetInitramfs
103 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
104 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
105 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
106 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
107 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
108 mkdir -p $(BUILD_DIR)/root/etc/init.d
109 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
112 define Kernel/SetInitramfs
113 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
114 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
115 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
116 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
120 define Kernel/CompileImage/Default
121 $(call Kernel/SetInitramfs)
122 $(MAKE) -j$(CONFIG_JLEVEL) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
123 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
125 define Kernel/CompileImage
126 $(call Kernel/CompileImage/Default)
129 define Kernel/Clean/Default
130 rm -f $(LINUX_DIR)/.linux-compile
131 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
132 rm -f $(LINUX_KERNEL)
133 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
137 $(call Kernel/Clean/Default)
141 ifneq ($(LINUX_SITE),)
142 $(DL_DIR)/$(LINUX_SOURCE):
144 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
147 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
148 -rm -rf $(KERNEL_BUILD_DIR)
149 -mkdir -p $(KERNEL_BUILD_DIR)
150 $(call Kernel/Prepare)
153 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
154 $(call Kernel/Configure)
157 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
158 rm -rf $(KERNEL_BUILD_DIR)/modules
159 @rm -f $(BUILD_DIR)/linux
160 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
161 $(call Kernel/CompileModules)
164 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
165 $(call Kernel/CompileImage)
173 @echo 'Target: $(BOARD)-$(KERNEL)'
174 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
175 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
176 @echo 'Target-Arch: $(ARCH)'
177 @echo 'Target-Features: $(FEATURES)'
178 @echo 'Linux-Version: $(LINUX_VERSION)'
179 @echo 'Linux-Release: $(LINUX_RELEASE)'
180 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
181 @echo 'Target-Description:'
182 @getvar $(call shvar,Target/Description)
184 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
194 define Profile/Default
200 $(eval $(call Profile/Default))
201 $(eval $(call Profile/$(1)))
203 echo "Target-Profile: $(1)"; \
204 echo "Target-Profile-Name: $(NAME)"; \
205 echo "Target-Profile-Packages: $(PACKAGES)";
208 $(eval $(call shexport,Target/Description))
210 download: $(DL_DIR)/$(LINUX_SOURCE)
211 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
212 compile: $(LINUX_DIR)/.modules
213 install: $(LINUX_DIR)/.image
216 rm -f $(STAMP_DIR)/.linux-compile
217 rm -rf $(KERNEL_BUILD_DIR)
221 @if [ -f $(LINUX_KERNEL) ]; then \