strip the kernel version suffix from target directories, except for brcm-2.4 (the...
[openwrt/svn-archive/archive.git] / include / kernel-build.mk
1 #
2 # Copyright (C) 2006-2007 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 KERNEL_BUILD:=1
8
9 include $(INCLUDE_DIR)/host.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/prereq.mk
12
13 override MAKEFLAGS=
14
15 GENERIC_LINUX_CONFIG:=$(GENERIC_PLATFORM_DIR)/config-$(shell [ -f "$(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER)" ] && echo "$(KERNEL_PATCHVER)" || echo template )
16 LINUX_CONFIG_DIR ?= ./config$(shell [ -d "./config-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
17 LINUX_CONFIG ?= $(LINUX_CONFIG_DIR)/default
18
19 ifneq ($(DUMP),)
20 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(BOARD)-$(KERNEL)
21 $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG)
22 $(SCRIPT_DIR)/config.pl + $^ > $@
23 -include $(TMP_CONFIG)
24 .SILENT: $(TMP_CONFIG)
25 endif
26
27 ifneq ($(CONFIG_PCI),)
28 FEATURES += pci
29 endif
30 ifneq ($(CONFIG_USB),)
31 FEATURES += usb
32 endif
33 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
34 FEATURES += pcmcia
35 endif
36
37 # remove duplicates
38 FEATURES:=$(sort $(FEATURES))
39
40 ifeq ($(DUMP),1)
41 all: dumpinfo
42 else
43 all: compile
44 endif
45
46 ifneq (,$(findstring uml,$(BOARD)))
47 LINUX_KARCH:=um
48 else
49 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
50 -e 's/mipsel/mips/' \
51 -e 's/mipseb/mips/' \
52 -e 's/powerpc/ppc/' \
53 -e 's/sh[234]/sh/' \
54 -e 's/armeb/arm/' \
55 )
56 endif
57
58 STAMP_PREPARED:=$(LINUX_DIR)/.prepared
59 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
60 include $(INCLUDE_DIR)/quilt.mk
61 include $(INCLUDE_DIR)/kernel-defaults.mk
62
63 define Kernel/Prepare
64 $(call Kernel/Prepare/Default)
65 endef
66
67 define Kernel/Configure
68 $(call Kernel/Configure/Default)
69 endef
70
71 define Kernel/CompileModules
72 $(call Kernel/CompileModules/Default)
73 endef
74
75 define Kernel/CompileImage
76 $(call Kernel/CompileImage/Default)
77 endef
78
79 define Kernel/Clean
80 $(call Kernel/Clean/Default)
81 endef
82
83 define BuildKernel
84 ifneq ($(LINUX_SITE),)
85 $(DL_DIR)/$(LINUX_SOURCE):
86 -mkdir -p $(DL_DIR)
87 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
88 endif
89
90 $(STAMP_PREPARED): $(DL_DIR)/$(LINUX_SOURCE)
91 -rm -rf $(KERNEL_BUILD_DIR)
92 -mkdir -p $(KERNEL_BUILD_DIR)
93 $(call Kernel/Prepare)
94 touch $$@
95
96 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_CONFIG) $(GENERIC_LINUX_CONFIG) $(TOPDIR)/.config
97 $(call Kernel/Configure)
98 touch $$@
99
100 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
101 $(call Kernel/CompileModules)
102 touch $$@
103
104 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) FORCE
105 $(call Kernel/CompileImage)
106 touch $$@
107
108 mostlyclean: FORCE
109 $(call Kernel/Clean)
110
111 ifeq ($(DUMP),1)
112 dumpinfo:
113 @echo 'Target: $(BOARD)'
114 @echo 'Target-Kernel: $(KERNEL)'
115 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
116 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
117 @echo 'Target-Arch: $(ARCH)'
118 @echo 'Target-Features: $(FEATURES)'
119 @echo 'Linux-Version: $(LINUX_VERSION)'
120 @echo 'Linux-Release: $(LINUX_RELEASE)'
121 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
122 @echo 'Target-Description:'
123 @getvar $(call shvar,Target/Description)
124 @echo '@@'
125 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
126 ifneq ($(DUMPINFO),)
127 @$(DUMPINFO)
128 endif
129 endif
130
131 define BuildKernel
132 endef
133 endef
134
135 define Profile/Default
136 NAME:=
137 PACKAGES:=
138 endef
139
140 confname=$(subst .,_,$(subst -,_,$(1)))
141 define Profile
142 $(eval $(call Profile/Default))
143 $(eval $(call Profile/$(1)))
144 $(eval $(call shexport,Profile/$(1)/Config))
145 $(eval $(call shexport,Profile/$(1)/Description))
146 DUMPINFO += \
147 echo "Target-Profile: $(1)"; \
148 echo "Target-Profile-Name: $(NAME)"; \
149 echo "Target-Profile-Packages: $(PACKAGES)"; \
150 if [ -f ./config/profile-$(1) ]; then \
151 echo "Target-Profile-Kconfig: yes"; \
152 fi; \
153 echo "Target-Profile-Config: "; \
154 getvar "$(call shvar,Profile/$(1)/Config)"; \
155 echo "@@"; \
156 echo "Target-Profile-Description:"; \
157 getvar "$(call shvar,Profile/$(1)/Description)"; \
158 echo "@@"; \
159 echo;
160 ifeq ($(CONFIG_LINUX_$(call confname,$(KERNEL)_$(1))),y)
161 PROFILE=$(1)
162 endif
163 endef
164
165 $(eval $(call shexport,Target/Description))
166
167 download: $(DL_DIR)/$(LINUX_SOURCE)
168 prepare: $(STAMP_CONFIGURED)
169 compile: $(LINUX_DIR)/.modules
170 $(MAKE) -C image compile
171
172 oldconfig menuconfig: $(STAMP_PREPARED) FORCE
173 $(call Kernel/Configure)
174 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) > $(LINUX_DIR)/.config
175 $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $@
176 $(SCRIPT_DIR)/config.pl '>' $(GENERIC_LINUX_CONFIG) $(LINUX_DIR)/.config > $(LINUX_CONFIG)
177
178 install: $(LINUX_DIR)/.image
179 $(MAKE) -C image compile install
180
181 clean: FORCE
182 rm -f $(STAMP_DIR)/.linux-compile
183 rm -rf $(KERNEL_BUILD_DIR)
184
185 rebuild: FORCE
186 @$(MAKE) mostlyclean
187 @if [ -f $(LINUX_KERNEL) ]; then \
188 $(MAKE) clean; \
189 fi
190 @$(MAKE) compile
191
192 image-prereq:
193 $(SUBMAKE) -s -C image prereq
194
195 prereq: image-prereq