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