ramips: rename PSG1218 to match label
[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)/prereq.mk
8 include $(INCLUDE_DIR)/depends.mk
9
10 ifneq ($(DUMP),1)
11 all: compile
12 endif
13
14 KERNEL_FILE_DEPENDS=$(GENERIC_PATCH_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
15 STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
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 HASH:=$(LINUX_KERNEL_HASH)
46 endef
47
48 KERNEL_GIT_OPTS:=
49 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
50 KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
51 endif
52
53 ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
54 KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
55 endif
56
57 define Download/git-kernel
58 URL:=$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI))
59 PROTO:=git
60 VERSION:=$(CONFIG_KERNEL_GIT_BRANCH)
61 FILE:=$(LINUX_SOURCE)
62 SUBDIR:=linux-$(LINUX_VERSION)
63 OPTS:=$(KERNEL_GIT_OPTS)
64 endef
65
66 ifdef CONFIG_COLLECT_KERNEL_DEBUG
67 define Kernel/CollectDebug
68 rm -rf $(KERNEL_BUILD_DIR)/debug
69 mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
70 $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
71 -$(CP) \
72 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
73 $(KERNEL_BUILD_DIR)/debug/modules/
74 $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
75 $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
76 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
77 | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
78 endef
79 endif
80
81 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
82 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
83 define Kernel/Autoclean
84 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
85 $(call rdep,$(KERNEL_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
86 endef
87 endif
88 endif
89
90 define BuildKernel
91 $(if $(QUILT),$(Build/Quilt))
92 $(if $(LINUX_SITE),$(call Download,kernel))
93 $(if $(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),$(call Download,git-kernel))
94
95 .NOTPARALLEL:
96
97 $(Kernel/Autoclean)
98 $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
99 -rm -rf $(KERNEL_BUILD_DIR)
100 -mkdir -p $(KERNEL_BUILD_DIR)
101 $(Kernel/Prepare)
102 touch $$@
103
104 $(KERNEL_BUILD_DIR)/symtab.h: FORCE
105 rm -f $(KERNEL_BUILD_DIR)/symtab.h
106 touch $(KERNEL_BUILD_DIR)/symtab.h
107 +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
108 find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
109 xargs $(TARGET_CROSS)nm | \
110 awk '$$$$1 == "U" { print $$$$2 } ' | \
111 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
112 $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
113 grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
114 grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
115 ( \
116 echo '#define SYMTAB_KEEP \'; \
117 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
118 awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
119 echo; \
120 echo '#define SYMTAB_KEEP_GPL \'; \
121 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
122 awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
123 echo; \
124 echo '#define SYMTAB_DISCARD \'; \
125 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
126 awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
127 echo; \
128 echo '#define SYMTAB_DISCARD_GPL \'; \
129 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
130 awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
131 echo; \
132 ) > $$@
133
134 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
135 $(Kernel/Configure)
136 touch $$@
137
138 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
139 $(Kernel/CompileModules)
140 touch $$@
141
142 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
143 $(Kernel/CompileImage)
144 $(Kernel/CollectDebug)
145 touch $$@
146
147 mostlyclean: FORCE
148 $(Kernel/Clean)
149
150 define BuildKernel
151 endef
152
153 download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
154 prepare: $(STAMP_PREPARED)
155 compile: $(LINUX_DIR)/.modules
156 $(MAKE) -C image compile TARGET_BUILD=
157
158 oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
159 rm -f $(LINUX_DIR)/.config.prev
160 rm -f $(STAMP_CONFIGURED)
161 $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
162 $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib -lncurses" $$@
163 $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
164
165 install: $(LINUX_DIR)/.image
166 +$(MAKE) -C image compile install TARGET_BUILD=
167
168 clean: FORCE
169 rm -rf $(KERNEL_BUILD_DIR)
170
171 image-prereq:
172 @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
173
174 prereq: image-prereq
175
176 endef