8750bb4fd52487b98dfb6d24cabb7ddbc749cf7a
[openwrt.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)/kernel-version.mk
10 include $(INCLUDE_DIR)/host.mk
11 include $(INCLUDE_DIR)/kernel.mk
12 include $(INCLUDE_DIR)/prereq.mk
13
14 override MAKEFLAGS=
15
16 GENERIC_LINUX_CONFIG:=$(GENERIC_PLATFORM_DIR)/config-$(shell [ -f "$(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER)" ] && echo "$(KERNEL_PATCHVER)" || echo template )
17 LINUX_CONFIG_DIR ?= ./config$(shell [ -d "./config-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
18 LINUX_CONFIG ?= $(LINUX_CONFIG_DIR)/default
19
20 ifneq ($(DUMP),)
21 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(BOARD)-$(KERNEL)
22 $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG)
23 $(SCRIPT_DIR)/config.pl + $^ > $@
24 -include $(TMP_CONFIG)
25 .SILENT: $(TMP_CONFIG)
26 endif
27
28 ifneq ($(CONFIG_PCI),)
29 FEATURES += pci
30 endif
31 ifneq ($(CONFIG_USB),)
32 FEATURES += usb
33 endif
34 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
35 FEATURES += pcmcia
36 endif
37
38 # remove duplicates
39 FEATURES:=$(sort $(FEATURES))
40
41 ifeq ($(DUMP),1)
42 all: dumpinfo
43 else
44 all: compile
45 endif
46
47 ifneq (,$(findstring uml,$(BOARD)))
48 LINUX_KARCH:=um
49 else
50 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
51 -e 's/mipsel/mips/' \
52 -e 's/mipseb/mips/' \
53 -e 's/powerpc/ppc/' \
54 -e 's/sh[234]/sh/' \
55 -e 's/armeb/arm/' \
56 )
57 endif
58
59 STAMP_PREPARED:=$(LINUX_DIR)/.prepared
60 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
61 include $(INCLUDE_DIR)/quilt.mk
62 include $(INCLUDE_DIR)/kernel-defaults.mk
63
64 define Kernel/Prepare
65 $(call Kernel/Prepare/Default)
66 endef
67
68 define Kernel/Configure
69 $(call Kernel/Configure/Default)
70 endef
71
72 define Kernel/CompileModules
73 $(call Kernel/CompileModules/Default)
74 endef
75
76 define Kernel/CompileImage
77 $(call Kernel/CompileImage/Default)
78 endef
79
80 define Kernel/Clean
81 $(call Kernel/Clean/Default)
82 endef
83
84 define BuildKernel
85 ifneq ($(LINUX_SITE),)
86 $(DL_DIR)/$(LINUX_SOURCE):
87 -mkdir -p $(DL_DIR)
88 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
89 endif
90
91 $(STAMP_PREPARED): $(DL_DIR)/$(LINUX_SOURCE)
92 -rm -rf $(KERNEL_BUILD_DIR)
93 -mkdir -p $(KERNEL_BUILD_DIR)
94 $(call Kernel/Prepare)
95 touch $$@
96
97 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_CONFIG) $(GENERIC_LINUX_CONFIG) $(TOPDIR)/.config
98 $(call Kernel/Configure)
99 touch $$@
100
101 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
102 $(call Kernel/CompileModules)
103 touch $$@
104
105 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) FORCE
106 $(call Kernel/CompileImage)
107 touch $$@
108
109 mostlyclean: FORCE
110 $(call Kernel/Clean)
111
112 ifeq ($(DUMP),1)
113 dumpinfo:
114 @echo 'Target: $(BOARD)-$(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
This page took 0.050099 seconds and 3 git commands to generate.