OSDN Git Service

build: drop HOST_LOADLIBES
[immortalwrt/immortalwrt.git] / include / kernel-build.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2006-2020 OpenWrt.org
4
5 include $(INCLUDE_DIR)/prereq.mk
6 include $(INCLUDE_DIR)/depends.mk
7
8 ifneq ($(DUMP),1)
9   all: compile
10 endif
11
12 KERNEL_FILE_DEPENDS=$(GENERIC_BACKPORT_DIR) $(GENERIC_PATCH_DIR) $(GENERIC_HACK_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
13 STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
14 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
15 include $(INCLUDE_DIR)/download.mk
16 include $(INCLUDE_DIR)/quilt.mk
17 include $(INCLUDE_DIR)/kernel-defaults.mk
18
19 define Kernel/Prepare
20         $(call Kernel/Prepare/Default)
21 endef
22
23 define Kernel/Configure
24         $(call Kernel/Configure/Default)
25 endef
26
27 define Kernel/CompileModules
28         $(call Kernel/CompileModules/Default)
29 endef
30
31 define Kernel/CompileImage
32         $(call Kernel/CompileImage/Default)
33         $(call Kernel/CompileImage/Initramfs)
34 endef
35
36 define Kernel/Clean
37         $(call Kernel/Clean/Default)
38 endef
39
40 define Download/kernel
41   URL:=$(LINUX_SITE)
42   FILE:=$(LINUX_SOURCE)
43   HASH:=$(LINUX_KERNEL_HASH)
44 endef
45
46 KERNEL_GIT_OPTS:=
47 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
48   KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
49 endif
50
51 define Download/git-kernel
52   URL:=$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI))
53   PROTO:=git
54   VERSION:=$(CONFIG_KERNEL_GIT_REF)
55   FILE:=$(LINUX_SOURCE)
56   SUBDIR:=linux-$(LINUX_VERSION)
57   OPTS:=$(KERNEL_GIT_OPTS)
58 endef
59
60 ifdef CONFIG_COLLECT_KERNEL_DEBUG
61   define Kernel/CollectDebug
62         rm -rf $(KERNEL_BUILD_DIR)/debug
63         mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
64         $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
65         -$(CP) \
66                 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
67                 $(KERNEL_BUILD_DIR)/debug/modules/
68         $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
69         $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
70                 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
71                 | zstd -T0 -f -o $(BIN_DIR)/kernel-debug.tar.zst
72   endef
73 endif
74
75 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
76   ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
77     define Kernel/Autoclean
78       $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
79       $(call rdep,$(KERNEL_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
80     endef
81   endif
82 endif
83
84 define BuildKernel
85   $(if $(QUILT),$(Build/Quilt))
86   $(if $(LINUX_SITE),$(call Download,kernel))
87   $(if $(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),$(call Download,git-kernel))
88
89   .NOTPARALLEL:
90
91   $(Kernel/Autoclean)
92   $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
93         -rm -rf $(KERNEL_BUILD_DIR)
94         -mkdir -p $(KERNEL_BUILD_DIR)
95         $(Kernel/Prepare)
96         touch $$@
97
98   $(KERNEL_BUILD_DIR)/symtab.h: FORCE
99         rm -f $(KERNEL_BUILD_DIR)/symtab.h
100         touch $(KERNEL_BUILD_DIR)/symtab.h
101         +$(KERNEL_MAKE) vmlinux
102         find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
103                 xargs $(TARGET_CROSS)nm | \
104                 awk '$$$$1 == "U" { print $$$$2 } ' | \
105                 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
106         $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | awk '/^[0-9a-f]+ [rR] __ksymtab_/ {print substr($$$$3,11)}' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
107         grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
108         grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
109         ( \
110                 echo '#define SYMTAB_KEEP \'; \
111                 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
112                         awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
113                 echo; \
114                 echo '#define SYMTAB_KEEP_GPL \'; \
115                 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
116                         awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
117                 echo; \
118                 echo '#define SYMTAB_DISCARD \'; \
119                 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
120                         awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
121                 echo; \
122                 echo '#define SYMTAB_DISCARD_GPL \'; \
123                 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
124                         awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
125                 echo; \
126         ) > $$@
127
128   $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
129         $(Kernel/Configure)
130         touch $$@
131
132   $(LINUX_DIR)/.modules: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
133   $(LINUX_DIR)/.modules: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
134   $(LINUX_DIR)/.modules: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
135   $(LINUX_DIR)/.modules: export FAIL_ON_UNCONFIGURED=1
136   $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
137         $(Kernel/CompileModules)
138         touch $$@
139
140   $(LINUX_DIR)/.image: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
141   $(LINUX_DIR)/.image: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
142   $(LINUX_DIR)/.image: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
143   $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
144         $(Kernel/CompileImage)
145         $(Kernel/CollectDebug)
146         touch $$@
147         
148   mostlyclean: FORCE
149         $(Kernel/Clean)
150
151   define BuildKernel
152   endef
153
154   download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
155   prepare: $(STAMP_PREPARED)
156   compile: $(LINUX_DIR)/.modules
157         $(MAKE) -C image compile TARGET_BUILD=
158
159   oldconfig menuconfig nconfig xconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
160         rm -f $(LINUX_DIR)/.config.prev
161         rm -f $(STAMP_CONFIGURED)
162         $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
163         $(_SINGLE)$(KERNEL_MAKE) \
164                 $(if $(findstring Darwin,$(HOST_OS)), \
165                         HOSTLDLIBS_mconf="-L$(STAGING_DIR_HOST)/lib -lncurses" \
166                         filechk_conf_cfg="      :" \
167                 ) \
168                 YACC=$(STAGING_DIR_HOST)/bin/bison \
169                 $$@
170         $(call LINUX_RECONF_DIFF,$(LINUX_DIR)/.config) > $(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