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