ar71xx: merge machine patches
[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 endef
36
37 define Kernel/Clean
38         $(call Kernel/Clean/Default)
39 endef
40
41 define Download/kernel
42   URL:=$(LINUX_SITE)
43   FILE:=$(LINUX_SOURCE)
44   MD5SUM:=$(LINUX_KERNEL_MD5SUM)
45 endef
46
47 ifdef CONFIG_COLLECT_KERNEL_DEBUG
48   define Kernel/CollectDebug
49         rm -rf $(KERNEL_BUILD_DIR)/debug
50         mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
51         $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
52         -$(CP) \
53                 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
54                 $(KERNEL_BUILD_DIR)/debug/modules/
55         $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
56         $(TAR) c -C $(KERNEL_BUILD_DIR) debug | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
57   endef
58 endif
59
60 define BuildKernel
61   $(if $(QUILT),$(Build/Quilt))
62   $(if $(LINUX_SITE),$(call Download,kernel))
63
64   $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
65         -rm -rf $(KERNEL_BUILD_DIR)
66         -mkdir -p $(KERNEL_BUILD_DIR)
67         $(Kernel/Prepare)
68         touch $$@
69
70   $(KERNEL_BUILD_DIR)/symtab.h: FORCE
71         rm -f $(KERNEL_BUILD_DIR)/symtab.h
72         touch $(KERNEL_BUILD_DIR)/symtab.h
73         +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
74         find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
75                 xargs $(TARGET_CROSS)nm | \
76                 awk '$$$$1 == "U" { print $$$$2 } ' | \
77                 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
78         $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' r __ksymtab' | sed -e 's,........ r __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
79         grep -f $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
80         grep -vf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
81         ( \
82                 echo '#define SYMTAB_KEEP \'; \
83                 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
84                         awk '{print "*(__ksymtab." $$$$1 ") \\" }'; \
85                 echo; \
86                 echo '#define SYMTAB_KEEP_GPL \'; \
87                 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
88                         awk '{print "*(__ksymtab_gpl." $$$$1 ") \\" }'; \
89                 echo; \
90                 echo '#define SYMTAB_KEEP_STR \'; \
91                 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
92                         awk '{print "*(__ksymtab_strings." $$$$1 ") \\" }'; \
93                 echo; \
94                 echo '#define SYMTAB_DISCARD \'; \
95                 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
96                         awk '{print "*(__ksymtab." $$$$1 ") \\" }'; \
97                 echo; \
98                 echo '#define SYMTAB_DISCARD_GPL \'; \
99                 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
100                         awk '{print "*(__ksymtab_gpl." $$$$1 ") \\" }'; \
101                 echo; \
102                 echo '#define SYMTAB_DISCARD_STR \'; \
103                 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
104                         awk '{print "*(__ksymtab_strings." $$$$1 ") \\" }'; \
105                 echo; \
106         ) > $$@
107
108   $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config
109         $(Kernel/Configure)
110         touch $$@
111
112   $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
113         $(Kernel/CompileModules)
114         touch $$@
115
116   $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
117         $(Kernel/CompileImage)
118         $(Kernel/CollectDebug)
119         touch $$@
120         
121   mostlyclean: FORCE
122         $(Kernel/Clean)
123
124   define BuildKernel
125   endef
126
127   download: $(DL_DIR)/$(LINUX_SOURCE)
128   prepare: $(STAMP_CONFIGURED)
129   compile: $(LINUX_DIR)/.modules
130         $(MAKE) -C image compile TARGET_BUILD=
131
132   oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
133         rm -f $(STAMP_CONFIGURED)
134         $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
135         $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $$@
136         $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
137
138   install: $(LINUX_DIR)/.image
139         +$(MAKE) -C image compile install TARGET_BUILD=
140
141   clean: FORCE
142         rm -rf $(KERNEL_BUILD_DIR)
143
144   image-prereq:
145         @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
146
147   prereq: image-prereq
148
149 endef