| .. | .. |
|---|
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -VERSION = 4 |
|---|
| 3 | | -PATCHLEVEL = 19 |
|---|
| 4 | | -SUBLEVEL = 232 |
|---|
| 2 | +VERSION = 5 |
|---|
| 3 | +PATCHLEVEL = 10 |
|---|
| 4 | +SUBLEVEL = 160 |
|---|
| 5 | 5 | EXTRAVERSION = |
|---|
| 6 | | -NAME = "People's Front" |
|---|
| 6 | +NAME = Dare mighty things |
|---|
| 7 | 7 | |
|---|
| 8 | 8 | # *DOCUMENTATION* |
|---|
| 9 | 9 | # To see a list of typical targets execute "make help" |
|---|
| .. | .. |
|---|
| 11 | 11 | # Comments in this file are targeted only to the developer, do not |
|---|
| 12 | 12 | # expect to learn how to build the kernel reading this file. |
|---|
| 13 | 13 | |
|---|
| 14 | +$(if $(filter __%, $(MAKECMDGOALS)), \ |
|---|
| 15 | + $(error targets prefixed with '__' are only for internal use)) |
|---|
| 16 | + |
|---|
| 14 | 17 | # That's our default target when none is given on the command line |
|---|
| 15 | | -PHONY := _all |
|---|
| 16 | | -_all: |
|---|
| 17 | | - |
|---|
| 18 | | -# o Do not use make's built-in rules and variables |
|---|
| 19 | | -# (this increases performance and avoids hard-to-debug behaviour); |
|---|
| 20 | | -# o Look for make include files relative to root of kernel src |
|---|
| 21 | | -MAKEFLAGS += -rR --include-dir=$(CURDIR) |
|---|
| 22 | | - |
|---|
| 23 | | -# Avoid funny character set dependencies |
|---|
| 24 | | -unexport LC_ALL |
|---|
| 25 | | -LC_COLLATE=C |
|---|
| 26 | | -LC_NUMERIC=C |
|---|
| 27 | | -export LC_COLLATE LC_NUMERIC |
|---|
| 28 | | - |
|---|
| 29 | | -# Avoid interference with shell env settings |
|---|
| 30 | | -unexport GREP_OPTIONS |
|---|
| 18 | +PHONY := __all |
|---|
| 19 | +__all: |
|---|
| 31 | 20 | |
|---|
| 32 | 21 | # We are using a recursive build, so we need to do a little thinking |
|---|
| 33 | 22 | # to get the ordering right. |
|---|
| .. | .. |
|---|
| 44 | 33 | # effects are thus separated out and done before the recursive |
|---|
| 45 | 34 | # descending is started. They are now explicitly listed as the |
|---|
| 46 | 35 | # prepare rule. |
|---|
| 36 | + |
|---|
| 37 | +ifneq ($(sub_make_done),1) |
|---|
| 38 | + |
|---|
| 39 | +# Do not use make's built-in rules and variables |
|---|
| 40 | +# (this increases performance and avoids hard-to-debug behaviour) |
|---|
| 41 | +MAKEFLAGS += -rR |
|---|
| 42 | + |
|---|
| 43 | +# Avoid funny character set dependencies |
|---|
| 44 | +unexport LC_ALL |
|---|
| 45 | +LC_COLLATE=C |
|---|
| 46 | +LC_NUMERIC=C |
|---|
| 47 | +export LC_COLLATE LC_NUMERIC |
|---|
| 48 | + |
|---|
| 49 | +# Avoid interference with shell env settings |
|---|
| 50 | +unexport GREP_OPTIONS |
|---|
| 47 | 51 | |
|---|
| 48 | 52 | # Beautify output |
|---|
| 49 | 53 | # --------------------------------------------------------------------------- |
|---|
| .. | .. |
|---|
| 67 | 71 | # |
|---|
| 68 | 72 | # If KBUILD_VERBOSE equals 0 then the above command will be hidden. |
|---|
| 69 | 73 | # If KBUILD_VERBOSE equals 1 then the above command is displayed. |
|---|
| 74 | +# If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt. |
|---|
| 70 | 75 | # |
|---|
| 71 | 76 | # To put more focus on warnings, be less verbose as default |
|---|
| 72 | 77 | # Use 'make V=1' to see the full commands |
|---|
| .. | .. |
|---|
| 91 | 96 | |
|---|
| 92 | 97 | ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) |
|---|
| 93 | 98 | quiet=silent_ |
|---|
| 94 | | - tools_silent=s |
|---|
| 95 | 99 | endif |
|---|
| 96 | 100 | |
|---|
| 97 | 101 | export quiet Q KBUILD_VERBOSE |
|---|
| 98 | 102 | |
|---|
| 99 | | -# kbuild supports saving output files in a separate directory. |
|---|
| 100 | | -# To locate output files in a separate directory two syntaxes are supported. |
|---|
| 101 | | -# In both cases the working directory must be the root of the kernel src. |
|---|
| 103 | +# Kbuild will save output files in the current working directory. |
|---|
| 104 | +# This does not need to match to the root of the kernel source tree. |
|---|
| 105 | +# |
|---|
| 106 | +# For example, you can do this: |
|---|
| 107 | +# |
|---|
| 108 | +# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile |
|---|
| 109 | +# |
|---|
| 110 | +# If you want to save output files in a different location, there are |
|---|
| 111 | +# two syntaxes to specify it. |
|---|
| 112 | +# |
|---|
| 102 | 113 | # 1) O= |
|---|
| 103 | 114 | # Use "make O=dir/to/store/output/files/" |
|---|
| 104 | 115 | # |
|---|
| 105 | 116 | # 2) Set KBUILD_OUTPUT |
|---|
| 106 | | -# Set the environment variable KBUILD_OUTPUT to point to the directory |
|---|
| 107 | | -# where the output files shall be placed. |
|---|
| 108 | | -# export KBUILD_OUTPUT=dir/to/store/output/files/ |
|---|
| 109 | | -# make |
|---|
| 117 | +# Set the environment variable KBUILD_OUTPUT to point to the output directory. |
|---|
| 118 | +# export KBUILD_OUTPUT=dir/to/store/output/files/; make |
|---|
| 110 | 119 | # |
|---|
| 111 | 120 | # The O= assignment takes precedence over the KBUILD_OUTPUT environment |
|---|
| 112 | 121 | # variable. |
|---|
| 113 | 122 | |
|---|
| 114 | | -# KBUILD_SRC is not intended to be used by the regular user (for now), |
|---|
| 115 | | -# it is set on invocation of make with KBUILD_OUTPUT or O= specified. |
|---|
| 116 | | -ifeq ($(KBUILD_SRC),) |
|---|
| 117 | | - |
|---|
| 118 | | -# OK, Make called in directory where kernel src resides |
|---|
| 119 | | -# Do we want to locate output files in a separate directory? |
|---|
| 123 | +# Do we want to change the working directory? |
|---|
| 120 | 124 | ifeq ("$(origin O)", "command line") |
|---|
| 121 | 125 | KBUILD_OUTPUT := $(O) |
|---|
| 122 | 126 | endif |
|---|
| 123 | 127 | |
|---|
| 124 | | -# Cancel implicit rules on top Makefile |
|---|
| 125 | | -$(CURDIR)/Makefile Makefile: ; |
|---|
| 128 | +ifneq ($(KBUILD_OUTPUT),) |
|---|
| 129 | +# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot |
|---|
| 130 | +# expand a shell special character '~'. We use a somewhat tedious way here. |
|---|
| 131 | +abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) |
|---|
| 132 | +$(if $(abs_objtree),, \ |
|---|
| 133 | + $(error failed to create output directory "$(KBUILD_OUTPUT)")) |
|---|
| 126 | 134 | |
|---|
| 127 | | -ifneq ($(words $(subst :, ,$(CURDIR))), 1) |
|---|
| 128 | | - $(error main directory cannot contain spaces nor colons) |
|---|
| 135 | +# $(realpath ...) resolves symlinks |
|---|
| 136 | +abs_objtree := $(realpath $(abs_objtree)) |
|---|
| 137 | +else |
|---|
| 138 | +abs_objtree := $(CURDIR) |
|---|
| 139 | +endif # ifneq ($(KBUILD_OUTPUT),) |
|---|
| 140 | + |
|---|
| 141 | +ifeq ($(abs_objtree),$(CURDIR)) |
|---|
| 142 | +# Suppress "Entering directory ..." unless we are changing the work directory. |
|---|
| 143 | +MAKEFLAGS += --no-print-directory |
|---|
| 144 | +else |
|---|
| 145 | +need-sub-make := 1 |
|---|
| 129 | 146 | endif |
|---|
| 130 | 147 | |
|---|
| 131 | | -ifneq ($(KBUILD_OUTPUT),) |
|---|
| 132 | | -# check that the output directory actually exists |
|---|
| 133 | | -saved-output := $(KBUILD_OUTPUT) |
|---|
| 134 | | -KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \ |
|---|
| 135 | | - && pwd) |
|---|
| 136 | | -$(if $(KBUILD_OUTPUT),, \ |
|---|
| 137 | | - $(error failed to create output directory "$(saved-output)")) |
|---|
| 148 | +abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) |
|---|
| 138 | 149 | |
|---|
| 139 | | -PHONY += $(MAKECMDGOALS) sub-make |
|---|
| 150 | +ifneq ($(words $(subst :, ,$(abs_srctree))), 1) |
|---|
| 151 | +$(error source directory cannot contain spaces or colons) |
|---|
| 152 | +endif |
|---|
| 140 | 153 | |
|---|
| 141 | | -$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make |
|---|
| 154 | +ifneq ($(abs_srctree),$(abs_objtree)) |
|---|
| 155 | +# Look for make include files relative to root of kernel src |
|---|
| 156 | +# |
|---|
| 157 | +# This does not become effective immediately because MAKEFLAGS is re-parsed |
|---|
| 158 | +# once after the Makefile is read. We need to invoke sub-make. |
|---|
| 159 | +MAKEFLAGS += --include-dir=$(abs_srctree) |
|---|
| 160 | +need-sub-make := 1 |
|---|
| 161 | +endif |
|---|
| 162 | + |
|---|
| 163 | +this-makefile := $(lastword $(MAKEFILE_LIST)) |
|---|
| 164 | + |
|---|
| 165 | +ifneq ($(filter 3.%,$(MAKE_VERSION)),) |
|---|
| 166 | +# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x |
|---|
| 167 | +# We need to invoke sub-make to avoid implicit rules in the top Makefile. |
|---|
| 168 | +need-sub-make := 1 |
|---|
| 169 | +# Cancel implicit rules for this Makefile. |
|---|
| 170 | +$(this-makefile): ; |
|---|
| 171 | +endif |
|---|
| 172 | + |
|---|
| 173 | +export abs_srctree abs_objtree |
|---|
| 174 | +export sub_make_done := 1 |
|---|
| 175 | + |
|---|
| 176 | +ifeq ($(need-sub-make),1) |
|---|
| 177 | + |
|---|
| 178 | +PHONY += $(MAKECMDGOALS) __sub-make |
|---|
| 179 | + |
|---|
| 180 | +$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make |
|---|
| 142 | 181 | @: |
|---|
| 143 | 182 | |
|---|
| 144 | 183 | # Invoke a second make in the output directory, passing relevant variables |
|---|
| 145 | | -sub-make: |
|---|
| 146 | | - $(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \ |
|---|
| 147 | | - -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS)) |
|---|
| 184 | +__sub-make: |
|---|
| 185 | + $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS) |
|---|
| 148 | 186 | |
|---|
| 149 | | -# Leave processing to above invocation of make |
|---|
| 150 | | -skip-makefile := 1 |
|---|
| 151 | | -endif # ifneq ($(KBUILD_OUTPUT),) |
|---|
| 152 | | -endif # ifeq ($(KBUILD_SRC),) |
|---|
| 187 | +endif # need-sub-make |
|---|
| 188 | +endif # sub_make_done |
|---|
| 153 | 189 | |
|---|
| 154 | 190 | # We process the rest of the Makefile if this is the final invocation of make |
|---|
| 155 | | -ifeq ($(skip-makefile),) |
|---|
| 191 | +ifeq ($(need-sub-make),) |
|---|
| 156 | 192 | |
|---|
| 157 | 193 | # Do not print "Entering directory ...", |
|---|
| 158 | 194 | # but we want to display it when entering to the output directory |
|---|
| .. | .. |
|---|
| 176 | 212 | KBUILD_CHECKSRC = 0 |
|---|
| 177 | 213 | endif |
|---|
| 178 | 214 | |
|---|
| 179 | | -# Use make M=dir to specify directory of external module to build |
|---|
| 180 | | -# Old syntax make ... SUBDIRS=$PWD is still supported |
|---|
| 181 | | -# Setting the environment variable KBUILD_EXTMOD take precedence |
|---|
| 182 | | -ifdef SUBDIRS |
|---|
| 183 | | - KBUILD_EXTMOD ?= $(SUBDIRS) |
|---|
| 184 | | -endif |
|---|
| 185 | | - |
|---|
| 215 | +# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the |
|---|
| 216 | +# directory of external module to build. Setting M= takes precedence. |
|---|
| 186 | 217 | ifeq ("$(origin M)", "command line") |
|---|
| 187 | 218 | KBUILD_EXTMOD := $(M) |
|---|
| 188 | 219 | endif |
|---|
| 189 | 220 | |
|---|
| 190 | | -ifeq ($(KBUILD_SRC),) |
|---|
| 221 | +$(if $(word 2, $(KBUILD_EXTMOD)), \ |
|---|
| 222 | + $(error building multiple external modules is not supported)) |
|---|
| 223 | + |
|---|
| 224 | +export KBUILD_CHECKSRC KBUILD_EXTMOD |
|---|
| 225 | + |
|---|
| 226 | +extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) |
|---|
| 227 | + |
|---|
| 228 | +# ANDROID: set up mixed-build support. mixed-build allows device kernel modules |
|---|
| 229 | +# to be compiled against a GKI kernel. This approach still uses the headers and |
|---|
| 230 | +# Kbuild from device kernel, so care must be taken to ensure that those headers match. |
|---|
| 231 | +ifdef KBUILD_MIXED_TREE |
|---|
| 232 | +# Need vmlinux.symvers for modpost and System.map for depmod, check whether they exist in KBUILD_MIXED_TREE |
|---|
| 233 | +required_mixed_files=vmlinux.symvers System.map |
|---|
| 234 | +$(if $(filter-out $(words $(required_mixed_files)), \ |
|---|
| 235 | + $(words $(wildcard $(add-prefix $(KBUILD_MIXED_TREE)/,$(required_mixed_files))))),,\ |
|---|
| 236 | + $(error KBUILD_MIXED_TREE=$(KBUILD_MIXED_TREE) doesn't contain $(required_mixed_files))) |
|---|
| 237 | +endif |
|---|
| 238 | + |
|---|
| 239 | +mixed-build-prefix = $(if $(KBUILD_MIXED_TREE),$(KBUILD_MIXED_TREE)/) |
|---|
| 240 | +export KBUILD_MIXED_TREE |
|---|
| 241 | + |
|---|
| 242 | +ifeq ($(abs_srctree),$(abs_objtree)) |
|---|
| 191 | 243 | # building in the source tree |
|---|
| 192 | 244 | srctree := . |
|---|
| 245 | + building_out_of_srctree := |
|---|
| 193 | 246 | else |
|---|
| 194 | | - ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR))) |
|---|
| 247 | + ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) |
|---|
| 195 | 248 | # building in a subdirectory of the source tree |
|---|
| 196 | 249 | srctree := .. |
|---|
| 197 | 250 | else |
|---|
| 198 | | - srctree := $(KBUILD_SRC) |
|---|
| 251 | + srctree := $(abs_srctree) |
|---|
| 199 | 252 | endif |
|---|
| 253 | + building_out_of_srctree := 1 |
|---|
| 200 | 254 | endif |
|---|
| 201 | 255 | |
|---|
| 202 | | -export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC |
|---|
| 256 | +ifneq ($(KBUILD_ABS_SRCTREE),) |
|---|
| 257 | +srctree := $(abs_srctree) |
|---|
| 258 | +endif |
|---|
| 203 | 259 | |
|---|
| 204 | 260 | objtree := . |
|---|
| 205 | | -src := $(srctree) |
|---|
| 206 | | -obj := $(objtree) |
|---|
| 261 | +VPATH := $(srctree) |
|---|
| 207 | 262 | |
|---|
| 208 | | -VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD)) |
|---|
| 209 | | - |
|---|
| 210 | | -export srctree objtree VPATH |
|---|
| 263 | +export building_out_of_srctree srctree objtree VPATH |
|---|
| 211 | 264 | |
|---|
| 212 | 265 | # To make sure we do not include .config for any of the *config targets |
|---|
| 213 | 266 | # catch them early, and hand them over to scripts/kconfig/Makefile |
|---|
| .. | .. |
|---|
| 223 | 276 | clean-targets := %clean mrproper cleandocs |
|---|
| 224 | 277 | no-dot-config-targets := $(clean-targets) \ |
|---|
| 225 | 278 | cscope gtags TAGS tags help% %docs check% coccicheck \ |
|---|
| 226 | | - $(version_h) headers_% archheaders archscripts \ |
|---|
| 227 | | - %asm-generic kernelversion %src-pkg |
|---|
| 228 | | -no-sync-config-targets := $(no-dot-config-targets) install %install \ |
|---|
| 229 | | - kernelrelease |
|---|
| 279 | + $(version_h) headers headers_% archheaders archscripts \ |
|---|
| 280 | + %asm-generic kernelversion %src-pkg dt_binding_check \ |
|---|
| 281 | + outputmakefile |
|---|
| 282 | +no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ |
|---|
| 283 | + image_name |
|---|
| 284 | +single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ |
|---|
| 230 | 285 | |
|---|
| 231 | | -config-targets := 0 |
|---|
| 232 | | -mixed-targets := 0 |
|---|
| 233 | | -dot-config := 1 |
|---|
| 234 | | -may-sync-config := 1 |
|---|
| 286 | +config-build := |
|---|
| 287 | +mixed-build := |
|---|
| 288 | +need-config := 1 |
|---|
| 289 | +may-sync-config := 1 |
|---|
| 290 | +single-build := |
|---|
| 235 | 291 | |
|---|
| 236 | 292 | ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) |
|---|
| 237 | 293 | ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) |
|---|
| 238 | | - dot-config := 0 |
|---|
| 294 | + need-config := |
|---|
| 239 | 295 | endif |
|---|
| 240 | 296 | endif |
|---|
| 241 | 297 | |
|---|
| 242 | 298 | ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) |
|---|
| 243 | 299 | ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) |
|---|
| 244 | | - may-sync-config := 0 |
|---|
| 300 | + may-sync-config := |
|---|
| 245 | 301 | endif |
|---|
| 246 | 302 | endif |
|---|
| 247 | 303 | |
|---|
| 248 | 304 | ifneq ($(KBUILD_EXTMOD),) |
|---|
| 249 | | - may-sync-config := 0 |
|---|
| 305 | + may-sync-config := |
|---|
| 250 | 306 | endif |
|---|
| 251 | 307 | |
|---|
| 252 | 308 | ifeq ($(KBUILD_EXTMOD),) |
|---|
| 253 | | - ifneq ($(filter config %config,$(MAKECMDGOALS)),) |
|---|
| 254 | | - config-targets := 1 |
|---|
| 309 | + ifneq ($(filter %config,$(MAKECMDGOALS)),) |
|---|
| 310 | + config-build := 1 |
|---|
| 255 | 311 | ifneq ($(words $(MAKECMDGOALS)),1) |
|---|
| 256 | | - mixed-targets := 1 |
|---|
| 312 | + mixed-build := 1 |
|---|
| 257 | 313 | endif |
|---|
| 258 | 314 | endif |
|---|
| 315 | +endif |
|---|
| 316 | + |
|---|
| 317 | +# We cannot build single targets and the others at the same time |
|---|
| 318 | +ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) |
|---|
| 319 | + single-build := 1 |
|---|
| 320 | + ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) |
|---|
| 321 | + mixed-build := 1 |
|---|
| 322 | + endif |
|---|
| 259 | 323 | endif |
|---|
| 260 | 324 | |
|---|
| 261 | 325 | # For "make -j clean all", "make -j mrproper defconfig all", etc. |
|---|
| 262 | 326 | ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) |
|---|
| 263 | 327 | ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) |
|---|
| 264 | | - mixed-targets := 1 |
|---|
| 328 | + mixed-build := 1 |
|---|
| 265 | 329 | endif |
|---|
| 266 | 330 | endif |
|---|
| 267 | 331 | |
|---|
| 268 | 332 | # install and modules_install need also be processed one by one |
|---|
| 269 | 333 | ifneq ($(filter install,$(MAKECMDGOALS)),) |
|---|
| 270 | 334 | ifneq ($(filter modules_install,$(MAKECMDGOALS)),) |
|---|
| 271 | | - mixed-targets := 1 |
|---|
| 335 | + mixed-build := 1 |
|---|
| 272 | 336 | endif |
|---|
| 273 | 337 | endif |
|---|
| 274 | 338 | |
|---|
| 275 | | -ifeq ($(mixed-targets),1) |
|---|
| 339 | +ifdef mixed-build |
|---|
| 276 | 340 | # =========================================================================== |
|---|
| 277 | 341 | # We're called with mixed targets (*config and build targets). |
|---|
| 278 | 342 | # Handle them one by one. |
|---|
| 279 | 343 | |
|---|
| 280 | 344 | PHONY += $(MAKECMDGOALS) __build_one_by_one |
|---|
| 281 | 345 | |
|---|
| 282 | | -$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one |
|---|
| 346 | +$(MAKECMDGOALS): __build_one_by_one |
|---|
| 283 | 347 | @: |
|---|
| 284 | 348 | |
|---|
| 285 | 349 | __build_one_by_one: |
|---|
| .. | .. |
|---|
| 288 | 352 | $(MAKE) -f $(srctree)/Makefile $$i; \ |
|---|
| 289 | 353 | done |
|---|
| 290 | 354 | |
|---|
| 291 | | -else |
|---|
| 355 | +else # !mixed-build |
|---|
| 292 | 356 | |
|---|
| 293 | | -# We need some generic definitions (do not try to remake the file). |
|---|
| 294 | | -scripts/Kbuild.include: ; |
|---|
| 295 | 357 | include scripts/Kbuild.include |
|---|
| 296 | 358 | |
|---|
| 297 | 359 | # Read KERNELRELEASE from include/config/kernel.release (if it exists) |
|---|
| .. | .. |
|---|
| 320 | 382 | # Default value for CROSS_COMPILE is not to prefix executables |
|---|
| 321 | 383 | # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile |
|---|
| 322 | 384 | ARCH ?= $(SUBARCH) |
|---|
| 323 | | -ifeq ($(ARCH),arm64) |
|---|
| 324 | | -ifneq ($(wildcard $(srctree)/../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu),) |
|---|
| 325 | | -CROSS_COMPILE ?= $(srctree)/../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- |
|---|
| 326 | | -endif |
|---|
| 327 | | -ifneq ($(wildcard $(srctree)/../prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9),) |
|---|
| 328 | | -CROSS_COMPILE ?= $(srctree)/../prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android- |
|---|
| 329 | | -endif |
|---|
| 330 | | -endif |
|---|
| 331 | | -ifeq ($(ARCH),arm) |
|---|
| 332 | | -ifneq ($(wildcard $(srctree)/../prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf),) |
|---|
| 333 | | -CROSS_COMPILE ?= $(srctree)/../prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- |
|---|
| 334 | | -endif |
|---|
| 335 | | -ifneq ($(wildcard $(srctree)/../prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9),) |
|---|
| 336 | | -CROSS_COMPILE ?= $(srctree)/../prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androidkernel- |
|---|
| 337 | | -endif |
|---|
| 338 | | -endif |
|---|
| 339 | 385 | |
|---|
| 340 | 386 | # Architecture as present in compile.h |
|---|
| 341 | 387 | UTS_MACHINE := $(ARCH) |
|---|
| .. | .. |
|---|
| 365 | 411 | KCONFIG_CONFIG ?= .config |
|---|
| 366 | 412 | export KCONFIG_CONFIG |
|---|
| 367 | 413 | |
|---|
| 414 | +# Default file for 'make defconfig'. This may be overridden by arch-Makefile. |
|---|
| 415 | +export KBUILD_DEFCONFIG := defconfig |
|---|
| 416 | + |
|---|
| 368 | 417 | # SHELL used by kbuild |
|---|
| 369 | | -CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ |
|---|
| 370 | | - else if [ -x /bin/bash ]; then echo /bin/bash; \ |
|---|
| 371 | | - else echo sh; fi ; fi) |
|---|
| 418 | +CONFIG_SHELL := sh |
|---|
| 372 | 419 | |
|---|
| 373 | 420 | HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null) |
|---|
| 374 | 421 | HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) |
|---|
| .. | .. |
|---|
| 381 | 428 | HOSTCC = gcc |
|---|
| 382 | 429 | HOSTCXX = g++ |
|---|
| 383 | 430 | endif |
|---|
| 384 | | -KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ |
|---|
| 385 | | - -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \ |
|---|
| 386 | | - $(HOSTCFLAGS) |
|---|
| 387 | | -KBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) |
|---|
| 431 | + |
|---|
| 432 | +KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ |
|---|
| 433 | + -O2 -fomit-frame-pointer -std=gnu89 |
|---|
| 434 | +KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) |
|---|
| 435 | +KBUILD_USERLDFLAGS := $(USERLDFLAGS) |
|---|
| 436 | + |
|---|
| 437 | +KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) |
|---|
| 438 | +KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) |
|---|
| 388 | 439 | KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) |
|---|
| 389 | 440 | KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) |
|---|
| 390 | 441 | |
|---|
| .. | .. |
|---|
| 398 | 449 | OBJCOPY = llvm-objcopy |
|---|
| 399 | 450 | OBJDUMP = llvm-objdump |
|---|
| 400 | 451 | READELF = llvm-readelf |
|---|
| 401 | | -OBJSIZE = llvm-size |
|---|
| 402 | 452 | STRIP = llvm-strip |
|---|
| 403 | 453 | else |
|---|
| 404 | 454 | CC = $(CROSS_COMPILE)gcc |
|---|
| .. | .. |
|---|
| 408 | 458 | OBJCOPY = $(CROSS_COMPILE)objcopy |
|---|
| 409 | 459 | OBJDUMP = $(CROSS_COMPILE)objdump |
|---|
| 410 | 460 | READELF = $(CROSS_COMPILE)readelf |
|---|
| 411 | | -OBJSIZE = $(CROSS_COMPILE)size |
|---|
| 412 | 461 | STRIP = $(CROSS_COMPILE)strip |
|---|
| 413 | 462 | endif |
|---|
| 463 | +PAHOLE = pahole |
|---|
| 464 | +RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids |
|---|
| 414 | 465 | LEX = flex |
|---|
| 415 | 466 | YACC = bison |
|---|
| 416 | 467 | AWK = awk |
|---|
| 417 | | -GENKSYMS = scripts/genksyms/genksyms |
|---|
| 418 | 468 | INSTALLKERNEL := installkernel |
|---|
| 419 | 469 | DEPMOD = depmod |
|---|
| 420 | 470 | PERL = perl |
|---|
| 421 | 471 | PYTHON = python |
|---|
| 422 | | -PYTHON2 = python2 |
|---|
| 423 | 472 | PYTHON3 = python3 |
|---|
| 424 | 473 | CHECK = sparse |
|---|
| 474 | +BASH = bash |
|---|
| 475 | +KGZIP = gzip |
|---|
| 476 | +KBZIP2 = bzip2 |
|---|
| 477 | +KLZOP = lzop |
|---|
| 478 | +LZMA = lzma |
|---|
| 479 | +LZ4 = lz4 |
|---|
| 480 | +XZ = xz |
|---|
| 481 | +ZSTD = zstd |
|---|
| 425 | 482 | |
|---|
| 426 | 483 | # Use the wrapper for the compiler. This wrapper scans for new |
|---|
| 427 | 484 | # warnings and causes the build to stop upon encountering them. |
|---|
| 428 | 485 | ifeq ($(CC),$(CROSS_COMPILE)gcc) |
|---|
| 429 | 486 | ifneq ($(wildcard $(srctree)/scripts/gcc-wrapper.py),) |
|---|
| 430 | | -CC = $(srctree)/scripts/gcc-wrapper.py $(CROSS_COMPILE)gcc |
|---|
| 487 | +CC = $(abspath $(srctree)/scripts/gcc-wrapper.py) $(CROSS_COMPILE)gcc |
|---|
| 431 | 488 | endif |
|---|
| 432 | 489 | endif |
|---|
| 433 | 490 | |
|---|
| 491 | +PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) |
|---|
| 492 | + |
|---|
| 434 | 493 | CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ |
|---|
| 435 | 494 | -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) |
|---|
| 436 | | -NOSTDINC_FLAGS = |
|---|
| 495 | +NOSTDINC_FLAGS := |
|---|
| 437 | 496 | CFLAGS_MODULE = |
|---|
| 438 | 497 | AFLAGS_MODULE = |
|---|
| 439 | 498 | LDFLAGS_MODULE = |
|---|
| .. | .. |
|---|
| 454 | 513 | LINUXINCLUDE := \ |
|---|
| 455 | 514 | -I$(srctree)/arch/$(SRCARCH)/include \ |
|---|
| 456 | 515 | -I$(objtree)/arch/$(SRCARCH)/include/generated \ |
|---|
| 457 | | - $(if $(KBUILD_SRC), -I$(srctree)/include) \ |
|---|
| 516 | + $(if $(building_out_of_srctree),-I$(srctree)/include) \ |
|---|
| 458 | 517 | -I$(objtree)/include \ |
|---|
| 459 | 518 | $(USERINCLUDE) |
|---|
| 460 | 519 | |
|---|
| 461 | | -KBUILD_AFLAGS := -D__ASSEMBLY__ |
|---|
| 462 | | -KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ |
|---|
| 463 | | - -fno-strict-aliasing -fno-common -fshort-wchar \ |
|---|
| 464 | | - -Werror-implicit-function-declaration \ |
|---|
| 520 | +KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE |
|---|
| 521 | +KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ |
|---|
| 522 | + -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ |
|---|
| 523 | + -Werror=implicit-function-declaration -Werror=implicit-int \ |
|---|
| 465 | 524 | -Werror=return-type -Wno-format-security \ |
|---|
| 525 | + -w \ |
|---|
| 466 | 526 | -std=gnu89 |
|---|
| 467 | 527 | KBUILD_CPPFLAGS := -D__KERNEL__ |
|---|
| 468 | 528 | KBUILD_AFLAGS_KERNEL := |
|---|
| 469 | 529 | KBUILD_CFLAGS_KERNEL := |
|---|
| 470 | 530 | KBUILD_AFLAGS_MODULE := -DMODULE |
|---|
| 471 | 531 | KBUILD_CFLAGS_MODULE := -DMODULE |
|---|
| 472 | | -KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds |
|---|
| 532 | +KBUILD_LDFLAGS_MODULE := |
|---|
| 473 | 533 | KBUILD_LDFLAGS := |
|---|
| 474 | | -GCC_PLUGINS_CFLAGS := |
|---|
| 475 | 534 | CLANG_FLAGS := |
|---|
| 476 | 535 | |
|---|
| 477 | | -export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC |
|---|
| 478 | | -export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS |
|---|
| 479 | | -export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE |
|---|
| 480 | | -export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS |
|---|
| 536 | +export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC |
|---|
| 537 | +export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL |
|---|
| 538 | +export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX |
|---|
| 539 | +export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD |
|---|
| 540 | +export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE |
|---|
| 541 | +export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS |
|---|
| 481 | 542 | |
|---|
| 482 | 543 | export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS |
|---|
| 483 | 544 | export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE |
|---|
| 484 | | -export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN |
|---|
| 485 | 545 | export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE |
|---|
| 486 | 546 | export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE |
|---|
| 487 | 547 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL |
|---|
| 488 | | -export KBUILD_ARFLAGS |
|---|
| 489 | | - |
|---|
| 490 | | -# When compiling out-of-tree modules, put MODVERDIR in the module |
|---|
| 491 | | -# tree rather than in the kernel tree. The kernel tree might |
|---|
| 492 | | -# even be read-only. |
|---|
| 493 | | -export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions |
|---|
| 548 | +export PAHOLE_FLAGS |
|---|
| 494 | 549 | |
|---|
| 495 | 550 | # Files to ignore in find ... statements |
|---|
| 496 | 551 | |
|---|
| .. | .. |
|---|
| 509 | 564 | $(Q)$(MAKE) $(build)=scripts/basic |
|---|
| 510 | 565 | $(Q)rm -f .tmp_quiet_recordmcount |
|---|
| 511 | 566 | |
|---|
| 512 | | -# To avoid any implicit rule to kick in, define an empty command. |
|---|
| 513 | | -scripts/basic/%: scripts_basic ; |
|---|
| 514 | | - |
|---|
| 515 | 567 | PHONY += outputmakefile |
|---|
| 568 | +# Before starting out-of-tree build, make sure the source tree is clean. |
|---|
| 516 | 569 | # outputmakefile generates a Makefile in the output directory, if using a |
|---|
| 517 | 570 | # separate output directory. This allows convenient use of make in the |
|---|
| 518 | 571 | # output directory. |
|---|
| 572 | +# At the same time when output Makefile generated, generate .gitignore to |
|---|
| 573 | +# ignore whole output directory |
|---|
| 519 | 574 | outputmakefile: |
|---|
| 520 | | -ifneq ($(KBUILD_SRC),) |
|---|
| 575 | +ifdef building_out_of_srctree |
|---|
| 576 | + $(Q)if [ -f $(srctree)/.config -o \ |
|---|
| 577 | + -d $(srctree)/include/config -o \ |
|---|
| 578 | + -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ |
|---|
| 579 | + echo >&2 "***"; \ |
|---|
| 580 | + echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ |
|---|
| 581 | + echo >&2 "*** in $(abs_srctree)";\ |
|---|
| 582 | + echo >&2 "***"; \ |
|---|
| 583 | + false; \ |
|---|
| 584 | + fi |
|---|
| 521 | 585 | $(Q)ln -fsn $(srctree) source |
|---|
| 522 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ |
|---|
| 523 | | - $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) |
|---|
| 586 | + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) |
|---|
| 587 | + $(Q)test -e .gitignore || \ |
|---|
| 588 | + { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore |
|---|
| 524 | 589 | endif |
|---|
| 525 | 590 | |
|---|
| 526 | | -ifeq ($(cc-name),clang) |
|---|
| 591 | +ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) |
|---|
| 527 | 592 | ifneq ($(CROSS_COMPILE),) |
|---|
| 528 | 593 | CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) |
|---|
| 529 | 594 | GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) |
|---|
| .. | .. |
|---|
| 542 | 607 | export CLANG_FLAGS |
|---|
| 543 | 608 | endif |
|---|
| 544 | 609 | |
|---|
| 545 | | -RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register |
|---|
| 546 | | -RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register |
|---|
| 547 | | -RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk |
|---|
| 548 | | -RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline |
|---|
| 549 | | -RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG))) |
|---|
| 550 | | -RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG))) |
|---|
| 551 | | -export RETPOLINE_CFLAGS |
|---|
| 552 | | -export RETPOLINE_VDSO_CFLAGS |
|---|
| 553 | | - |
|---|
| 554 | | -KBUILD_CFLAGS += $(call cc-option,-fno-PIE) |
|---|
| 555 | | -KBUILD_AFLAGS += $(call cc-option,-fno-PIE) |
|---|
| 556 | | - |
|---|
| 557 | 610 | # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. |
|---|
| 558 | 611 | # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. |
|---|
| 559 | 612 | # CC_VERSION_TEXT is referenced from Kconfig (so it needs export), |
|---|
| 560 | 613 | # and from include/config/auto.conf.cmd to detect the compiler upgrade. |
|---|
| 561 | | -CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1) |
|---|
| 614 | +CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1) |
|---|
| 562 | 615 | |
|---|
| 563 | | -ifeq ($(config-targets),1) |
|---|
| 616 | +ifdef config-build |
|---|
| 564 | 617 | # =========================================================================== |
|---|
| 565 | 618 | # *config targets only - make sure prerequisites are updated, and descend |
|---|
| 566 | 619 | # in scripts/kconfig to make the *config target |
|---|
| .. | .. |
|---|
| 571 | 624 | include arch/$(SRCARCH)/Makefile |
|---|
| 572 | 625 | export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT |
|---|
| 573 | 626 | |
|---|
| 574 | | -config: scripts_basic outputmakefile FORCE |
|---|
| 627 | +config: outputmakefile scripts_basic FORCE |
|---|
| 575 | 628 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ |
|---|
| 576 | 629 | |
|---|
| 577 | | -%config: scripts_basic outputmakefile FORCE |
|---|
| 630 | +%config: outputmakefile scripts_basic FORCE |
|---|
| 578 | 631 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ |
|---|
| 579 | 632 | |
|---|
| 580 | | -else |
|---|
| 633 | +else #!config-build |
|---|
| 581 | 634 | # =========================================================================== |
|---|
| 582 | 635 | # Build targets only - this includes vmlinux, arch specific targets, clean |
|---|
| 583 | 636 | # targets and others. In general all targets except *config targets. |
|---|
| 584 | 637 | |
|---|
| 585 | 638 | # If building an external module we do not care about the all: rule |
|---|
| 586 | | -# but instead _all depend on modules |
|---|
| 639 | +# but instead __all depend on modules |
|---|
| 587 | 640 | PHONY += all |
|---|
| 588 | 641 | ifeq ($(KBUILD_EXTMOD),) |
|---|
| 589 | | -_all: all |
|---|
| 642 | +__all: all |
|---|
| 590 | 643 | else |
|---|
| 591 | | -_all: modules |
|---|
| 644 | +__all: modules |
|---|
| 592 | 645 | endif |
|---|
| 593 | 646 | |
|---|
| 594 | 647 | # Decide whether to build built-in, modular, or both. |
|---|
| .. | .. |
|---|
| 606 | 659 | # in addition to whatever we do anyway. |
|---|
| 607 | 660 | # Just "make" or "make all" shall build modules as well |
|---|
| 608 | 661 | |
|---|
| 609 | | -ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) |
|---|
| 662 | +ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),) |
|---|
| 610 | 663 | KBUILD_MODULES := 1 |
|---|
| 611 | 664 | endif |
|---|
| 612 | 665 | |
|---|
| .. | .. |
|---|
| 616 | 669 | |
|---|
| 617 | 670 | export KBUILD_MODULES KBUILD_BUILTIN |
|---|
| 618 | 671 | |
|---|
| 619 | | -ifeq ($(KBUILD_EXTMOD),) |
|---|
| 620 | | -# Objects we will link into vmlinux / subdirs we need to visit |
|---|
| 621 | | -init-y := init/ |
|---|
| 622 | | -drivers-y := drivers/ sound/ firmware/ |
|---|
| 623 | | -net-y := net/ |
|---|
| 624 | | -libs-y := lib/ |
|---|
| 625 | | -core-y := usr/ |
|---|
| 626 | | -virt-y := virt/ |
|---|
| 627 | | -endif # KBUILD_EXTMOD |
|---|
| 628 | | - |
|---|
| 629 | | -ifeq ($(dot-config),1) |
|---|
| 672 | +ifdef need-config |
|---|
| 630 | 673 | include include/config/auto.conf |
|---|
| 631 | 674 | endif |
|---|
| 632 | 675 | |
|---|
| 676 | +ifeq ($(KBUILD_EXTMOD),) |
|---|
| 677 | +# Objects we will link into vmlinux / subdirs we need to visit |
|---|
| 678 | +core-y := init/ usr/ |
|---|
| 679 | +drivers-y := drivers/ sound/ |
|---|
| 680 | +drivers-$(CONFIG_SAMPLES) += samples/ |
|---|
| 681 | +drivers-y += net/ virt/ |
|---|
| 682 | +libs-y := lib/ |
|---|
| 683 | +endif # KBUILD_EXTMOD |
|---|
| 684 | + |
|---|
| 685 | +ifndef KBUILD_MIXED_TREE |
|---|
| 633 | 686 | # The all: target is the default when no target is given on the |
|---|
| 634 | 687 | # command line. |
|---|
| 635 | 688 | # This allow a user to issue only 'make' to build a kernel including modules |
|---|
| 636 | 689 | # Defaults to vmlinux, but the arch makefile usually adds further targets |
|---|
| 637 | 690 | all: vmlinux |
|---|
| 691 | +endif |
|---|
| 638 | 692 | |
|---|
| 639 | 693 | CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ |
|---|
| 640 | 694 | $(call cc-option,-fno-tree-loop-im) \ |
|---|
| .. | .. |
|---|
| 646 | 700 | CC_FLAGS_FTRACE := -pg |
|---|
| 647 | 701 | endif |
|---|
| 648 | 702 | |
|---|
| 649 | | -# Make toolchain changes before including arch/$(SRCARCH)/Makefile to ensure |
|---|
| 650 | | -# ar/cc/ld-* macros return correct values. |
|---|
| 651 | | -ifdef CONFIG_LTO_CLANG |
|---|
| 652 | | -# use llvm-ar for building symbol tables from IR files, and llvm-nm instead |
|---|
| 653 | | -# of objdump for processing symbol versions and exports |
|---|
| 654 | | -LLVM_AR := llvm-ar |
|---|
| 655 | | -LLVM_NM := llvm-nm |
|---|
| 656 | | -export LLVM_AR LLVM_NM |
|---|
| 703 | +ifdef CONFIG_CC_IS_GCC |
|---|
| 704 | +RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) |
|---|
| 705 | +RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix) |
|---|
| 706 | +RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register) |
|---|
| 707 | +endif |
|---|
| 708 | +ifdef CONFIG_CC_IS_CLANG |
|---|
| 709 | +RETPOLINE_CFLAGS := -mretpoline-external-thunk |
|---|
| 710 | +RETPOLINE_VDSO_CFLAGS := -mretpoline |
|---|
| 657 | 711 | endif |
|---|
| 658 | 712 | |
|---|
| 659 | | -# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default |
|---|
| 660 | | -# values of the respective KBUILD_* variables |
|---|
| 661 | | -ARCH_CPPFLAGS := |
|---|
| 662 | | -ARCH_AFLAGS := |
|---|
| 663 | | -ARCH_CFLAGS := |
|---|
| 713 | +ifdef CONFIG_RETHUNK |
|---|
| 714 | +RETHUNK_CFLAGS := -mfunction-return=thunk-extern |
|---|
| 715 | +RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS) |
|---|
| 716 | +endif |
|---|
| 717 | + |
|---|
| 718 | +export RETPOLINE_CFLAGS |
|---|
| 719 | +export RETPOLINE_VDSO_CFLAGS |
|---|
| 720 | + |
|---|
| 664 | 721 | include arch/$(SRCARCH)/Makefile |
|---|
| 665 | 722 | |
|---|
| 666 | | -ifeq ($(dot-config),1) |
|---|
| 667 | | -ifeq ($(may-sync-config),1) |
|---|
| 723 | +ifdef need-config |
|---|
| 724 | +ifdef may-sync-config |
|---|
| 668 | 725 | # Read in dependencies to all Kconfig* files, make sure to run syncconfig if |
|---|
| 669 | 726 | # changes are detected. This should be included after arch/$(SRCARCH)/Makefile |
|---|
| 670 | 727 | # because some architectures define CROSS_COMPILE there. |
|---|
| 671 | 728 | include include/config/auto.conf.cmd |
|---|
| 672 | 729 | |
|---|
| 673 | | -# To avoid any implicit rule to kick in, define an empty command |
|---|
| 674 | | -$(KCONFIG_CONFIG): ; |
|---|
| 730 | +$(KCONFIG_CONFIG): |
|---|
| 731 | + @echo >&2 '***' |
|---|
| 732 | + @echo >&2 '*** Configuration file "$@" not found!' |
|---|
| 733 | + @echo >&2 '***' |
|---|
| 734 | + @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or' |
|---|
| 735 | + @echo >&2 '*** "make menuconfig" or "make xconfig").' |
|---|
| 736 | + @echo >&2 '***' |
|---|
| 737 | + @/bin/false |
|---|
| 675 | 738 | |
|---|
| 676 | 739 | # The actual configuration files used during the build are stored in |
|---|
| 677 | 740 | # include/generated/ and include/config/. Update them if .config is newer than |
|---|
| .. | .. |
|---|
| 679 | 742 | # |
|---|
| 680 | 743 | # This exploits the 'multi-target pattern rule' trick. |
|---|
| 681 | 744 | # The syncconfig should be executed only once to make all the targets. |
|---|
| 682 | | -%/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG) |
|---|
| 745 | +# (Note: use the grouped target '&:' when we bump to GNU Make 4.3) |
|---|
| 746 | +# |
|---|
| 747 | +# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig, |
|---|
| 748 | +# so you cannot notice that Kconfig is waiting for the user input. |
|---|
| 749 | +%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG) |
|---|
| 750 | + $(Q)$(kecho) " SYNC $@" |
|---|
| 683 | 751 | $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig |
|---|
| 684 | | -else |
|---|
| 752 | +else # !may-sync-config |
|---|
| 685 | 753 | # External modules and some install targets need include/generated/autoconf.h |
|---|
| 686 | 754 | # and include/config/auto.conf but do not care if they are up-to-date. |
|---|
| 687 | 755 | # Use auto.conf to trigger the test |
|---|
| .. | .. |
|---|
| 697 | 765 | /bin/false) |
|---|
| 698 | 766 | |
|---|
| 699 | 767 | endif # may-sync-config |
|---|
| 700 | | -endif # $(dot-config) |
|---|
| 768 | +endif # need-config |
|---|
| 701 | 769 | |
|---|
| 702 | 770 | KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) |
|---|
| 703 | 771 | KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) |
|---|
| 704 | 772 | KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) |
|---|
| 705 | 773 | KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) |
|---|
| 706 | | -KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context) |
|---|
| 707 | 774 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) |
|---|
| 708 | 775 | |
|---|
| 709 | | -ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE |
|---|
| 710 | | -KBUILD_CFLAGS += -Os |
|---|
| 711 | | -else |
|---|
| 712 | | -KBUILD_CFLAGS += -O2 |
|---|
| 776 | +ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE |
|---|
| 777 | +KBUILD_CFLAGS += -O2 |
|---|
| 778 | +else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 |
|---|
| 779 | +KBUILD_CFLAGS += -O3 |
|---|
| 780 | +else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE |
|---|
| 781 | +KBUILD_CFLAGS += -Os |
|---|
| 713 | 782 | endif |
|---|
| 714 | 783 | |
|---|
| 715 | 784 | # Tell gcc to never replace conditional load with a non-conditional one |
|---|
| 716 | 785 | KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) |
|---|
| 717 | 786 | KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) |
|---|
| 718 | | - |
|---|
| 719 | | -# check for 'asm goto' |
|---|
| 720 | | -ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y) |
|---|
| 721 | | - KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO |
|---|
| 722 | | - KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO |
|---|
| 723 | | -endif |
|---|
| 724 | | - |
|---|
| 725 | | -include scripts/Makefile.kcov |
|---|
| 726 | | -include scripts/Makefile.gcc-plugins |
|---|
| 727 | 787 | |
|---|
| 728 | 788 | ifdef CONFIG_READABLE_ASM |
|---|
| 729 | 789 | # Disable optimizations that make assembler listings hard to read. |
|---|
| .. | .. |
|---|
| 736 | 796 | endif |
|---|
| 737 | 797 | |
|---|
| 738 | 798 | ifneq ($(CONFIG_FRAME_WARN),0) |
|---|
| 739 | | -KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) |
|---|
| 799 | +KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) |
|---|
| 740 | 800 | endif |
|---|
| 741 | 801 | |
|---|
| 742 | | -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector |
|---|
| 802 | +stackp-flags-y := -fno-stack-protector |
|---|
| 743 | 803 | stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector |
|---|
| 744 | 804 | stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong |
|---|
| 745 | 805 | |
|---|
| 746 | 806 | KBUILD_CFLAGS += $(stackp-flags-y) |
|---|
| 747 | 807 | |
|---|
| 748 | | -ifeq ($(cc-name),clang) |
|---|
| 749 | | -KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) |
|---|
| 750 | | -KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) |
|---|
| 751 | | -KBUILD_CFLAGS += $(call cc-disable-warning, gnu) |
|---|
| 752 | | -# Quiet clang warning: comparison of unsigned expression < 0 is always false |
|---|
| 753 | | -KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare) |
|---|
| 808 | +KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror |
|---|
| 809 | +KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) |
|---|
| 810 | + |
|---|
| 811 | +ifdef CONFIG_CC_IS_CLANG |
|---|
| 812 | +KBUILD_CPPFLAGS += -Qunused-arguments |
|---|
| 813 | +KBUILD_CFLAGS += -Wno-format-invalid-specifier |
|---|
| 814 | +KBUILD_CFLAGS += -Wno-gnu |
|---|
| 754 | 815 | # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the |
|---|
| 755 | 816 | # source of a reference will be _MergedGlobals and not on of the whitelisted names. |
|---|
| 756 | 817 | # See modpost pattern 2 |
|---|
| 757 | | -KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) |
|---|
| 758 | | -KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) |
|---|
| 818 | +KBUILD_CFLAGS += -mno-global-merge |
|---|
| 819 | +else |
|---|
| 820 | + |
|---|
| 821 | +# Warn about unmarked fall-throughs in switch statement. |
|---|
| 822 | +# Disabled for clang while comment to attribute conversion happens and |
|---|
| 823 | +# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed. |
|---|
| 824 | +KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,) |
|---|
| 759 | 825 | endif |
|---|
| 760 | 826 | |
|---|
| 761 | 827 | # These warnings generated too much noise in a regular build. |
|---|
| .. | .. |
|---|
| 783 | 849 | |
|---|
| 784 | 850 | # Initialize all stack variables with a zero value. |
|---|
| 785 | 851 | ifdef CONFIG_INIT_STACK_ALL_ZERO |
|---|
| 786 | | -# Future support for zero initialization is still being debated, see |
|---|
| 787 | | -# https://bugs.llvm.org/show_bug.cgi?id=45497. These flags are subject to being |
|---|
| 788 | | -# renamed or dropped. |
|---|
| 789 | 852 | KBUILD_CFLAGS += -ftrivial-auto-var-init=zero |
|---|
| 853 | +ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER |
|---|
| 854 | +# https://github.com/llvm/llvm-project/issues/44842 |
|---|
| 790 | 855 | KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang |
|---|
| 791 | 856 | endif |
|---|
| 857 | +endif |
|---|
| 792 | 858 | |
|---|
| 793 | | -KBUILD_CFLAGS += $(call cc-option, -fno-var-tracking-assignments) |
|---|
| 859 | +DEBUG_CFLAGS := |
|---|
| 860 | + |
|---|
| 861 | +# Workaround for GCC versions < 5.0 |
|---|
| 862 | +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 |
|---|
| 863 | +ifdef CONFIG_CC_IS_GCC |
|---|
| 864 | +DEBUG_CFLAGS += $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-tracking-assignments)) |
|---|
| 865 | +endif |
|---|
| 794 | 866 | |
|---|
| 795 | 867 | ifdef CONFIG_DEBUG_INFO |
|---|
| 868 | + |
|---|
| 796 | 869 | ifdef CONFIG_DEBUG_INFO_SPLIT |
|---|
| 797 | | -KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g) |
|---|
| 870 | +DEBUG_CFLAGS += -gsplit-dwarf |
|---|
| 798 | 871 | else |
|---|
| 799 | | -KBUILD_CFLAGS += -g |
|---|
| 872 | +DEBUG_CFLAGS += -g |
|---|
| 800 | 873 | endif |
|---|
| 801 | | -ifneq ($(LLVM_IAS),1) |
|---|
| 874 | + |
|---|
| 875 | +ifeq ($(LLVM_IAS),1) |
|---|
| 876 | +KBUILD_AFLAGS += -g |
|---|
| 877 | +else |
|---|
| 802 | 878 | KBUILD_AFLAGS += -Wa,-gdwarf-2 |
|---|
| 803 | | -endif |
|---|
| 804 | 879 | endif |
|---|
| 805 | 880 | |
|---|
| 806 | 881 | ifdef CONFIG_DEBUG_INFO_DWARF4 |
|---|
| 807 | | -KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,) |
|---|
| 882 | +DEBUG_CFLAGS += -gdwarf-4 |
|---|
| 808 | 883 | endif |
|---|
| 809 | 884 | |
|---|
| 810 | 885 | ifdef CONFIG_DEBUG_INFO_REDUCED |
|---|
| 811 | | -KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ |
|---|
| 886 | +DEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ |
|---|
| 812 | 887 | $(call cc-option,-fno-var-tracking) |
|---|
| 813 | 888 | endif |
|---|
| 814 | 889 | |
|---|
| 890 | +ifdef CONFIG_DEBUG_INFO_COMPRESSED |
|---|
| 891 | +DEBUG_CFLAGS += -gz=zlib |
|---|
| 892 | +KBUILD_AFLAGS += -gz=zlib |
|---|
| 893 | +KBUILD_LDFLAGS += --compress-debug-sections=zlib |
|---|
| 894 | +endif |
|---|
| 895 | + |
|---|
| 896 | +endif # CONFIG_DEBUG_INFO |
|---|
| 897 | + |
|---|
| 898 | +KBUILD_CFLAGS += $(DEBUG_CFLAGS) |
|---|
| 899 | +export DEBUG_CFLAGS |
|---|
| 900 | + |
|---|
| 815 | 901 | ifdef CONFIG_FUNCTION_TRACER |
|---|
| 816 | | -ifdef CONFIG_FTRACE_MCOUNT_RECORD |
|---|
| 817 | | - # gcc 5 supports generating the mcount tables directly |
|---|
| 818 | | - ifeq ($(call cc-option-yn,-mrecord-mcount),y) |
|---|
| 819 | | - CC_FLAGS_FTRACE += -mrecord-mcount |
|---|
| 820 | | - export CC_USING_RECORD_MCOUNT := 1 |
|---|
| 821 | | - endif |
|---|
| 902 | +ifdef CONFIG_FTRACE_MCOUNT_USE_CC |
|---|
| 903 | + CC_FLAGS_FTRACE += -mrecord-mcount |
|---|
| 822 | 904 | ifdef CONFIG_HAVE_NOP_MCOUNT |
|---|
| 823 | 905 | ifeq ($(call cc-option-yn, -mnop-mcount),y) |
|---|
| 824 | 906 | CC_FLAGS_FTRACE += -mnop-mcount |
|---|
| 825 | 907 | CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT |
|---|
| 826 | 908 | endif |
|---|
| 909 | + endif |
|---|
| 910 | +endif |
|---|
| 911 | +ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL |
|---|
| 912 | + CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT |
|---|
| 913 | +endif |
|---|
| 914 | +ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT |
|---|
| 915 | + ifdef CONFIG_HAVE_C_RECORDMCOUNT |
|---|
| 916 | + BUILD_C_RECORDMCOUNT := y |
|---|
| 917 | + export BUILD_C_RECORDMCOUNT |
|---|
| 827 | 918 | endif |
|---|
| 828 | 919 | endif |
|---|
| 829 | 920 | ifdef CONFIG_HAVE_FENTRY |
|---|
| .. | .. |
|---|
| 835 | 926 | export CC_FLAGS_FTRACE |
|---|
| 836 | 927 | KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING) |
|---|
| 837 | 928 | KBUILD_AFLAGS += $(CC_FLAGS_USING) |
|---|
| 838 | | -ifdef CONFIG_DYNAMIC_FTRACE |
|---|
| 839 | | - ifdef CONFIG_HAVE_C_RECORDMCOUNT |
|---|
| 840 | | - BUILD_C_RECORDMCOUNT := y |
|---|
| 841 | | - export BUILD_C_RECORDMCOUNT |
|---|
| 842 | | - endif |
|---|
| 843 | | -endif |
|---|
| 844 | 929 | endif |
|---|
| 845 | 930 | |
|---|
| 846 | 931 | # We trigger additional mismatches with less inlining |
|---|
| .. | .. |
|---|
| 853 | 938 | LDFLAGS_vmlinux += --gc-sections |
|---|
| 854 | 939 | endif |
|---|
| 855 | 940 | |
|---|
| 856 | | -ifdef CONFIG_LTO_CLANG |
|---|
| 857 | | -ifdef CONFIG_THINLTO |
|---|
| 858 | | -lto-clang-flags := -flto=thin |
|---|
| 859 | | -KBUILD_LDFLAGS += --thinlto-cache-dir=.thinlto-cache |
|---|
| 860 | | -else |
|---|
| 861 | | -lto-clang-flags := -flto |
|---|
| 862 | | -endif |
|---|
| 863 | | -lto-clang-flags += -fvisibility=default $(call cc-option, -fsplit-lto-unit) |
|---|
| 864 | | - |
|---|
| 865 | | -# Limit inlining across translation units to reduce binary size |
|---|
| 866 | | -LD_FLAGS_LTO_CLANG := -mllvm -import-instr-limit=5 |
|---|
| 867 | | - |
|---|
| 868 | | -KBUILD_LDFLAGS += $(LD_FLAGS_LTO_CLANG) |
|---|
| 869 | | -KBUILD_LDFLAGS_MODULE += $(LD_FLAGS_LTO_CLANG) |
|---|
| 870 | | - |
|---|
| 871 | | -KBUILD_LDFLAGS_MODULE += -T scripts/module-lto.lds |
|---|
| 872 | | - |
|---|
| 873 | | -# allow disabling only clang LTO where needed |
|---|
| 874 | | -DISABLE_LTO_CLANG := -fno-lto |
|---|
| 875 | | -export DISABLE_LTO_CLANG |
|---|
| 876 | | -endif |
|---|
| 877 | | - |
|---|
| 878 | | -ifdef CONFIG_LTO |
|---|
| 879 | | -LTO_CFLAGS := $(lto-clang-flags) |
|---|
| 880 | | -KBUILD_CFLAGS += $(LTO_CFLAGS) |
|---|
| 881 | | - |
|---|
| 882 | | -DISABLE_LTO := $(DISABLE_LTO_CLANG) |
|---|
| 883 | | -export LTO_CFLAGS DISABLE_LTO |
|---|
| 884 | | -endif |
|---|
| 885 | | - |
|---|
| 886 | | -ifdef CONFIG_CFI_CLANG |
|---|
| 887 | | -cfi-clang-flags += -fsanitize=cfi -fno-sanitize-cfi-canonical-jump-tables \ |
|---|
| 888 | | - -fno-sanitize-blacklist |
|---|
| 889 | | -DISABLE_CFI_CLANG := -fno-sanitize=cfi |
|---|
| 890 | | -ifdef CONFIG_MODULES |
|---|
| 891 | | -cfi-clang-flags += -fsanitize-cfi-cross-dso |
|---|
| 892 | | -DISABLE_CFI_CLANG += -fno-sanitize-cfi-cross-dso |
|---|
| 893 | | -endif |
|---|
| 894 | | -ifdef CONFIG_CFI_PERMISSIVE |
|---|
| 895 | | -cfi-clang-flags += -fsanitize-recover=cfi -fno-sanitize-trap=cfi |
|---|
| 896 | | -endif |
|---|
| 897 | | - |
|---|
| 898 | | -# also disable CFI when LTO is disabled |
|---|
| 899 | | -DISABLE_LTO_CLANG += $(DISABLE_CFI_CLANG) |
|---|
| 900 | | -# allow disabling only clang CFI where needed |
|---|
| 901 | | -export DISABLE_CFI_CLANG |
|---|
| 902 | | -endif |
|---|
| 903 | | - |
|---|
| 904 | | -ifdef CONFIG_CFI |
|---|
| 905 | | -CFI_CFLAGS := $(cfi-clang-flags) |
|---|
| 906 | | -KBUILD_CFLAGS += $(CFI_CFLAGS) |
|---|
| 907 | | - |
|---|
| 908 | | -DISABLE_CFI := $(DISABLE_CFI_CLANG) |
|---|
| 909 | | -DISABLE_LTO += $(DISABLE_CFI) |
|---|
| 910 | | -export CFI_CFLAGS DISABLE_CFI |
|---|
| 911 | | -endif |
|---|
| 912 | | - |
|---|
| 913 | 941 | ifdef CONFIG_SHADOW_CALL_STACK |
|---|
| 914 | 942 | CC_FLAGS_SCS := -fsanitize=shadow-call-stack |
|---|
| 915 | 943 | KBUILD_CFLAGS += $(CC_FLAGS_SCS) |
|---|
| 916 | 944 | export CC_FLAGS_SCS |
|---|
| 917 | 945 | endif |
|---|
| 918 | 946 | |
|---|
| 947 | +ifdef CONFIG_LTO_CLANG |
|---|
| 948 | +ifdef CONFIG_LTO_CLANG_THIN |
|---|
| 949 | +CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit |
|---|
| 950 | +KBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod-prefix).thinlto-cache |
|---|
| 951 | +else |
|---|
| 952 | +CC_FLAGS_LTO := -flto |
|---|
| 953 | +endif |
|---|
| 954 | + |
|---|
| 955 | +ifeq ($(SRCARCH),x86) |
|---|
| 956 | +# TODO(b/182572011): Revert workaround for compiler / linker bug. |
|---|
| 957 | +CC_FLAGS_LTO += -fvisibility=hidden |
|---|
| 958 | +else |
|---|
| 959 | +CC_FLAGS_LTO += -fvisibility=default |
|---|
| 960 | +endif |
|---|
| 961 | + |
|---|
| 962 | +# Limit inlining across translation units to reduce binary size |
|---|
| 963 | +KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 |
|---|
| 964 | +endif |
|---|
| 965 | + |
|---|
| 966 | +ifdef CONFIG_LTO |
|---|
| 967 | +KBUILD_CFLAGS += $(CC_FLAGS_LTO) |
|---|
| 968 | +export CC_FLAGS_LTO |
|---|
| 969 | +endif |
|---|
| 970 | + |
|---|
| 971 | +ifdef CONFIG_CFI_CLANG |
|---|
| 972 | +CC_FLAGS_CFI := -fsanitize=cfi \ |
|---|
| 973 | + -fsanitize-cfi-cross-dso \ |
|---|
| 974 | + -fno-sanitize-cfi-canonical-jump-tables \ |
|---|
| 975 | + -fno-sanitize-blacklist |
|---|
| 976 | + |
|---|
| 977 | +ifdef CONFIG_CFI_PERMISSIVE |
|---|
| 978 | +CC_FLAGS_CFI += -fsanitize-recover=cfi \ |
|---|
| 979 | + -fno-sanitize-trap=cfi |
|---|
| 980 | +else |
|---|
| 981 | +ifndef CONFIG_UBSAN_TRAP |
|---|
| 982 | +CC_FLAGS_CFI += -ftrap-function=__ubsan_handle_cfi_check_fail_abort |
|---|
| 983 | +endif |
|---|
| 984 | +endif |
|---|
| 985 | + |
|---|
| 986 | +# If LTO flags are filtered out, we must also filter out CFI. |
|---|
| 987 | +CC_FLAGS_LTO += $(CC_FLAGS_CFI) |
|---|
| 988 | +KBUILD_CFLAGS += $(CC_FLAGS_CFI) |
|---|
| 989 | +export CC_FLAGS_CFI |
|---|
| 990 | +endif |
|---|
| 991 | + |
|---|
| 992 | +ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B |
|---|
| 993 | +KBUILD_CFLAGS += -falign-functions=32 |
|---|
| 994 | +endif |
|---|
| 995 | + |
|---|
| 919 | 996 | # arch Makefile may override CC so keep this after arch Makefile is included |
|---|
| 920 | 997 | NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) |
|---|
| 921 | 998 | |
|---|
| 922 | 999 | # warn about C99 declaration after statement |
|---|
| 923 | | -KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) |
|---|
| 1000 | +KBUILD_CFLAGS += -Wdeclaration-after-statement |
|---|
| 1001 | + |
|---|
| 1002 | +# Variable Length Arrays (VLAs) should not be used anywhere in the kernel |
|---|
| 1003 | +KBUILD_CFLAGS += -Wvla |
|---|
| 924 | 1004 | |
|---|
| 925 | 1005 | # disable pointer signed / unsigned warnings in gcc 4.0 |
|---|
| 926 | | -KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign) |
|---|
| 1006 | +KBUILD_CFLAGS += -Wno-pointer-sign |
|---|
| 927 | 1007 | |
|---|
| 928 | 1008 | # disable stringop warnings in gcc 8+ |
|---|
| 929 | 1009 | KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) |
|---|
| .. | .. |
|---|
| 940 | 1020 | KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized) |
|---|
| 941 | 1021 | |
|---|
| 942 | 1022 | # disable invalid "can't wrap" optimizations for signed / pointers |
|---|
| 943 | | -KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) |
|---|
| 944 | | - |
|---|
| 945 | | -# clang sets -fmerge-all-constants by default as optimization, but this |
|---|
| 946 | | -# is non-conforming behavior for C and in fact breaks the kernel, so we |
|---|
| 947 | | -# need to disable it here generally. |
|---|
| 948 | | -KBUILD_CFLAGS += $(call cc-option,-fno-merge-all-constants) |
|---|
| 949 | | - |
|---|
| 950 | | -# for gcc -fno-merge-all-constants disables everything, but it is fine |
|---|
| 951 | | -# to have actual conforming behavior enabled. |
|---|
| 952 | | -KBUILD_CFLAGS += $(call cc-option,-fmerge-constants) |
|---|
| 1023 | +KBUILD_CFLAGS += -fno-strict-overflow |
|---|
| 953 | 1024 | |
|---|
| 954 | 1025 | # Make sure -fstack-check isn't enabled (like gentoo apparently did) |
|---|
| 955 | | -KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,) |
|---|
| 1026 | +KBUILD_CFLAGS += -fno-stack-check |
|---|
| 956 | 1027 | |
|---|
| 957 | 1028 | # conserve stack if available |
|---|
| 958 | 1029 | KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) |
|---|
| 959 | 1030 | |
|---|
| 960 | | -# disallow errors like 'EXPORT_GPL(foo);' with missing header |
|---|
| 961 | | -KBUILD_CFLAGS += $(call cc-option,-Werror=implicit-int) |
|---|
| 962 | | - |
|---|
| 963 | | -# require functions to have arguments in prototypes, not empty 'int foo()' |
|---|
| 964 | | -KBUILD_CFLAGS += $(call cc-option,-Werror=strict-prototypes) |
|---|
| 965 | | - |
|---|
| 966 | 1031 | # Prohibit date/time macros, which would make the build non-deterministic |
|---|
| 967 | | -KBUILD_CFLAGS += $(call cc-option,-Werror=date-time) |
|---|
| 1032 | +KBUILD_CFLAGS += -Werror=date-time |
|---|
| 968 | 1033 | |
|---|
| 969 | 1034 | # enforce correct pointer usage |
|---|
| 970 | 1035 | KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) |
|---|
| .. | .. |
|---|
| 973 | 1038 | KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) |
|---|
| 974 | 1039 | |
|---|
| 975 | 1040 | # change __FILE__ to the relative path from the srctree |
|---|
| 976 | | -KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) |
|---|
| 1041 | +KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) |
|---|
| 977 | 1042 | |
|---|
| 978 | | -# use the deterministic mode of AR if available |
|---|
| 979 | | -KBUILD_ARFLAGS := $(call ar-option,D) |
|---|
| 1043 | +# include additional Makefiles when needed |
|---|
| 1044 | +include-y := scripts/Makefile.extrawarn |
|---|
| 1045 | +include-$(CONFIG_KASAN) += scripts/Makefile.kasan |
|---|
| 1046 | +include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan |
|---|
| 1047 | +include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan |
|---|
| 1048 | +include-$(CONFIG_KCOV) += scripts/Makefile.kcov |
|---|
| 1049 | +include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins |
|---|
| 980 | 1050 | |
|---|
| 981 | | -include scripts/Makefile.kasan |
|---|
| 982 | | -include scripts/Makefile.extrawarn |
|---|
| 983 | | -include scripts/Makefile.ubsan |
|---|
| 1051 | +include $(addprefix $(srctree)/, $(include-y)) |
|---|
| 984 | 1052 | |
|---|
| 985 | | -# Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the |
|---|
| 986 | | -# last assignments |
|---|
| 987 | | -KBUILD_CPPFLAGS += $(ARCH_CPPFLAGS) $(KCPPFLAGS) |
|---|
| 988 | | -KBUILD_AFLAGS += $(ARCH_AFLAGS) $(KAFLAGS) |
|---|
| 989 | | -KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS) |
|---|
| 1053 | +# scripts/Makefile.gcc-plugins is intentionally included last. |
|---|
| 1054 | +# Do not add $(call cc-option,...) below this line. When you build the kernel |
|---|
| 1055 | +# from the clean source tree, the GCC plugins do not exist at this point. |
|---|
| 990 | 1056 | |
|---|
| 991 | | -# Use --build-id when available. |
|---|
| 992 | | -LDFLAGS_BUILD_ID := $(call ld-option, --build-id) |
|---|
| 993 | | -KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) |
|---|
| 994 | | -LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) |
|---|
| 1057 | +# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments |
|---|
| 1058 | +KBUILD_CPPFLAGS += $(KCPPFLAGS) |
|---|
| 1059 | +KBUILD_AFLAGS += $(KAFLAGS) |
|---|
| 1060 | +KBUILD_CFLAGS += $(KCFLAGS) |
|---|
| 1061 | + |
|---|
| 1062 | +KBUILD_LDFLAGS_MODULE += --build-id=sha1 |
|---|
| 1063 | +LDFLAGS_vmlinux += --build-id=sha1 |
|---|
| 1064 | + |
|---|
| 1065 | +KBUILD_LDFLAGS += -z noexecstack |
|---|
| 1066 | +KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments) |
|---|
| 995 | 1067 | |
|---|
| 996 | 1068 | ifeq ($(CONFIG_STRIP_ASM_SYMS),y) |
|---|
| 997 | 1069 | LDFLAGS_vmlinux += $(call ld-option, -X,) |
|---|
| 998 | 1070 | endif |
|---|
| 999 | 1071 | |
|---|
| 1000 | 1072 | ifeq ($(CONFIG_RELR),y) |
|---|
| 1001 | | -LDFLAGS_vmlinux += --pack-dyn-relocs=relr |
|---|
| 1073 | +LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags |
|---|
| 1002 | 1074 | endif |
|---|
| 1075 | + |
|---|
| 1076 | +# We never want expected sections to be placed heuristically by the |
|---|
| 1077 | +# linker. All sections should be explicitly named in the linker script. |
|---|
| 1078 | +ifdef CONFIG_LD_ORPHAN_WARN |
|---|
| 1079 | +LDFLAGS_vmlinux += --orphan-handling=warn |
|---|
| 1080 | +endif |
|---|
| 1081 | + |
|---|
| 1082 | +# Align the bit size of userspace programs with the kernel |
|---|
| 1083 | +KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) |
|---|
| 1084 | +KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) |
|---|
| 1085 | + |
|---|
| 1086 | +# make the checker run with the right architecture |
|---|
| 1087 | +CHECKFLAGS += --arch=$(ARCH) |
|---|
| 1003 | 1088 | |
|---|
| 1004 | 1089 | # insure the checker run with the right endianness |
|---|
| 1005 | 1090 | CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian) |
|---|
| .. | .. |
|---|
| 1059 | 1144 | mod_compress_cmd = true |
|---|
| 1060 | 1145 | ifdef CONFIG_MODULE_COMPRESS |
|---|
| 1061 | 1146 | ifdef CONFIG_MODULE_COMPRESS_GZIP |
|---|
| 1062 | | - mod_compress_cmd = gzip -n -f |
|---|
| 1147 | + mod_compress_cmd = $(KGZIP) -n -f |
|---|
| 1063 | 1148 | endif # CONFIG_MODULE_COMPRESS_GZIP |
|---|
| 1064 | 1149 | ifdef CONFIG_MODULE_COMPRESS_XZ |
|---|
| 1065 | | - mod_compress_cmd = xz -f |
|---|
| 1150 | + mod_compress_cmd = $(XZ) -f |
|---|
| 1066 | 1151 | endif # CONFIG_MODULE_COMPRESS_XZ |
|---|
| 1067 | 1152 | endif # CONFIG_MODULE_COMPRESS |
|---|
| 1068 | 1153 | export mod_compress_cmd |
|---|
| 1069 | | - |
|---|
| 1070 | | -# Select initial ramdisk compression format, default is gzip(1). |
|---|
| 1071 | | -# This shall be used by the dracut(8) tool while creating an initramfs image. |
|---|
| 1072 | | -# |
|---|
| 1073 | | -INITRD_COMPRESS-y := gzip |
|---|
| 1074 | | -INITRD_COMPRESS-$(CONFIG_RD_BZIP2) := bzip2 |
|---|
| 1075 | | -INITRD_COMPRESS-$(CONFIG_RD_LZMA) := lzma |
|---|
| 1076 | | -INITRD_COMPRESS-$(CONFIG_RD_XZ) := xz |
|---|
| 1077 | | -INITRD_COMPRESS-$(CONFIG_RD_LZO) := lzo |
|---|
| 1078 | | -INITRD_COMPRESS-$(CONFIG_RD_LZ4) := lz4 |
|---|
| 1079 | | -# do not export INITRD_COMPRESS, since we didn't actually |
|---|
| 1080 | | -# choose a sane default compression above. |
|---|
| 1081 | | -# export INITRD_COMPRESS := $(INITRD_COMPRESS-y) |
|---|
| 1082 | 1154 | |
|---|
| 1083 | 1155 | ifdef CONFIG_MODULE_SIG_ALL |
|---|
| 1084 | 1156 | $(eval $(call config_filename,MODULE_SIG_KEY)) |
|---|
| .. | .. |
|---|
| 1091 | 1163 | |
|---|
| 1092 | 1164 | HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) |
|---|
| 1093 | 1165 | |
|---|
| 1166 | +has_libelf := $(call try-run,\ |
|---|
| 1167 | + echo "int main() {}" | \ |
|---|
| 1168 | + $(HOSTCC) $(KBUILD_HOSTCFLAGS) -xc -o /dev/null $(KBUILD_HOSTLDFLAGS) $(HOST_LIBELF_LIBS) -,1,0) |
|---|
| 1169 | + |
|---|
| 1094 | 1170 | ifdef CONFIG_STACK_VALIDATION |
|---|
| 1095 | | - has_libelf := $(call try-run,\ |
|---|
| 1096 | | - echo "int main() {}" | $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) |
|---|
| 1097 | 1171 | ifeq ($(has_libelf),1) |
|---|
| 1098 | 1172 | objtool_target := tools/objtool FORCE |
|---|
| 1099 | 1173 | else |
|---|
| .. | .. |
|---|
| 1102 | 1176 | endif |
|---|
| 1103 | 1177 | endif |
|---|
| 1104 | 1178 | |
|---|
| 1179 | +PHONY += resolve_btfids_clean |
|---|
| 1180 | + |
|---|
| 1181 | +resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids |
|---|
| 1182 | + |
|---|
| 1183 | +# tools/bpf/resolve_btfids directory might not exist |
|---|
| 1184 | +# in output directory, skip its clean in that case |
|---|
| 1185 | +resolve_btfids_clean: |
|---|
| 1186 | +ifneq ($(wildcard $(resolve_btfids_O)),) |
|---|
| 1187 | + $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean |
|---|
| 1188 | +endif |
|---|
| 1189 | + |
|---|
| 1190 | +ifdef CONFIG_BPF |
|---|
| 1191 | +ifdef CONFIG_DEBUG_INFO_BTF |
|---|
| 1192 | + ifeq ($(has_libelf),1) |
|---|
| 1193 | + resolve_btfids_target := tools/bpf/resolve_btfids FORCE |
|---|
| 1194 | + else |
|---|
| 1195 | + ERROR_RESOLVE_BTFIDS := 1 |
|---|
| 1196 | + endif |
|---|
| 1197 | +endif # CONFIG_DEBUG_INFO_BTF |
|---|
| 1198 | +endif # CONFIG_BPF |
|---|
| 1199 | + |
|---|
| 1105 | 1200 | PHONY += prepare0 |
|---|
| 1106 | 1201 | |
|---|
| 1202 | +export MODORDER := $(extmod-prefix)modules.order |
|---|
| 1203 | +export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps |
|---|
| 1204 | + |
|---|
| 1205 | +# --------------------------------------------------------------------------- |
|---|
| 1206 | +# Kernel headers |
|---|
| 1207 | + |
|---|
| 1208 | +PHONY += headers |
|---|
| 1209 | + |
|---|
| 1210 | +#Default location for installed headers |
|---|
| 1107 | 1211 | ifeq ($(KBUILD_EXTMOD),) |
|---|
| 1108 | | -core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ |
|---|
| 1212 | +PHONY += archheaders archscripts |
|---|
| 1213 | +hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj |
|---|
| 1214 | +headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts |
|---|
| 1215 | +else |
|---|
| 1216 | +hdr-prefix = $(KBUILD_EXTMOD)/ |
|---|
| 1217 | +hdr-inst := -f $(srctree)/scripts/Makefile.headersinst dst=$(KBUILD_EXTMOD)/usr/include objtree=$(objtree)/$(KBUILD_EXTMOD) obj |
|---|
| 1218 | +endif |
|---|
| 1109 | 1219 | |
|---|
| 1110 | | -vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ |
|---|
| 1220 | +export INSTALL_HDR_PATH = $(objtree)/$(hdr-prefix)usr |
|---|
| 1221 | + |
|---|
| 1222 | +quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include |
|---|
| 1223 | + cmd_headers_install = \ |
|---|
| 1224 | + mkdir -p $(INSTALL_HDR_PATH); \ |
|---|
| 1225 | + rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ |
|---|
| 1226 | + $(hdr-prefix)usr/include $(INSTALL_HDR_PATH); |
|---|
| 1227 | + |
|---|
| 1228 | +PHONY += headers_install |
|---|
| 1229 | +headers_install: headers |
|---|
| 1230 | + $(call cmd,headers_install) |
|---|
| 1231 | + |
|---|
| 1232 | +headers: |
|---|
| 1233 | +ifeq ($(KBUILD_EXTMOD),) |
|---|
| 1234 | + $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ |
|---|
| 1235 | + $(error Headers not exportable for the $(SRCARCH) architecture)) |
|---|
| 1236 | +endif |
|---|
| 1237 | + $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)include/uapi |
|---|
| 1238 | + $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)arch/$(SRCARCH)/include/uapi |
|---|
| 1239 | + |
|---|
| 1240 | +ifeq ($(KBUILD_EXTMOD),) |
|---|
| 1241 | +core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ io_uring/ |
|---|
| 1242 | + |
|---|
| 1243 | +vmlinux-dirs := $(patsubst %/,%,$(filter %/, \ |
|---|
| 1111 | 1244 | $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ |
|---|
| 1112 | | - $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y))) |
|---|
| 1245 | + $(libs-y) $(libs-m))) |
|---|
| 1113 | 1246 | |
|---|
| 1114 | | -vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ |
|---|
| 1115 | | - $(init-) $(core-) $(drivers-) $(net-) $(libs-) $(virt-)))) |
|---|
| 1247 | +vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ |
|---|
| 1248 | + $(patsubst %/,%,$(filter %/, $(core-) \ |
|---|
| 1249 | + $(drivers-) $(libs-)))) |
|---|
| 1116 | 1250 | |
|---|
| 1117 | | -init-y := $(patsubst %/, %/built-in.a, $(init-y)) |
|---|
| 1118 | | -core-y := $(patsubst %/, %/built-in.a, $(core-y)) |
|---|
| 1119 | | -drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) |
|---|
| 1120 | | -net-y := $(patsubst %/, %/built-in.a, $(net-y)) |
|---|
| 1121 | | -libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) |
|---|
| 1122 | | -libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y))) |
|---|
| 1123 | | -virt-y := $(patsubst %/, %/built-in.a, $(virt-y)) |
|---|
| 1251 | +build-dirs := $(vmlinux-dirs) |
|---|
| 1252 | +clean-dirs := $(vmlinux-alldirs) |
|---|
| 1253 | + |
|---|
| 1254 | +subdir-modorder := $(addsuffix /modules.order, $(build-dirs)) |
|---|
| 1124 | 1255 | |
|---|
| 1125 | 1256 | # Externally visible symbols (used by link-vmlinux.sh) |
|---|
| 1126 | | -export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) |
|---|
| 1127 | | -export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y2) $(drivers-y) $(net-y) $(virt-y) |
|---|
| 1128 | | -export KBUILD_VMLINUX_LIBS := $(libs-y1) |
|---|
| 1129 | | -export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds |
|---|
| 1130 | | -export LDFLAGS_vmlinux |
|---|
| 1131 | | -# used by scripts/package/Makefile |
|---|
| 1132 | | -export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Documentation include samples scripts tools) |
|---|
| 1257 | +KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y)) |
|---|
| 1258 | +KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y))) |
|---|
| 1259 | +ifdef CONFIG_MODULES |
|---|
| 1260 | +KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) |
|---|
| 1261 | +KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) |
|---|
| 1262 | +else |
|---|
| 1263 | +KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) |
|---|
| 1264 | +endif |
|---|
| 1265 | +KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) |
|---|
| 1133 | 1266 | |
|---|
| 1134 | | -vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS) |
|---|
| 1267 | +export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS |
|---|
| 1268 | +export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds |
|---|
| 1269 | +# used by scripts/Makefile.package |
|---|
| 1270 | +export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools) |
|---|
| 1271 | + |
|---|
| 1272 | +vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) |
|---|
| 1135 | 1273 | |
|---|
| 1136 | 1274 | # Recurse until adjust_autoksyms.sh is satisfied |
|---|
| 1137 | 1275 | PHONY += autoksyms_recursive |
|---|
| 1138 | | -autoksyms_recursive: $(vmlinux-deps) |
|---|
| 1139 | 1276 | ifdef CONFIG_TRIM_UNUSED_KSYMS |
|---|
| 1140 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ |
|---|
| 1141 | | - "$(MAKE) -f $(srctree)/Makefile vmlinux" |
|---|
| 1142 | | -endif |
|---|
| 1143 | | - |
|---|
| 1144 | 1277 | # For the kernel to actually contain only the needed exported symbols, |
|---|
| 1145 | 1278 | # we have to build modules as well to determine what those symbols are. |
|---|
| 1146 | 1279 | # (this can be evaluated only once include/config/auto.conf has been included) |
|---|
| 1147 | | -ifdef CONFIG_TRIM_UNUSED_KSYMS |
|---|
| 1148 | | - KBUILD_MODULES := 1 |
|---|
| 1280 | +KBUILD_MODULES := 1 |
|---|
| 1281 | + |
|---|
| 1282 | +autoksyms_recursive: descend modules.order |
|---|
| 1283 | + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ |
|---|
| 1284 | + "$(MAKE) -f $(srctree)/Makefile autoksyms_recursive" |
|---|
| 1149 | 1285 | endif |
|---|
| 1150 | 1286 | |
|---|
| 1151 | 1287 | autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h) |
|---|
| .. | .. |
|---|
| 1161 | 1297 | |
|---|
| 1162 | 1298 | # Final link of vmlinux with optional arch pass after final link |
|---|
| 1163 | 1299 | cmd_link-vmlinux = \ |
|---|
| 1164 | | - $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \ |
|---|
| 1300 | + $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ |
|---|
| 1165 | 1301 | $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) |
|---|
| 1166 | 1302 | |
|---|
| 1303 | +ifndef KBUILD_MIXED_TREE |
|---|
| 1167 | 1304 | vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE |
|---|
| 1168 | | -ifdef CONFIG_HEADERS_CHECK |
|---|
| 1169 | | - $(Q)$(MAKE) -f $(srctree)/Makefile headers_check |
|---|
| 1170 | | -endif |
|---|
| 1171 | | -ifdef CONFIG_GDB_SCRIPTS |
|---|
| 1172 | | - $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) |
|---|
| 1173 | | -endif |
|---|
| 1174 | 1305 | +$(call if_changed,link-vmlinux) |
|---|
| 1175 | | - |
|---|
| 1176 | | -# Build samples along the rest of the kernel. This needs headers_install. |
|---|
| 1177 | | -ifdef CONFIG_SAMPLES |
|---|
| 1178 | | -vmlinux-dirs += samples |
|---|
| 1179 | | -samples: headers_install |
|---|
| 1180 | 1306 | endif |
|---|
| 1307 | + |
|---|
| 1308 | +targets := vmlinux |
|---|
| 1181 | 1309 | |
|---|
| 1182 | 1310 | # The actual objects are generated when descending, |
|---|
| 1183 | 1311 | # make sure no implicit rule kicks in |
|---|
| 1184 | | -$(sort $(vmlinux-deps)): $(vmlinux-dirs) ; |
|---|
| 1312 | +$(sort $(vmlinux-deps) $(subdir-modorder)): descend ; |
|---|
| 1185 | 1313 | |
|---|
| 1186 | | -# Handle descending into subdirectories listed in $(vmlinux-dirs) |
|---|
| 1187 | | -# Preset locale variables to speed up the build process. Limit locale |
|---|
| 1188 | | -# tweaks to this spot to avoid wrong language settings when running |
|---|
| 1189 | | -# make menuconfig etc. |
|---|
| 1190 | | -# Error messages still appears in the original language |
|---|
| 1191 | | - |
|---|
| 1192 | | -PHONY += $(vmlinux-dirs) |
|---|
| 1193 | | -$(vmlinux-dirs): prepare scripts |
|---|
| 1194 | | - $(Q)$(MAKE) $(build)=$@ need-builtin=1 |
|---|
| 1195 | | - |
|---|
| 1196 | | -define filechk_kernel.release |
|---|
| 1314 | +filechk_kernel.release = \ |
|---|
| 1197 | 1315 | echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \ |
|---|
| 1198 | 1316 | $(srctree) $(BRANCH) $(KMI_GENERATION))" |
|---|
| 1199 | | -endef |
|---|
| 1200 | 1317 | |
|---|
| 1201 | 1318 | # Store (new) KERNELRELEASE string in include/config/kernel.release |
|---|
| 1202 | | -include/config/kernel.release: $(srctree)/Makefile FORCE |
|---|
| 1319 | +include/config/kernel.release: FORCE |
|---|
| 1203 | 1320 | $(call filechk,kernel.release) |
|---|
| 1204 | 1321 | |
|---|
| 1205 | 1322 | # Additional helpers built in scripts/ |
|---|
| 1206 | 1323 | # Carefully list dependencies so we do not try to build scripts twice |
|---|
| 1207 | 1324 | # in parallel |
|---|
| 1208 | 1325 | PHONY += scripts |
|---|
| 1209 | | -scripts: scripts_basic asm-generic gcc-plugins $(autoksyms_h) |
|---|
| 1326 | +scripts: scripts_basic scripts_dtc |
|---|
| 1210 | 1327 | $(Q)$(MAKE) $(build)=$(@) |
|---|
| 1211 | 1328 | |
|---|
| 1212 | 1329 | # Things we need to do before we recursively start building the kernel |
|---|
| .. | .. |
|---|
| 1215 | 1332 | # archprepare is used in arch Makefiles and when processed asm symlink, |
|---|
| 1216 | 1333 | # version.h and scripts_basic is processed / created. |
|---|
| 1217 | 1334 | |
|---|
| 1218 | | -PHONY += prepare archprepare prepare1 prepare2 prepare3 |
|---|
| 1335 | +PHONY += prepare archprepare |
|---|
| 1219 | 1336 | |
|---|
| 1220 | | -# prepare3 is used to check if we are building in a separate output directory, |
|---|
| 1221 | | -# and if so do: |
|---|
| 1222 | | -# 1) Check that make has not been executed in the kernel src $(srctree) |
|---|
| 1223 | | -prepare3: include/config/kernel.release |
|---|
| 1224 | | -ifneq ($(KBUILD_SRC),) |
|---|
| 1225 | | - @$(kecho) ' Using $(srctree) as source for kernel' |
|---|
| 1226 | | - $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \ |
|---|
| 1227 | | - echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \ |
|---|
| 1228 | | - echo >&2 " in the '$(srctree)' directory.";\ |
|---|
| 1229 | | - /bin/false; \ |
|---|
| 1230 | | - fi; |
|---|
| 1231 | | -endif |
|---|
| 1337 | +archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ |
|---|
| 1338 | + asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ |
|---|
| 1339 | + include/generated/autoconf.h |
|---|
| 1232 | 1340 | |
|---|
| 1233 | | -# prepare2 creates a makefile if using a separate output directory. |
|---|
| 1234 | | -# From this point forward, .config has been reprocessed, so any rules |
|---|
| 1235 | | -# that need to depend on updated CONFIG_* values can be checked here. |
|---|
| 1236 | | -prepare2: prepare3 outputmakefile asm-generic |
|---|
| 1237 | | - |
|---|
| 1238 | | -prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h |
|---|
| 1239 | | - $(cmd_crmodverdir) |
|---|
| 1240 | | - |
|---|
| 1241 | | -archprepare: archheaders archscripts prepare1 scripts_basic |
|---|
| 1242 | | - |
|---|
| 1243 | | -prepare0: archprepare gcc-plugins |
|---|
| 1341 | +prepare0: archprepare |
|---|
| 1342 | + $(Q)$(MAKE) $(build)=scripts/mod |
|---|
| 1244 | 1343 | $(Q)$(MAKE) $(build)=. |
|---|
| 1245 | 1344 | |
|---|
| 1246 | 1345 | # All the preparing.. |
|---|
| 1247 | | -prepare: prepare0 prepare-objtool |
|---|
| 1346 | +prepare: prepare0 prepare-objtool prepare-resolve_btfids |
|---|
| 1248 | 1347 | |
|---|
| 1249 | 1348 | # Support for using generic headers in asm-generic |
|---|
| 1349 | +asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj |
|---|
| 1350 | + |
|---|
| 1250 | 1351 | PHONY += asm-generic uapi-asm-generic |
|---|
| 1251 | 1352 | asm-generic: uapi-asm-generic |
|---|
| 1252 | | - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \ |
|---|
| 1253 | | - src=asm obj=arch/$(SRCARCH)/include/generated/asm |
|---|
| 1353 | + $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \ |
|---|
| 1354 | + generic=include/asm-generic |
|---|
| 1254 | 1355 | uapi-asm-generic: |
|---|
| 1255 | | - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \ |
|---|
| 1256 | | - src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm |
|---|
| 1356 | + $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \ |
|---|
| 1357 | + generic=include/uapi/asm-generic |
|---|
| 1257 | 1358 | |
|---|
| 1258 | | -PHONY += prepare-objtool |
|---|
| 1359 | +PHONY += prepare-objtool prepare-resolve_btfids |
|---|
| 1259 | 1360 | prepare-objtool: $(objtool_target) |
|---|
| 1260 | 1361 | ifeq ($(SKIP_STACK_VALIDATION),1) |
|---|
| 1362 | +ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL |
|---|
| 1363 | + @echo "error: Cannot generate __mcount_loc for CONFIG_DYNAMIC_FTRACE=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 |
|---|
| 1364 | + @false |
|---|
| 1365 | +endif |
|---|
| 1261 | 1366 | ifdef CONFIG_UNWINDER_ORC |
|---|
| 1262 | 1367 | @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 |
|---|
| 1263 | 1368 | @false |
|---|
| .. | .. |
|---|
| 1266 | 1371 | endif |
|---|
| 1267 | 1372 | endif |
|---|
| 1268 | 1373 | |
|---|
| 1374 | +prepare-resolve_btfids: $(resolve_btfids_target) |
|---|
| 1375 | +ifeq ($(ERROR_RESOLVE_BTFIDS),1) |
|---|
| 1376 | + @echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2 |
|---|
| 1377 | + @false |
|---|
| 1378 | +endif |
|---|
| 1269 | 1379 | # Generate some files |
|---|
| 1270 | 1380 | # --------------------------------------------------------------------------- |
|---|
| 1271 | 1381 | |
|---|
| .. | .. |
|---|
| 1283 | 1393 | echo '"$(UTS_RELEASE)" exceeds $(uts_len) characters' >&2; \ |
|---|
| 1284 | 1394 | exit 1; \ |
|---|
| 1285 | 1395 | fi; \ |
|---|
| 1286 | | - (echo \#define UTS_RELEASE \"$(UTS_RELEASE)\";) |
|---|
| 1396 | + echo \#define UTS_RELEASE \"$(UTS_RELEASE)\" |
|---|
| 1287 | 1397 | endef |
|---|
| 1288 | 1398 | |
|---|
| 1289 | 1399 | define filechk_version.h |
|---|
| 1290 | | - (echo \#define LINUX_VERSION_CODE $(shell \ |
|---|
| 1291 | | - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ |
|---|
| 1292 | | - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';) |
|---|
| 1400 | + if [ $(SUBLEVEL) -gt 255 ]; then \ |
|---|
| 1401 | + echo \#define LINUX_VERSION_CODE $(shell \ |
|---|
| 1402 | + expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \ |
|---|
| 1403 | + else \ |
|---|
| 1404 | + echo \#define LINUX_VERSION_CODE $(shell \ |
|---|
| 1405 | + expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ |
|---|
| 1406 | + fi; \ |
|---|
| 1407 | + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ |
|---|
| 1408 | + ((c) > 255 ? 255 : (c)))' |
|---|
| 1293 | 1409 | endef |
|---|
| 1294 | 1410 | |
|---|
| 1411 | +$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0) |
|---|
| 1412 | +$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0) |
|---|
| 1295 | 1413 | $(version_h): FORCE |
|---|
| 1296 | 1414 | $(call filechk,version.h) |
|---|
| 1297 | 1415 | $(Q)rm -f $(old_version_h) |
|---|
| .. | .. |
|---|
| 1304 | 1422 | $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ |
|---|
| 1305 | 1423 | $(srctree)/scripts/headerdep.pl -I$(srctree)/include |
|---|
| 1306 | 1424 | |
|---|
| 1307 | | -# --------------------------------------------------------------------------- |
|---|
| 1308 | | -# Kernel headers |
|---|
| 1309 | | - |
|---|
| 1310 | | -#Default location for installed headers |
|---|
| 1311 | | -export INSTALL_HDR_PATH = $(objtree)/usr |
|---|
| 1312 | | - |
|---|
| 1313 | | -# If we do an all arch process set dst to include/arch-$(SRCARCH) |
|---|
| 1314 | | -hdr-dst = $(if $(KBUILD_HEADERS), dst=include/arch-$(SRCARCH), dst=include) |
|---|
| 1315 | | - |
|---|
| 1316 | | -PHONY += archheaders |
|---|
| 1317 | | -archheaders: |
|---|
| 1318 | | - |
|---|
| 1319 | | -PHONY += archscripts |
|---|
| 1320 | | -archscripts: |
|---|
| 1321 | | - |
|---|
| 1322 | | -PHONY += __headers |
|---|
| 1323 | | -__headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts |
|---|
| 1324 | | - $(Q)$(MAKE) $(build)=scripts build_unifdef |
|---|
| 1325 | | - |
|---|
| 1326 | | -PHONY += headers_install_all |
|---|
| 1327 | | -headers_install_all: |
|---|
| 1328 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install |
|---|
| 1329 | | - |
|---|
| 1330 | | -PHONY += headers_install |
|---|
| 1331 | | -headers_install: __headers |
|---|
| 1332 | | - $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ |
|---|
| 1333 | | - $(error Headers not exportable for the $(SRCARCH) architecture)) |
|---|
| 1334 | | - $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include |
|---|
| 1335 | | - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) |
|---|
| 1336 | | - |
|---|
| 1337 | | -PHONY += headers_check_all |
|---|
| 1338 | | -headers_check_all: headers_install_all |
|---|
| 1339 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check |
|---|
| 1340 | | - |
|---|
| 1425 | +# Deprecated. It is no-op now. |
|---|
| 1341 | 1426 | PHONY += headers_check |
|---|
| 1342 | | -headers_check: headers_install |
|---|
| 1343 | | - $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1 |
|---|
| 1344 | | - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) HDRCHECK=1 |
|---|
| 1427 | +headers_check: |
|---|
| 1428 | + @: |
|---|
| 1429 | + |
|---|
| 1430 | +ifdef CONFIG_HEADERS_INSTALL |
|---|
| 1431 | +prepare: headers |
|---|
| 1432 | +endif |
|---|
| 1433 | + |
|---|
| 1434 | +PHONY += scripts_unifdef |
|---|
| 1435 | +scripts_unifdef: scripts_basic |
|---|
| 1436 | + $(Q)$(MAKE) $(build)=scripts scripts/unifdef |
|---|
| 1345 | 1437 | |
|---|
| 1346 | 1438 | # --------------------------------------------------------------------------- |
|---|
| 1347 | 1439 | # Kernel selftest |
|---|
| .. | .. |
|---|
| 1350 | 1442 | kselftest: |
|---|
| 1351 | 1443 | $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests |
|---|
| 1352 | 1444 | |
|---|
| 1353 | | -PHONY += kselftest-clean |
|---|
| 1354 | | -kselftest-clean: |
|---|
| 1355 | | - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests clean |
|---|
| 1445 | +kselftest-%: FORCE |
|---|
| 1446 | + $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* |
|---|
| 1356 | 1447 | |
|---|
| 1357 | 1448 | PHONY += kselftest-merge |
|---|
| 1358 | 1449 | kselftest-merge: |
|---|
| 1359 | 1450 | $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) |
|---|
| 1360 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \ |
|---|
| 1361 | | - -m $(objtree)/.config \ |
|---|
| 1362 | | - $(srctree)/tools/testing/selftests/*/config |
|---|
| 1363 | | - +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig |
|---|
| 1451 | + $(Q)find $(srctree)/tools/testing/selftests -name config | \ |
|---|
| 1452 | + xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config |
|---|
| 1453 | + $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig |
|---|
| 1454 | + |
|---|
| 1455 | +# --------------------------------------------------------------------------- |
|---|
| 1456 | +# Devicetree files |
|---|
| 1457 | + |
|---|
| 1458 | +ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),) |
|---|
| 1459 | +dtstree := arch/$(SRCARCH)/boot/dts |
|---|
| 1460 | +endif |
|---|
| 1461 | + |
|---|
| 1462 | +ifneq ($(dtstree),) |
|---|
| 1463 | + |
|---|
| 1464 | +%.dtb: include/config/kernel.release scripts_dtc |
|---|
| 1465 | + $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ |
|---|
| 1466 | + |
|---|
| 1467 | +PHONY += dtbs dtbs_install dtbs_check |
|---|
| 1468 | +dtbs: include/config/kernel.release scripts_dtc |
|---|
| 1469 | + $(Q)$(MAKE) $(build)=$(dtstree) |
|---|
| 1470 | + |
|---|
| 1471 | +ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),) |
|---|
| 1472 | +export CHECK_DTBS=y |
|---|
| 1473 | +dtbs: dt_binding_check |
|---|
| 1474 | +endif |
|---|
| 1475 | + |
|---|
| 1476 | +dtbs_check: dtbs |
|---|
| 1477 | + |
|---|
| 1478 | +dtbs_install: |
|---|
| 1479 | + $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH) |
|---|
| 1480 | + |
|---|
| 1481 | +ifdef CONFIG_OF_EARLY_FLATTREE |
|---|
| 1482 | +all: dtbs |
|---|
| 1483 | +endif |
|---|
| 1484 | + |
|---|
| 1485 | +endif |
|---|
| 1486 | + |
|---|
| 1487 | +PHONY += scripts_dtc |
|---|
| 1488 | +scripts_dtc: scripts_basic |
|---|
| 1489 | + $(Q)$(MAKE) $(build)=scripts/dtc |
|---|
| 1490 | + |
|---|
| 1491 | +ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),) |
|---|
| 1492 | +export CHECK_DT_BINDING=y |
|---|
| 1493 | +endif |
|---|
| 1494 | + |
|---|
| 1495 | +PHONY += dt_binding_check |
|---|
| 1496 | +dt_binding_check: scripts_dtc |
|---|
| 1497 | + $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings |
|---|
| 1364 | 1498 | |
|---|
| 1365 | 1499 | # --------------------------------------------------------------------------- |
|---|
| 1366 | 1500 | # Modules |
|---|
| .. | .. |
|---|
| 1385 | 1519 | # using awk while concatenating to the final file. |
|---|
| 1386 | 1520 | |
|---|
| 1387 | 1521 | PHONY += modules |
|---|
| 1388 | | -modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin |
|---|
| 1389 | | - $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order |
|---|
| 1390 | | - @$(kecho) ' Building modules, stage 2.'; |
|---|
| 1522 | +# if KBUILD_BUILTIN && !KBUILD_MIXED_TREE, depend on vmlinux |
|---|
| 1523 | +modules: $(if $(KBUILD_BUILTIN), $(if $(KBUILD_MIXED_TREE),,vmlinux)) |
|---|
| 1524 | +modules: modules_check modules_prepare |
|---|
| 1391 | 1525 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
|---|
| 1392 | 1526 | |
|---|
| 1393 | | -modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) |
|---|
| 1394 | | - $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin |
|---|
| 1527 | +PHONY += modules_check |
|---|
| 1528 | +modules_check: modules.order |
|---|
| 1529 | + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< |
|---|
| 1395 | 1530 | |
|---|
| 1396 | | -%/modules.builtin: include/config/auto.conf include/config/tristate.conf |
|---|
| 1397 | | - $(Q)$(MAKE) $(modbuiltin)=$* |
|---|
| 1531 | +cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@ |
|---|
| 1398 | 1532 | |
|---|
| 1533 | +modules.order: $(subdir-modorder) FORCE |
|---|
| 1534 | + $(call if_changed,modules_order) |
|---|
| 1535 | + |
|---|
| 1536 | +targets += modules.order |
|---|
| 1399 | 1537 | |
|---|
| 1400 | 1538 | # Target to prepare building external modules |
|---|
| 1401 | 1539 | PHONY += modules_prepare |
|---|
| 1402 | | -modules_prepare: prepare scripts |
|---|
| 1540 | +modules_prepare: prepare |
|---|
| 1541 | + $(Q)$(MAKE) $(build)=scripts scripts/module.lds |
|---|
| 1403 | 1542 | |
|---|
| 1404 | 1543 | # Target to install modules |
|---|
| 1405 | 1544 | PHONY += modules_install |
|---|
| .. | .. |
|---|
| 1415 | 1554 | rm -f $(MODLIB)/build ; \ |
|---|
| 1416 | 1555 | ln -s $(CURDIR) $(MODLIB)/build ; \ |
|---|
| 1417 | 1556 | fi |
|---|
| 1418 | | - @cp -f $(objtree)/modules.order $(MODLIB)/ |
|---|
| 1419 | | - @cp -f $(objtree)/modules.builtin $(MODLIB)/ |
|---|
| 1557 | + @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order |
|---|
| 1558 | + @cp -f $(mixed-build-prefix)modules.builtin $(MODLIB)/ |
|---|
| 1559 | + @cp -f $(or $(mixed-build-prefix),$(objtree)/)modules.builtin.modinfo $(MODLIB)/ |
|---|
| 1420 | 1560 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst |
|---|
| 1421 | 1561 | |
|---|
| 1422 | 1562 | # This depmod is only for convenience to give the initial |
|---|
| .. | .. |
|---|
| 1456 | 1596 | # make distclean Remove editor backup files, patch leftover files and the like |
|---|
| 1457 | 1597 | |
|---|
| 1458 | 1598 | # Directories & files removed with 'make clean' |
|---|
| 1459 | | -CLEAN_DIRS += $(MODVERDIR) include/ksym |
|---|
| 1599 | +CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \ |
|---|
| 1600 | + modules.builtin modules.builtin.modinfo modules.nsdeps \ |
|---|
| 1601 | + compile_commands.json .thinlto-cache |
|---|
| 1460 | 1602 | |
|---|
| 1461 | 1603 | # Directories & files removed with 'make mrproper' |
|---|
| 1462 | | -MRPROPER_DIRS += include/config usr/include include/generated \ |
|---|
| 1463 | | - arch/*/include/generated .tmp_objdiff |
|---|
| 1464 | | -MRPROPER_FILES += .config .config.old .version \ |
|---|
| 1465 | | - Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ |
|---|
| 1604 | +MRPROPER_FILES += include/config include/generated \ |
|---|
| 1605 | + arch/$(SRCARCH)/include/generated .tmp_objdiff \ |
|---|
| 1606 | + debian snap tar-install \ |
|---|
| 1607 | + .config .config.old .version \ |
|---|
| 1608 | + Module.symvers \ |
|---|
| 1466 | 1609 | signing_key.pem signing_key.priv signing_key.x509 \ |
|---|
| 1467 | 1610 | x509.genkey extra_certificates signing_key.x509.keyid \ |
|---|
| 1468 | | - signing_key.x509.signer vmlinux-gdb.py |
|---|
| 1611 | + signing_key.x509.signer vmlinux-gdb.py \ |
|---|
| 1612 | + *.spec |
|---|
| 1613 | + |
|---|
| 1614 | +# Directories & files removed with 'make distclean' |
|---|
| 1615 | +DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS |
|---|
| 1469 | 1616 | |
|---|
| 1470 | 1617 | # clean - Delete most, but leave enough to build external modules |
|---|
| 1471 | 1618 | # |
|---|
| 1472 | | -clean: rm-dirs := $(CLEAN_DIRS) |
|---|
| 1473 | 1619 | clean: rm-files := $(CLEAN_FILES) |
|---|
| 1474 | | -clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation samples) |
|---|
| 1475 | 1620 | |
|---|
| 1476 | | -PHONY += $(clean-dirs) clean archclean vmlinuxclean |
|---|
| 1477 | | -$(clean-dirs): |
|---|
| 1478 | | - $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) |
|---|
| 1621 | +PHONY += archclean vmlinuxclean |
|---|
| 1479 | 1622 | |
|---|
| 1480 | 1623 | vmlinuxclean: |
|---|
| 1481 | 1624 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean |
|---|
| 1482 | 1625 | $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) |
|---|
| 1483 | 1626 | |
|---|
| 1484 | | -clean: archclean vmlinuxclean |
|---|
| 1627 | +clean: archclean vmlinuxclean resolve_btfids_clean |
|---|
| 1485 | 1628 | |
|---|
| 1486 | 1629 | # mrproper - Delete all generated files, including .config |
|---|
| 1487 | 1630 | # |
|---|
| 1488 | | -mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) |
|---|
| 1489 | 1631 | mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) |
|---|
| 1490 | 1632 | mrproper-dirs := $(addprefix _mrproper_,scripts) |
|---|
| 1491 | 1633 | |
|---|
| 1492 | | -PHONY += $(mrproper-dirs) mrproper archmrproper |
|---|
| 1634 | +PHONY += $(mrproper-dirs) mrproper |
|---|
| 1493 | 1635 | $(mrproper-dirs): |
|---|
| 1494 | 1636 | $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) |
|---|
| 1495 | 1637 | |
|---|
| 1496 | | -mrproper: clean archmrproper $(mrproper-dirs) |
|---|
| 1497 | | - $(call cmd,rmdirs) |
|---|
| 1638 | +mrproper: clean $(mrproper-dirs) |
|---|
| 1498 | 1639 | $(call cmd,rmfiles) |
|---|
| 1499 | 1640 | |
|---|
| 1500 | 1641 | # distclean |
|---|
| 1501 | 1642 | # |
|---|
| 1643 | +distclean: rm-files := $(wildcard $(DISTCLEAN_FILES)) |
|---|
| 1644 | + |
|---|
| 1502 | 1645 | PHONY += distclean |
|---|
| 1503 | 1646 | |
|---|
| 1504 | 1647 | distclean: mrproper |
|---|
| 1648 | + $(call cmd,rmfiles) |
|---|
| 1505 | 1649 | @find $(srctree) $(RCS_FIND_IGNORE) \ |
|---|
| 1506 | 1650 | \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ |
|---|
| 1507 | 1651 | -o -name '*.bak' -o -name '#*#' -o -name '*%' \ |
|---|
| .. | .. |
|---|
| 1511 | 1655 | |
|---|
| 1512 | 1656 | # Packaging of the kernel to various formats |
|---|
| 1513 | 1657 | # --------------------------------------------------------------------------- |
|---|
| 1514 | | -package-dir := scripts/package |
|---|
| 1515 | 1658 | |
|---|
| 1516 | 1659 | %src-pkg: FORCE |
|---|
| 1517 | | - $(Q)$(MAKE) $(build)=$(package-dir) $@ |
|---|
| 1660 | + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ |
|---|
| 1518 | 1661 | %pkg: include/config/kernel.release FORCE |
|---|
| 1519 | | - $(Q)$(MAKE) $(build)=$(package-dir) $@ |
|---|
| 1520 | | - |
|---|
| 1662 | + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ |
|---|
| 1521 | 1663 | |
|---|
| 1522 | 1664 | # Brief documentation of the typical targets used |
|---|
| 1523 | 1665 | # --------------------------------------------------------------------------- |
|---|
| .. | .. |
|---|
| 1562 | 1704 | echo '' |
|---|
| 1563 | 1705 | @echo 'Static analysers:' |
|---|
| 1564 | 1706 | @echo ' checkstack - Generate a list of stack hogs' |
|---|
| 1565 | | - @echo ' namespacecheck - Name space analysis on compiled kernel' |
|---|
| 1566 | 1707 | @echo ' versioncheck - Sanity check on version.h usage' |
|---|
| 1567 | 1708 | @echo ' includecheck - Check for duplicate included header files' |
|---|
| 1568 | 1709 | @echo ' export_report - List the usages of all exported symbols' |
|---|
| 1569 | | - @echo ' headers_check - Sanity check on exported headers' |
|---|
| 1570 | 1710 | @echo ' headerdep - Detect inclusion cycles in headers' |
|---|
| 1571 | 1711 | @echo ' coccicheck - Check with Coccinelle' |
|---|
| 1712 | + @echo ' clang-analyzer - Check with clang static analyzer' |
|---|
| 1713 | + @echo ' clang-tidy - Check with clang-tidy' |
|---|
| 1714 | + @echo '' |
|---|
| 1715 | + @echo 'Tools:' |
|---|
| 1716 | + @echo ' nsdeps - Generate missing symbol namespace dependencies' |
|---|
| 1572 | 1717 | @echo '' |
|---|
| 1573 | 1718 | @echo 'Kernel selftest:' |
|---|
| 1574 | | - @echo ' kselftest - Build and run kernel selftest (run as root)' |
|---|
| 1575 | | - @echo ' Build, install, and boot kernel before' |
|---|
| 1576 | | - @echo ' running kselftest on it' |
|---|
| 1577 | | - @echo ' kselftest-clean - Remove all generated kselftest files' |
|---|
| 1578 | | - @echo ' kselftest-merge - Merge all the config dependencies of kselftest to existing' |
|---|
| 1579 | | - @echo ' .config.' |
|---|
| 1719 | + @echo ' kselftest - Build and run kernel selftest' |
|---|
| 1720 | + @echo ' Build, install, and boot kernel before' |
|---|
| 1721 | + @echo ' running kselftest on it' |
|---|
| 1722 | + @echo ' Run as root for full coverage' |
|---|
| 1723 | + @echo ' kselftest-all - Build kernel selftest' |
|---|
| 1724 | + @echo ' kselftest-install - Build and install kernel selftest' |
|---|
| 1725 | + @echo ' kselftest-clean - Remove all generated kselftest files' |
|---|
| 1726 | + @echo ' kselftest-merge - Merge all the config dependencies of' |
|---|
| 1727 | + @echo ' kselftest to existing .config.' |
|---|
| 1580 | 1728 | @echo '' |
|---|
| 1729 | + @$(if $(dtstree), \ |
|---|
| 1730 | + echo 'Devicetree:'; \ |
|---|
| 1731 | + echo '* dtbs - Build device tree blobs for enabled boards'; \ |
|---|
| 1732 | + echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \ |
|---|
| 1733 | + echo ' dt_binding_check - Validate device tree binding documents'; \ |
|---|
| 1734 | + echo ' dtbs_check - Validate device tree source files';\ |
|---|
| 1735 | + echo '') |
|---|
| 1736 | + |
|---|
| 1581 | 1737 | @echo 'Userspace tools targets:' |
|---|
| 1582 | 1738 | @echo ' use "make tools/help"' |
|---|
| 1583 | 1739 | @echo ' or "cd tools; make help"' |
|---|
| 1584 | 1740 | @echo '' |
|---|
| 1585 | 1741 | @echo 'Kernel packaging:' |
|---|
| 1586 | | - @$(MAKE) $(build)=$(package-dir) help |
|---|
| 1742 | + @$(MAKE) -f $(srctree)/scripts/Makefile.package help |
|---|
| 1587 | 1743 | @echo '' |
|---|
| 1588 | 1744 | @echo 'Documentation targets:' |
|---|
| 1589 | 1745 | @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp |
|---|
| .. | .. |
|---|
| 1594 | 1750 | @echo '' |
|---|
| 1595 | 1751 | @$(if $(boards), \ |
|---|
| 1596 | 1752 | $(foreach b, $(boards), \ |
|---|
| 1597 | | - printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ |
|---|
| 1753 | + printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ |
|---|
| 1598 | 1754 | echo '') |
|---|
| 1599 | 1755 | @$(if $(board-dirs), \ |
|---|
| 1600 | 1756 | $(foreach b, $(board-dirs), \ |
|---|
| .. | .. |
|---|
| 1605 | 1761 | @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' |
|---|
| 1606 | 1762 | @echo ' make V=2 [targets] 2 => give reason for rebuild of target' |
|---|
| 1607 | 1763 | @echo ' make O=dir [targets] Locate all output files in "dir", including .config' |
|---|
| 1608 | | - @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK (sparse by default)' |
|---|
| 1764 | + @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' |
|---|
| 1765 | + @echo ' (sparse by default)' |
|---|
| 1609 | 1766 | @echo ' make C=2 [targets] Force check of all c source with $$CHECK' |
|---|
| 1610 | 1767 | @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' |
|---|
| 1611 | | - @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where' |
|---|
| 1768 | + @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where' |
|---|
| 1612 | 1769 | @echo ' 1: warnings which may be relevant and do not occur too often' |
|---|
| 1613 | 1770 | @echo ' 2: warnings which occur quite often but may still be relevant' |
|---|
| 1614 | 1771 | @echo ' 3: more obscure warnings, can most likely be ignored' |
|---|
| .. | .. |
|---|
| 1637 | 1794 | DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ |
|---|
| 1638 | 1795 | linkcheckdocs dochelp refcheckdocs |
|---|
| 1639 | 1796 | PHONY += $(DOC_TARGETS) |
|---|
| 1640 | | -$(DOC_TARGETS): scripts_basic FORCE |
|---|
| 1797 | +$(DOC_TARGETS): |
|---|
| 1641 | 1798 | $(Q)$(MAKE) $(build)=Documentation $@ |
|---|
| 1799 | + |
|---|
| 1800 | +# Misc |
|---|
| 1801 | +# --------------------------------------------------------------------------- |
|---|
| 1802 | + |
|---|
| 1803 | +PHONY += scripts_gdb |
|---|
| 1804 | +scripts_gdb: prepare0 |
|---|
| 1805 | + $(Q)$(MAKE) $(build)=scripts/gdb |
|---|
| 1806 | + $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) |
|---|
| 1807 | + |
|---|
| 1808 | +ifdef CONFIG_GDB_SCRIPTS |
|---|
| 1809 | +all: scripts_gdb |
|---|
| 1810 | +endif |
|---|
| 1642 | 1811 | |
|---|
| 1643 | 1812 | else # KBUILD_EXTMOD |
|---|
| 1644 | 1813 | |
|---|
| .. | .. |
|---|
| 1659 | 1828 | # Install the modules built in the module directory |
|---|
| 1660 | 1829 | # Assumes install directory is already created |
|---|
| 1661 | 1830 | |
|---|
| 1662 | | -# We are always building modules |
|---|
| 1831 | +# We are always building only modules. |
|---|
| 1832 | +KBUILD_BUILTIN := |
|---|
| 1663 | 1833 | KBUILD_MODULES := 1 |
|---|
| 1664 | 1834 | |
|---|
| 1665 | | -PHONY += $(objtree)/Module.symvers |
|---|
| 1666 | | -$(objtree)/Module.symvers: |
|---|
| 1667 | | - @test -e $(objtree)/Module.symvers || ( \ |
|---|
| 1668 | | - echo; \ |
|---|
| 1669 | | - echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \ |
|---|
| 1670 | | - echo " is missing; modules will have no dependencies and modversions."; \ |
|---|
| 1671 | | - echo ) |
|---|
| 1672 | | - |
|---|
| 1673 | | -module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD)) |
|---|
| 1674 | | -PHONY += $(module-dirs) modules |
|---|
| 1675 | | -$(module-dirs): prepare $(objtree)/Module.symvers |
|---|
| 1676 | | - $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) |
|---|
| 1677 | | - |
|---|
| 1678 | | -modules: $(module-dirs) |
|---|
| 1679 | | - @$(kecho) ' Building modules, stage 2.'; |
|---|
| 1835 | +build-dirs := $(KBUILD_EXTMOD) |
|---|
| 1836 | +PHONY += modules |
|---|
| 1837 | +modules: $(MODORDER) |
|---|
| 1680 | 1838 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
|---|
| 1839 | + |
|---|
| 1840 | +$(MODORDER): descend |
|---|
| 1841 | + @: |
|---|
| 1681 | 1842 | |
|---|
| 1682 | 1843 | PHONY += modules_install |
|---|
| 1683 | 1844 | modules_install: _emodinst_ _emodinst_post |
|---|
| .. | .. |
|---|
| 1692 | 1853 | _emodinst_post: _emodinst_ |
|---|
| 1693 | 1854 | $(call cmd,depmod) |
|---|
| 1694 | 1855 | |
|---|
| 1695 | | -clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD)) |
|---|
| 1856 | +compile_commands.json: $(extmod-prefix)compile_commands.json |
|---|
| 1857 | +PHONY += compile_commands.json |
|---|
| 1696 | 1858 | |
|---|
| 1697 | | -PHONY += $(clean-dirs) clean |
|---|
| 1698 | | -$(clean-dirs): |
|---|
| 1699 | | - $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) |
|---|
| 1700 | | - |
|---|
| 1701 | | -clean: rm-dirs := $(MODVERDIR) |
|---|
| 1702 | | -clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers |
|---|
| 1859 | +clean-dirs := $(KBUILD_EXTMOD) |
|---|
| 1860 | +clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ |
|---|
| 1861 | + $(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache |
|---|
| 1703 | 1862 | |
|---|
| 1704 | 1863 | PHONY += help |
|---|
| 1705 | 1864 | help: |
|---|
| .. | .. |
|---|
| 1708 | 1867 | @echo '' |
|---|
| 1709 | 1868 | @echo ' modules - default target, build the module(s)' |
|---|
| 1710 | 1869 | @echo ' modules_install - install the module' |
|---|
| 1870 | + @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH' |
|---|
| 1871 | + @echo ' (default: $(abspath $(INSTALL_HDR_PATH)))' |
|---|
| 1711 | 1872 | @echo ' clean - remove generated files in module directory only' |
|---|
| 1712 | 1873 | @echo '' |
|---|
| 1713 | 1874 | |
|---|
| 1714 | | -# Dummies... |
|---|
| 1715 | | -PHONY += prepare scripts |
|---|
| 1716 | | -prepare: |
|---|
| 1717 | | - $(cmd_crmodverdir) |
|---|
| 1718 | | -scripts: ; |
|---|
| 1875 | +# no-op for external module builds |
|---|
| 1876 | +PHONY += prepare modules_prepare |
|---|
| 1877 | + |
|---|
| 1719 | 1878 | endif # KBUILD_EXTMOD |
|---|
| 1720 | 1879 | |
|---|
| 1880 | +# Single targets |
|---|
| 1881 | +# --------------------------------------------------------------------------- |
|---|
| 1882 | +# To build individual files in subdirectories, you can do like this: |
|---|
| 1883 | +# |
|---|
| 1884 | +# make foo/bar/baz.s |
|---|
| 1885 | +# |
|---|
| 1886 | +# The supported suffixes for single-target are listed in 'single-targets' |
|---|
| 1887 | +# |
|---|
| 1888 | +# To build only under specific subdirectories, you can do like this: |
|---|
| 1889 | +# |
|---|
| 1890 | +# make foo/bar/baz/ |
|---|
| 1891 | + |
|---|
| 1892 | +ifdef single-build |
|---|
| 1893 | + |
|---|
| 1894 | +# .ko is special because modpost is needed |
|---|
| 1895 | +single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) |
|---|
| 1896 | +single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS))) |
|---|
| 1897 | + |
|---|
| 1898 | +$(single-ko): single_modpost |
|---|
| 1899 | + @: |
|---|
| 1900 | +$(single-no-ko): descend |
|---|
| 1901 | + @: |
|---|
| 1902 | + |
|---|
| 1903 | +ifeq ($(KBUILD_EXTMOD),) |
|---|
| 1904 | +# For the single build of in-tree modules, use a temporary file to avoid |
|---|
| 1905 | +# the situation of modules_install installing an invalid modules.order. |
|---|
| 1906 | +MODORDER := .modules.tmp |
|---|
| 1907 | +endif |
|---|
| 1908 | + |
|---|
| 1909 | +PHONY += single_modpost |
|---|
| 1910 | +single_modpost: $(single-no-ko) modules_prepare |
|---|
| 1911 | + $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER) |
|---|
| 1912 | + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
|---|
| 1913 | + |
|---|
| 1914 | +KBUILD_MODULES := 1 |
|---|
| 1915 | + |
|---|
| 1916 | +export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko)) |
|---|
| 1917 | + |
|---|
| 1918 | +# trim unrelated directories |
|---|
| 1919 | +build-dirs := $(foreach d, $(build-dirs), \ |
|---|
| 1920 | + $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d))) |
|---|
| 1921 | + |
|---|
| 1922 | +endif |
|---|
| 1923 | + |
|---|
| 1924 | +ifndef CONFIG_MODULES |
|---|
| 1925 | +KBUILD_MODULES := |
|---|
| 1926 | +endif |
|---|
| 1927 | + |
|---|
| 1928 | +# Handle descending into subdirectories listed in $(build-dirs) |
|---|
| 1929 | +# Preset locale variables to speed up the build process. Limit locale |
|---|
| 1930 | +# tweaks to this spot to avoid wrong language settings when running |
|---|
| 1931 | +# make menuconfig etc. |
|---|
| 1932 | +# Error messages still appears in the original language |
|---|
| 1933 | +PHONY += descend $(build-dirs) |
|---|
| 1934 | +descend: $(build-dirs) |
|---|
| 1935 | +$(build-dirs): prepare |
|---|
| 1936 | + $(Q)$(MAKE) $(build)=$@ \ |
|---|
| 1937 | + single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \ |
|---|
| 1938 | + $(if $(KBUILD_MIXED_TREE),,need-builtin=1) need-modorder=1 |
|---|
| 1939 | + |
|---|
| 1940 | +clean-dirs := $(addprefix _clean_, $(clean-dirs)) |
|---|
| 1941 | +PHONY += $(clean-dirs) clean |
|---|
| 1942 | +$(clean-dirs): |
|---|
| 1943 | + $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) |
|---|
| 1944 | + |
|---|
| 1721 | 1945 | clean: $(clean-dirs) |
|---|
| 1722 | | - $(call cmd,rmdirs) |
|---|
| 1723 | 1946 | $(call cmd,rmfiles) |
|---|
| 1724 | 1947 | @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ |
|---|
| 1725 | 1948 | \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \ |
|---|
| 1726 | | - -o -name '*.ko.*' -o -name '*.dtb' -o -name '*.dtb.S' \ |
|---|
| 1949 | + -o -name '*.ko.*' \ |
|---|
| 1950 | + -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \ |
|---|
| 1727 | 1951 | -o -name '*.dwo' -o -name '*.lst' \ |
|---|
| 1728 | | - -o -name '*.su' \ |
|---|
| 1952 | + -o -name '*.su' -o -name '*.mod' \ |
|---|
| 1729 | 1953 | -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ |
|---|
| 1730 | 1954 | -o -name '*.lex.c' -o -name '*.tab.[ch]' \ |
|---|
| 1731 | 1955 | -o -name '*.asn1.[ch]' \ |
|---|
| 1732 | 1956 | -o -name '*.symtypes' -o -name 'modules.order' \ |
|---|
| 1733 | | - -o -name modules.builtin -o -name '.tmp_*.o.*' \ |
|---|
| 1957 | + -o -name '.tmp_*.o.*' \ |
|---|
| 1734 | 1958 | -o -name '*.c.[012]*.*' \ |
|---|
| 1735 | 1959 | -o -name '*.ll' \ |
|---|
| 1736 | 1960 | -o -name '*.gcno' \ |
|---|
| .. | .. |
|---|
| 1739 | 1963 | # Generate tags for editors |
|---|
| 1740 | 1964 | # --------------------------------------------------------------------------- |
|---|
| 1741 | 1965 | quiet_cmd_tags = GEN $@ |
|---|
| 1742 | | - cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ |
|---|
| 1966 | + cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@ |
|---|
| 1743 | 1967 | |
|---|
| 1744 | 1968 | tags TAGS cscope gtags: FORCE |
|---|
| 1745 | 1969 | $(call cmd,tags) |
|---|
| 1746 | 1970 | |
|---|
| 1971 | +# Script to generate missing namespace dependencies |
|---|
| 1972 | +# --------------------------------------------------------------------------- |
|---|
| 1973 | + |
|---|
| 1974 | +PHONY += nsdeps |
|---|
| 1975 | +nsdeps: export KBUILD_NSDEPS=1 |
|---|
| 1976 | +nsdeps: modules |
|---|
| 1977 | + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps |
|---|
| 1978 | + |
|---|
| 1979 | +# Clang Tooling |
|---|
| 1980 | +# --------------------------------------------------------------------------- |
|---|
| 1981 | + |
|---|
| 1982 | +quiet_cmd_gen_compile_commands = GEN $@ |
|---|
| 1983 | + cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) |
|---|
| 1984 | + |
|---|
| 1985 | +$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \ |
|---|
| 1986 | + $(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \ |
|---|
| 1987 | + $(if $(CONFIG_MODULES), $(MODORDER)) FORCE |
|---|
| 1988 | + $(call if_changed,gen_compile_commands) |
|---|
| 1989 | + |
|---|
| 1990 | +targets += $(extmod-prefix)compile_commands.json |
|---|
| 1991 | + |
|---|
| 1992 | +PHONY += clang-tidy clang-analyzer |
|---|
| 1993 | + |
|---|
| 1994 | +ifdef CONFIG_CC_IS_CLANG |
|---|
| 1995 | +quiet_cmd_clang_tools = CHECK $< |
|---|
| 1996 | + cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< |
|---|
| 1997 | + |
|---|
| 1998 | +clang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json |
|---|
| 1999 | + $(call cmd,clang_tools) |
|---|
| 2000 | +else |
|---|
| 2001 | +clang-tidy clang-analyzer: |
|---|
| 2002 | + @echo "$@ requires CC=clang" >&2 |
|---|
| 2003 | + @false |
|---|
| 2004 | +endif |
|---|
| 2005 | + |
|---|
| 1747 | 2006 | # Scripts to check various things for consistency |
|---|
| 1748 | 2007 | # --------------------------------------------------------------------------- |
|---|
| 1749 | 2008 | |
|---|
| 1750 | | -PHONY += includecheck versioncheck coccicheck namespacecheck export_report |
|---|
| 2009 | +PHONY += includecheck versioncheck coccicheck export_report |
|---|
| 1751 | 2010 | |
|---|
| 1752 | 2011 | includecheck: |
|---|
| 1753 | 2012 | find $(srctree)/* $(RCS_FIND_IGNORE) \ |
|---|
| .. | .. |
|---|
| 1760 | 2019 | | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl |
|---|
| 1761 | 2020 | |
|---|
| 1762 | 2021 | coccicheck: |
|---|
| 1763 | | - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@ |
|---|
| 1764 | | - |
|---|
| 1765 | | -namespacecheck: |
|---|
| 1766 | | - $(PERL) $(srctree)/scripts/namespace.pl |
|---|
| 2022 | + $(Q)$(BASH) $(srctree)/scripts/$@ |
|---|
| 1767 | 2023 | |
|---|
| 1768 | 2024 | export_report: |
|---|
| 1769 | 2025 | $(PERL) $(srctree)/scripts/export_report.pl |
|---|
| 1770 | | - |
|---|
| 1771 | | -endif #ifeq ($(config-targets),1) |
|---|
| 1772 | | -endif #ifeq ($(mixed-targets),1) |
|---|
| 1773 | 2026 | |
|---|
| 1774 | 2027 | PHONY += checkstack kernelrelease kernelversion image_name |
|---|
| 1775 | 2028 | |
|---|
| .. | .. |
|---|
| 1784 | 2037 | endif |
|---|
| 1785 | 2038 | checkstack: |
|---|
| 1786 | 2039 | $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ |
|---|
| 1787 | | - $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH) |
|---|
| 2040 | + $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) |
|---|
| 1788 | 2041 | |
|---|
| 1789 | 2042 | kernelrelease: |
|---|
| 1790 | 2043 | @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \ |
|---|
| .. | .. |
|---|
| 1797 | 2050 | @echo $(KBUILD_IMAGE) |
|---|
| 1798 | 2051 | |
|---|
| 1799 | 2052 | # Clear a bunch of variables before executing the submake |
|---|
| 2053 | + |
|---|
| 2054 | +ifeq ($(quiet),silent_) |
|---|
| 2055 | +tools_silent=s |
|---|
| 2056 | +endif |
|---|
| 2057 | + |
|---|
| 1800 | 2058 | tools/: FORCE |
|---|
| 1801 | 2059 | $(Q)mkdir -p $(objtree)/tools |
|---|
| 1802 | | - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ |
|---|
| 2060 | + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ |
|---|
| 1803 | 2061 | |
|---|
| 1804 | 2062 | tools/%: FORCE |
|---|
| 1805 | 2063 | $(Q)mkdir -p $(objtree)/tools |
|---|
| 1806 | | - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ $* |
|---|
| 1807 | | - |
|---|
| 1808 | | -# Single targets |
|---|
| 1809 | | -# --------------------------------------------------------------------------- |
|---|
| 1810 | | -# Single targets are compatible with: |
|---|
| 1811 | | -# - build with mixed source and output |
|---|
| 1812 | | -# - build with separate output dir 'make O=...' |
|---|
| 1813 | | -# - external modules |
|---|
| 1814 | | -# |
|---|
| 1815 | | -# target-dir => where to store outputfile |
|---|
| 1816 | | -# build-dir => directory in kernel source tree to use |
|---|
| 1817 | | - |
|---|
| 1818 | | -ifeq ($(KBUILD_EXTMOD),) |
|---|
| 1819 | | - build-dir = $(patsubst %/,%,$(dir $@)) |
|---|
| 1820 | | - target-dir = $(dir $@) |
|---|
| 1821 | | -else |
|---|
| 1822 | | - zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@))) |
|---|
| 1823 | | - build-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash)) |
|---|
| 1824 | | - target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) |
|---|
| 1825 | | -endif |
|---|
| 1826 | | - |
|---|
| 1827 | | -%.s: %.c prepare scripts FORCE |
|---|
| 1828 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1829 | | -%.i: %.c prepare scripts FORCE |
|---|
| 1830 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1831 | | -%.o: %.c prepare scripts FORCE |
|---|
| 1832 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1833 | | -%.lst: %.c prepare scripts FORCE |
|---|
| 1834 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1835 | | -%.s: %.S prepare scripts FORCE |
|---|
| 1836 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1837 | | -%.o: %.S prepare scripts FORCE |
|---|
| 1838 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1839 | | -%.symtypes: %.c prepare scripts FORCE |
|---|
| 1840 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1841 | | -%.ll: %.c prepare scripts FORCE |
|---|
| 1842 | | - $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) |
|---|
| 1843 | | - |
|---|
| 1844 | | -# Modules |
|---|
| 1845 | | -/: prepare scripts FORCE |
|---|
| 1846 | | - $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ |
|---|
| 1847 | | - $(build)=$(build-dir) |
|---|
| 1848 | | -# Make sure the latest headers are built for Documentation |
|---|
| 1849 | | -Documentation/ samples/: headers_install |
|---|
| 1850 | | -%/: prepare scripts FORCE |
|---|
| 1851 | | - $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ |
|---|
| 1852 | | - $(build)=$(build-dir) |
|---|
| 1853 | | -%.ko: prepare scripts FORCE |
|---|
| 1854 | | - $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ |
|---|
| 1855 | | - $(build)=$(build-dir) $(@:.ko=.o) |
|---|
| 1856 | | - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
|---|
| 1857 | | - |
|---|
| 1858 | | -# FIXME Should go into a make.lib or something |
|---|
| 1859 | | -# =========================================================================== |
|---|
| 1860 | | - |
|---|
| 1861 | | -quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs))) |
|---|
| 1862 | | - cmd_rmdirs = rm -rf $(rm-dirs) |
|---|
| 2064 | + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* |
|---|
| 1863 | 2065 | |
|---|
| 1864 | 2066 | quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) |
|---|
| 1865 | | - cmd_rmfiles = rm -f $(rm-files) |
|---|
| 2067 | + cmd_rmfiles = rm -rf $(rm-files) |
|---|
| 1866 | 2068 | |
|---|
| 1867 | 2069 | # Run depmod only if we have System.map and depmod is executable |
|---|
| 1868 | 2070 | quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) |
|---|
| 1869 | 2071 | cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ |
|---|
| 1870 | | - $(KERNELRELEASE) |
|---|
| 2072 | + $(KERNELRELEASE) $(mixed-build-prefix) |
|---|
| 1871 | 2073 | |
|---|
| 1872 | | -# Create temporary dir for module support files |
|---|
| 1873 | | -# clean it up only when building all modules |
|---|
| 1874 | | -cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \ |
|---|
| 1875 | | - $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) |
|---|
| 2074 | +# read saved command lines for existing targets |
|---|
| 2075 | +existing-targets := $(wildcard $(sort $(targets))) |
|---|
| 1876 | 2076 | |
|---|
| 1877 | | -# read all saved command lines |
|---|
| 2077 | +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
|---|
| 1878 | 2078 | |
|---|
| 1879 | | -cmd_files := $(wildcard .*.cmd $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) |
|---|
| 1880 | | - |
|---|
| 1881 | | -ifneq ($(cmd_files),) |
|---|
| 1882 | | - $(cmd_files): ; # Do not try to update included dependency files |
|---|
| 1883 | | - include $(cmd_files) |
|---|
| 1884 | | -endif |
|---|
| 1885 | | - |
|---|
| 1886 | | -endif # skip-makefile |
|---|
| 2079 | +endif # config-build |
|---|
| 2080 | +endif # mixed-build |
|---|
| 2081 | +endif # need-sub-make |
|---|
| 1887 | 2082 | |
|---|
| 1888 | 2083 | PHONY += FORCE |
|---|
| 1889 | 2084 | FORCE: |
|---|