image.mk: fix evaluation order for image profile check
[openwrt/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 include $(INCLUDE_DIR)/host.mk
8 include $(INCLUDE_DIR)/prereq.mk
9
10 ifneq ($(DUMP),1)
11 all: compile
12 endif
13
14 export QUILT=1
15 STAMP_PREPARED:=$(LINUX_DIR)/.prepared
16 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
17 include $(INCLUDE_DIR)/download.mk
18 include $(INCLUDE_DIR)/quilt.mk
19 include $(INCLUDE_DIR)/kernel-defaults.mk
20
21 define Kernel/Prepare
22 $(call Kernel/Prepare/Default)
23 endef
24
25 define Kernel/Configure
26 $(call Kernel/Configure/Default)
27 endef
28
29 define Kernel/CompileModules
30 $(call Kernel/CompileModules/Default)
31 endef
32
33 define Kernel/CompileImage
34 $(call Kernel/CompileImage/Default)
35 $(call Kernel/CompileImage/Initramfs)
36 endef
37
38 define Kernel/Clean
39 $(call Kernel/Clean/Default)
40 endef
41
42 define Download/kernel
43 URL:=$(LINUX_SITE)
44 FILE:=$(LINUX_SOURCE)
45 MD5SUM:=$(LINUX_KERNEL_MD5SUM)
46 endef
47
48 ifdef CONFIG_COLLECT_KERNEL_DEBUG
49 define Kernel/CollectDebug
50 rm -rf $(KERNEL_BUILD_DIR)/debug
51 mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
52 $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
53 -$(CP) \
54 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
55 $(KERNEL_BUILD_DIR)/debug/modules/
56 $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
57 $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
58 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
59 | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
60 endef
61 endif
62
63 define BuildKernel
64 $(if $(QUILT),$(Build/Quilt))
65 $(if $(LINUX_SITE),$(call Download,kernel))
66
67 .NOTPARALLEL:
68
69 $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
70 -rm -rf $(KERNEL_BUILD_DIR)
71 -mkdir -p $(KERNEL_BUILD_DIR)
72 $(Kernel/Prepare)
73 touch $$@
74
75 $(KERNEL_BUILD_DIR)/symtab.h: FORCE
76 rm -f $(KERNEL_BUILD_DIR)/symtab.h
77 touch $(KERNEL_BUILD_DIR)/symtab.h
78 +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
79 find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
80 xargs $(TARGET_CROSS)nm | \
81 awk '$$$$1 == "U" { print $$$$2 } ' | \
82 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
83 $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
84 grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
85 grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
86 ( \
87 echo '#define SYMTAB_KEEP \'; \
88 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
89 awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
90 echo; \
91 echo '#define SYMTAB_KEEP_GPL \'; \
92 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
93 awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
94 echo; \
95 echo '#define SYMTAB_DISCARD \'; \
96 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
97 awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
98 echo; \
99 echo '#define SYMTAB_DISCARD_GPL \'; \
100 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
101 awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
102 echo; \
103 ) > $$@
104
105 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config
106 $(Kernel/Configure)
107 touch $$@
108
109 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
110 $(Kernel/CompileModules)
111 touch $$@
112
113 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
114 $(Kernel/CompileImage)
115 $(Kernel/CollectDebug)
116 touch $$@
117
118 mostlyclean: FORCE
119 $(Kernel/Clean)
120
121 define BuildKernel
122 endef
123
124 download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
125 prepare: $(STAMP_CONFIGURED)
126 compile: $(LINUX_DIR)/.modules
127 $(MAKE) -C image compile TARGET_BUILD=
128
129 oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
130 rm -f $(LINUX_DIR)/.config.prev
131 rm -f $(STAMP_CONFIGURED)
132 $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
133 $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $$@
134 $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
135
136 install: $(LINUX_DIR)/.image
137 +$(MAKE) -C image compile install TARGET_BUILD=
138
139 clean: FORCE
140 rm -rf $(KERNEL_BUILD_DIR)
141
142 image-prereq:
143 @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
144
145 prereq: image-prereq
146
147 endef