Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'kbuild-v6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

- Change V=1 option to print both short log and full command log

- Allow V=1 and V=2 to be combined as V=12

- Make W=1 detect wrong .gitignore files

- Tree-wide cleanups for unused command line arguments passed to Clang

- Stop using -Qunused-arguments with Clang

- Make scripts/setlocalversion handle only correct release tags instead
of any arbitrary annotated tag

- Create Debian and RPM source packages without cleaning the source
tree

- Various cleanups for packaging

* tag 'kbuild-v6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (74 commits)
kbuild: rpm-pkg: remove unneeded KERNELRELEASE from modules/headers_install
docs: kbuild: remove description of KBUILD_LDS_MODULE
.gitattributes: use 'dts' diff driver for *.dtso files
kbuild: deb-pkg: improve the usability of source package
kbuild: deb-pkg: fix binary-arch and clean in debian/rules
kbuild: tar-pkg: use tar rules in scripts/Makefile.package
kbuild: make perf-tar*-src-pkg work without relying on git
kbuild: deb-pkg: switch over to source format 3.0 (quilt)
kbuild: deb-pkg: make .orig tarball a hard link if possible
kbuild: deb-pkg: hide KDEB_SOURCENAME from Makefile
kbuild: srcrpm-pkg: create source package without cleaning
kbuild: rpm-pkg: build binary packages from source rpm
kbuild: deb-pkg: create source package without cleaning
kbuild: add a tool to list files ignored by git
Documentation/llvm: add Chimera Linux, Google and Meta datacenters
setlocalversion: use only the correct release tag for git-describe
setlocalversion: clean up the construction of version output
.gitignore: ignore *.cover and *.mbx
kbuild: remove --include-dir MAKEFLAG from top Makefile
kbuild: fix trivial typo in comment
...

+3048 -1952
+4 -4
.gitattributes
··· 1 - *.c diff=cpp 2 - *.h diff=cpp 3 - *.dtsi diff=dts 4 - *.dts diff=dts 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + *.[ch] diff=cpp 3 + *.dts diff=dts 4 + *.dts[io] diff=dts
+3 -1
.gitignore
··· 4 4 # subdirectories here. Add them in the ".gitignore" file 5 5 # in that subdirectory instead. 6 6 # 7 - # NOTE! Please use 'git ls-files -i --exclude-standard' 7 + # NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore' 8 8 # command after changing this file, to see if there are 9 9 # any tracked files which get ignored after the change. 10 10 # ··· 16 16 *.bin 17 17 *.bz2 18 18 *.c.[012]*.* 19 + *.cover 19 20 *.dt.yaml 20 21 *.dtb 21 22 *.dtbo ··· 34 33 *.lz4 35 34 *.lzma 36 35 *.lzo 36 + *.mbx 37 37 *.mod 38 38 *.mod.c 39 39 *.o
+1 -1
Documentation/Makefile
··· 28 28 PDFLATEX = xelatex 29 29 LATEXOPTS = -interaction=batchmode -no-shell-escape 30 30 31 - ifeq ($(KBUILD_VERBOSE),0) 31 + ifeq ($(findstring 1, $(KBUILD_VERBOSE)),) 32 32 SPHINXOPTS += "-q" 33 33 endif 34 34
-1
Documentation/dontdiff
··· 91 91 autoconf.h* 92 92 av_permissions.h 93 93 bbootsect 94 - bin2c 95 94 binkernel.spec 96 95 bootsect 97 96 bounds.h
+9 -6
Documentation/kbuild/llvm.rst
··· 15 15 <https://clang.llvm.org/>`_ and `LLVM <https://llvm.org/>`_ utilities to be 16 16 used as viable substitutes. Distributions such as `Android 17 17 <https://www.android.com/>`_, `ChromeOS 18 - <https://www.chromium.org/chromium-os>`_, and `OpenMandriva 19 - <https://www.openmandriva.org/>`_ use Clang built kernels. `LLVM is a 20 - collection of toolchain components implemented in terms of C++ objects 21 - <https://www.aosabook.org/en/llvm.html>`_. Clang is a front-end to LLVM that 22 - supports C and the GNU C extensions required by the kernel, and is pronounced 23 - "klang," not "see-lang." 18 + <https://www.chromium.org/chromium-os>`_, `OpenMandriva 19 + <https://www.openmandriva.org/>`_, and `Chimera Linux 20 + <https://chimera-linux.org/>`_ use Clang built kernels. Google's and Meta's 21 + datacenter fleets also run kernels built with Clang. 22 + 23 + `LLVM is a collection of toolchain components implemented in terms of C++ 24 + objects <https://www.aosabook.org/en/llvm.html>`_. Clang is a front-end to LLVM 25 + that supports C and the GNU C extensions required by the kernel, and is 26 + pronounced "klang," not "see-lang." 24 27 25 28 Clang 26 29 -----
+1228 -1262
Documentation/kbuild/makefiles.rst
··· 4 4 5 5 This document describes the Linux kernel Makefiles. 6 6 7 - .. Table of Contents 8 - 9 - === 1 Overview 10 - === 2 Who does what 11 - === 3 The kbuild files 12 - --- 3.1 Goal definitions 13 - --- 3.2 Built-in object goals - obj-y 14 - --- 3.3 Loadable module goals - obj-m 15 - --- 3.4 <deleted> 16 - --- 3.5 Library file goals - lib-y 17 - --- 3.6 Descending down in directories 18 - --- 3.7 Non-builtin vmlinux targets - extra-y 19 - --- 3.8 Always built goals - always-y 20 - --- 3.9 Compilation flags 21 - --- 3.10 Dependency tracking 22 - --- 3.11 Custom Rules 23 - --- 3.12 Command change detection 24 - --- 3.13 $(CC) support functions 25 - --- 3.14 $(LD) support functions 26 - --- 3.15 Script Invocation 27 - 28 - === 4 Host Program support 29 - --- 4.1 Simple Host Program 30 - --- 4.2 Composite Host Programs 31 - --- 4.3 Using C++ for host programs 32 - --- 4.4 Using Rust for host programs 33 - --- 4.5 Controlling compiler options for host programs 34 - --- 4.6 When host programs are actually built 35 - 36 - === 5 Userspace Program support 37 - --- 5.1 Simple Userspace Program 38 - --- 5.2 Composite Userspace Programs 39 - --- 5.3 Controlling compiler options for userspace programs 40 - --- 5.4 When userspace programs are actually built 41 - 42 - === 6 Kbuild clean infrastructure 43 - 44 - === 7 Architecture Makefiles 45 - --- 7.1 Set variables to tweak the build to the architecture 46 - --- 7.2 Add prerequisites to archheaders 47 - --- 7.3 Add prerequisites to archprepare 48 - --- 7.4 List directories to visit when descending 49 - --- 7.5 Architecture-specific boot images 50 - --- 7.6 Building non-kbuild targets 51 - --- 7.7 Commands useful for building a boot image 52 - --- 7.8 <deleted> 53 - --- 7.9 Preprocessing linker scripts 54 - --- 7.10 Generic header files 55 - --- 7.11 Post-link pass 56 - 57 - === 8 Kbuild syntax for exported headers 58 - --- 8.1 no-export-headers 59 - --- 8.2 generic-y 60 - --- 8.3 generated-y 61 - --- 8.4 mandatory-y 62 - 63 - === 9 Kbuild Variables 64 - === 10 Makefile language 65 - === 11 Credits 66 - === 12 TODO 67 - 68 - 1 Overview 69 - ========== 7 + Overview 8 + ======== 70 9 71 10 The Makefiles have five parts:: 72 11 ··· 22 83 (the resident kernel image) and modules (any module files). 23 84 It builds these goals by recursively descending into the subdirectories of 24 85 the kernel source tree. 86 + 25 87 The list of subdirectories which are visited depends upon the kernel 26 88 configuration. The top Makefile textually includes an arch Makefile 27 89 with the name arch/$(SRCARCH)/Makefile. The arch Makefile supplies ··· 36 96 scripts/Makefile.* contains all the definitions/rules etc. that 37 97 are used to build the kernel based on the kbuild makefiles. 38 98 39 - 40 - 2 Who does what 41 - =============== 99 + Who does what 100 + ============= 42 101 43 102 People have four different relationships with the kernel Makefiles. 44 103 45 104 *Users* are people who build kernels. These people type commands such as 46 - "make menuconfig" or "make". They usually do not read or edit 105 + ``make menuconfig`` or ``make``. They usually do not read or edit 47 106 any kernel Makefiles (or any other source files). 48 107 49 108 *Normal developers* are people who work on features such as device ··· 62 123 This document is aimed towards normal developers and arch developers. 63 124 64 125 65 - 3 The kbuild files 66 - ================== 126 + The kbuild files 127 + ================ 67 128 68 129 Most Makefiles within the kernel are kbuild Makefiles that use the 69 130 kbuild infrastructure. This chapter introduces the syntax used in the 70 131 kbuild makefiles. 71 - The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can 72 - be used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild' 132 + 133 + The preferred name for the kbuild files are ``Makefile`` but ``Kbuild`` can 134 + be used and if both a ``Makefile`` and a ``Kbuild`` file exists, then the ``Kbuild`` 73 135 file will be used. 74 136 75 - Section 3.1 "Goal definitions" is a quick intro; further chapters provide 137 + Section `Goal definitions`_ is a quick intro; further chapters provide 76 138 more details, with real examples. 77 139 78 - 3.1 Goal definitions 79 - -------------------- 140 + Goal definitions 141 + ---------------- 80 142 81 - Goal definitions are the main part (heart) of the kbuild Makefile. 82 - These lines define the files to be built, any special compilation 83 - options, and any subdirectories to be entered recursively. 143 + Goal definitions are the main part (heart) of the kbuild Makefile. 144 + These lines define the files to be built, any special compilation 145 + options, and any subdirectories to be entered recursively. 84 146 85 - The most simple kbuild makefile contains one line: 147 + The most simple kbuild makefile contains one line: 86 148 87 - Example:: 149 + Example:: 88 150 89 - obj-y += foo.o 151 + obj-y += foo.o 90 152 91 - This tells kbuild that there is one object in that directory, named 92 - foo.o. foo.o will be built from foo.c or foo.S. 153 + This tells kbuild that there is one object in that directory, named 154 + foo.o. foo.o will be built from foo.c or foo.S. 93 155 94 - If foo.o shall be built as a module, the variable obj-m is used. 95 - Therefore the following pattern is often used: 156 + If foo.o shall be built as a module, the variable obj-m is used. 157 + Therefore the following pattern is often used: 96 158 97 - Example:: 159 + Example:: 98 160 99 - obj-$(CONFIG_FOO) += foo.o 161 + obj-$(CONFIG_FOO) += foo.o 100 162 101 - $(CONFIG_FOO) evaluates to either y (for built-in) or m (for module). 102 - If CONFIG_FOO is neither y nor m, then the file will not be compiled 103 - nor linked. 163 + $(CONFIG_FOO) evaluates to either y (for built-in) or m (for module). 164 + If CONFIG_FOO is neither y nor m, then the file will not be compiled 165 + nor linked. 104 166 105 - 3.2 Built-in object goals - obj-y 106 - --------------------------------- 107 - 108 - The kbuild Makefile specifies object files for vmlinux 109 - in the $(obj-y) lists. These lists depend on the kernel 110 - configuration. 111 - 112 - Kbuild compiles all the $(obj-y) files. It then calls 113 - "$(AR) rcSTP" to merge these files into one built-in.a file. 114 - This is a thin archive without a symbol table. It will be later 115 - linked into vmlinux by scripts/link-vmlinux.sh 116 - 117 - The order of files in $(obj-y) is significant. Duplicates in 118 - the lists are allowed: the first instance will be linked into 119 - built-in.a and succeeding instances will be ignored. 120 - 121 - Link order is significant, because certain functions 122 - (module_init() / __initcall) will be called during boot in the 123 - order they appear. So keep in mind that changing the link 124 - order may e.g. change the order in which your SCSI 125 - controllers are detected, and thus your disks are renumbered. 126 - 127 - Example:: 128 - 129 - #drivers/isdn/i4l/Makefile 130 - # Makefile for the kernel ISDN subsystem and device drivers. 131 - # Each configuration option enables a list of files. 132 - obj-$(CONFIG_ISDN_I4L) += isdn.o 133 - obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 134 - 135 - 3.3 Loadable module goals - obj-m 136 - --------------------------------- 137 - 138 - $(obj-m) specifies object files which are built as loadable 139 - kernel modules. 140 - 141 - A module may be built from one source file or several source 142 - files. In the case of one source file, the kbuild makefile 143 - simply adds the file to $(obj-m). 144 - 145 - Example:: 146 - 147 - #drivers/isdn/i4l/Makefile 148 - obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 149 - 150 - Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm' 151 - 152 - If a kernel module is built from several source files, you specify 153 - that you want to build a module in the same way as above; however, 154 - kbuild needs to know which object files you want to build your 155 - module from, so you have to tell it by setting a $(<module_name>-y) 156 - variable. 157 - 158 - Example:: 159 - 160 - #drivers/isdn/i4l/Makefile 161 - obj-$(CONFIG_ISDN_I4L) += isdn.o 162 - isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o 163 - 164 - In this example, the module name will be isdn.o. Kbuild will 165 - compile the objects listed in $(isdn-y) and then run 166 - "$(LD) -r" on the list of these files to generate isdn.o. 167 - 168 - Due to kbuild recognizing $(<module_name>-y) for composite objects, 169 - you can use the value of a `CONFIG_` symbol to optionally include an 170 - object file as part of a composite object. 171 - 172 - Example:: 173 - 174 - #fs/ext2/Makefile 175 - obj-$(CONFIG_EXT2_FS) += ext2.o 176 - ext2-y := balloc.o dir.o file.o ialloc.o inode.o ioctl.o \ 177 - namei.o super.o symlink.o 178 - ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o \ 179 - xattr_trusted.o 180 - 181 - In this example, xattr.o, xattr_user.o and xattr_trusted.o are only 182 - part of the composite object ext2.o if $(CONFIG_EXT2_FS_XATTR) 183 - evaluates to 'y'. 184 - 185 - Note: Of course, when you are building objects into the kernel, 186 - the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, 187 - kbuild will build an ext2.o file for you out of the individual 188 - parts and then link this into built-in.a, as you would expect. 189 - 190 - 3.5 Library file goals - lib-y 191 - ------------------------------ 192 - 193 - Objects listed with obj-* are used for modules, or 194 - combined in a built-in.a for that specific directory. 195 - There is also the possibility to list objects that will 196 - be included in a library, lib.a. 197 - All objects listed with lib-y are combined in a single 198 - library for that directory. 199 - Objects that are listed in obj-y and additionally listed in 200 - lib-y will not be included in the library, since they will 201 - be accessible anyway. 202 - For consistency, objects listed in lib-m will be included in lib.a. 203 - 204 - Note that the same kbuild makefile may list files to be built-in 205 - and to be part of a library. Therefore the same directory 206 - may contain both a built-in.a and a lib.a file. 207 - 208 - Example:: 209 - 210 - #arch/x86/lib/Makefile 211 - lib-y := delay.o 212 - 213 - This will create a library lib.a based on delay.o. For kbuild to 214 - actually recognize that there is a lib.a being built, the directory 215 - shall be listed in libs-y. 216 - 217 - See also "7.4 List directories to visit when descending". 218 - 219 - Use of lib-y is normally restricted to `lib/` and `arch/*/lib`. 220 - 221 - 3.6 Descending down in directories 222 - ---------------------------------- 223 - 224 - A Makefile is only responsible for building objects in its own 225 - directory. Files in subdirectories should be taken care of by 226 - Makefiles in these subdirs. The build system will automatically 227 - invoke make recursively in subdirectories, provided you let it know of 228 - them. 229 - 230 - To do so, obj-y and obj-m are used. 231 - ext2 lives in a separate directory, and the Makefile present in fs/ 232 - tells kbuild to descend down using the following assignment. 233 - 234 - Example:: 235 - 236 - #fs/Makefile 237 - obj-$(CONFIG_EXT2_FS) += ext2/ 238 - 239 - If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular) 240 - the corresponding obj- variable will be set, and kbuild will descend 241 - down in the ext2 directory. 242 - 243 - Kbuild uses this information not only to decide that it needs to visit 244 - the directory, but also to decide whether or not to link objects from 245 - the directory into vmlinux. 246 - 247 - When Kbuild descends into the directory with 'y', all built-in objects 248 - from that directory are combined into the built-in.a, which will be 249 - eventually linked into vmlinux. 250 - 251 - When Kbuild descends into the directory with 'm', in contrast, nothing 252 - from that directory will be linked into vmlinux. If the Makefile in 253 - that directory specifies obj-y, those objects will be left orphan. 254 - It is very likely a bug of the Makefile or of dependencies in Kconfig. 255 - 256 - Kbuild also supports dedicated syntax, subdir-y and subdir-m, for 257 - descending into subdirectories. It is a good fit when you know they 258 - do not contain kernel-space objects at all. A typical usage is to let 259 - Kbuild descend into subdirectories to build tools. 260 - 261 - Examples:: 262 - 263 - # scripts/Makefile 264 - subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins 265 - subdir-$(CONFIG_MODVERSIONS) += genksyms 266 - subdir-$(CONFIG_SECURITY_SELINUX) += selinux 267 - 268 - Unlike obj-y/m, subdir-y/m does not need the trailing slash since this 269 - syntax is always used for directories. 270 - 271 - It is good practice to use a `CONFIG_` variable when assigning directory 272 - names. This allows kbuild to totally skip the directory if the 273 - corresponding `CONFIG_` option is neither 'y' nor 'm'. 274 - 275 - 3.7 Non-builtin vmlinux targets - extra-y 276 - ----------------------------------------- 277 - 278 - extra-y specifies targets which are needed for building vmlinux, 279 - but not combined into built-in.a. 280 - 281 - Examples are: 282 - 283 - 1) vmlinux linker script 284 - 285 - The linker script for vmlinux is located at 286 - arch/$(SRCARCH)/kernel/vmlinux.lds 287 - 288 - Example:: 289 - 290 - # arch/x86/kernel/Makefile 291 - extra-y += vmlinux.lds 292 - 293 - $(extra-y) should only contain targets needed for vmlinux. 294 - 295 - Kbuild skips extra-y when vmlinux is apparently not a final goal. 296 - (e.g. 'make modules', or building external modules) 297 - 298 - If you intend to build targets unconditionally, always-y (explained 299 - in the next section) is the correct syntax to use. 300 - 301 - 3.8 Always built goals - always-y 302 - --------------------------------- 303 - 304 - always-y specifies targets which are literally always built when 305 - Kbuild visits the Makefile. 306 - 307 - Example:: 308 - # ./Kbuild 309 - offsets-file := include/generated/asm-offsets.h 310 - always-y += $(offsets-file) 311 - 312 - 3.9 Compilation flags 313 - --------------------- 314 - 315 - ccflags-y, asflags-y and ldflags-y 316 - These three flags apply only to the kbuild makefile in which they 317 - are assigned. They are used for all the normal cc, as and ld 318 - invocations happening during a recursive build. 319 - Note: Flags with the same behaviour were previously named: 320 - EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS. 321 - They are still supported but their usage is deprecated. 322 - 323 - ccflags-y specifies options for compiling with $(CC). 324 - 325 - Example:: 326 - 327 - # drivers/acpi/acpica/Makefile 328 - ccflags-y := -Os -D_LINUX -DBUILDING_ACPICA 329 - ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT 330 - 331 - This variable is necessary because the top Makefile owns the 332 - variable $(KBUILD_CFLAGS) and uses it for compilation flags for the 333 - entire tree. 334 - 335 - asflags-y specifies assembler options. 336 - 337 - Example:: 338 - 339 - #arch/sparc/kernel/Makefile 340 - asflags-y := -ansi 341 - 342 - ldflags-y specifies options for linking with $(LD). 343 - 344 - Example:: 345 - 346 - #arch/cris/boot/compressed/Makefile 347 - ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds 348 - 349 - subdir-ccflags-y, subdir-asflags-y 350 - The two flags listed above are similar to ccflags-y and asflags-y. 351 - The difference is that the subdir- variants have effect for the kbuild 352 - file where they are present and all subdirectories. 353 - Options specified using subdir-* are added to the commandline before 354 - the options specified using the non-subdir variants. 355 - 356 - Example:: 357 - 358 - subdir-ccflags-y := -Werror 359 - 360 - ccflags-remove-y, asflags-remove-y 361 - These flags are used to remove particular flags for the compiler, 362 - assembler invocations. 363 - 364 - Example:: 365 - 366 - ccflags-remove-$(CONFIG_MCOUNT) += -pg 367 - 368 - CFLAGS_$@, AFLAGS_$@ 369 - CFLAGS_$@ and AFLAGS_$@ only apply to commands in current 370 - kbuild makefile. 371 - 372 - $(CFLAGS_$@) specifies per-file options for $(CC). The $@ 373 - part has a literal value which specifies the file that it is for. 374 - 375 - CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@ 376 - can re-add compiler flags that were removed by ccflags-remove-y. 377 - 378 - Example:: 379 - 380 - # drivers/scsi/Makefile 381 - CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF 382 - 383 - This line specify compilation flags for aha152x.o. 384 - 385 - $(AFLAGS_$@) is a similar feature for source files in assembly 386 - languages. 387 - 388 - AFLAGS_$@ has the higher priority than asflags-remove-y; AFLAGS_$@ 389 - can re-add assembler flags that were removed by asflags-remove-y. 390 - 391 - Example:: 392 - 393 - # arch/arm/kernel/Makefile 394 - AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 395 - AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312 396 - AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt 397 - 398 - 399 - 3.10 Dependency tracking 400 - ------------------------ 401 - 402 - Kbuild tracks dependencies on the following: 403 - 404 - 1) All prerequisite files (both `*.c` and `*.h`) 405 - 2) `CONFIG_` options used in all prerequisite files 406 - 3) Command-line used to compile target 407 - 408 - Thus, if you change an option to $(CC) all affected files will 409 - be re-compiled. 410 - 411 - 3.11 Custom Rules 412 - ----------------- 413 - 414 - Custom rules are used when the kbuild infrastructure does 415 - not provide the required support. A typical example is 416 - header files generated during the build process. 417 - Another example are the architecture-specific Makefiles which 418 - need custom rules to prepare boot images etc. 419 - 420 - Custom rules are written as normal Make rules. 421 - Kbuild is not executing in the directory where the Makefile is 422 - located, so all custom rules shall use a relative 423 - path to prerequisite files and target files. 424 - 425 - Two variables are used when defining custom rules: 426 - 427 - $(src) 428 - $(src) is a relative path which points to the directory 429 - where the Makefile is located. Always use $(src) when 430 - referring to files located in the src tree. 431 - 432 - $(obj) 433 - $(obj) is a relative path which points to the directory 434 - where the target is saved. Always use $(obj) when 435 - referring to generated files. 436 - 437 - Example:: 438 - 439 - #drivers/scsi/Makefile 440 - $(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl 441 - $(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl 442 - 443 - This is a custom rule, following the normal syntax 444 - required by make. 445 - 446 - The target file depends on two prerequisite files. References 447 - to the target file are prefixed with $(obj), references 448 - to prerequisites are referenced with $(src) (because they are not 449 - generated files). 450 - 451 - $(kecho) 452 - echoing information to user in a rule is often a good practice 453 - but when execution "make -s" one does not expect to see any output 454 - except for warnings/errors. 455 - To support this kbuild defines $(kecho) which will echo out the 456 - text following $(kecho) to stdout except if "make -s" is used. 457 - 458 - Example:: 459 - 460 - # arch/arm/Makefile 461 - $(BOOT_TARGETS): vmlinux 462 - $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 463 - @$(kecho) ' Kernel: $(boot)/$@ is ready' 464 - 465 - When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand 466 - of a command is normally displayed. 467 - To enable this behaviour for custom commands kbuild requires 468 - two variables to be set:: 469 - 470 - quiet_cmd_<command> - what shall be echoed 471 - cmd_<command> - the command to execute 472 - 473 - Example:: 474 - 475 - # lib/Makefile 476 - quiet_cmd_crc32 = GEN $@ 477 - cmd_crc32 = $< > $@ 478 - 479 - $(obj)/crc32table.h: $(obj)/gen_crc32table 480 - $(call cmd,crc32) 481 - 482 - When updating the $(obj)/crc32table.h target, the line: 483 - 484 - GEN lib/crc32table.h 485 - 486 - will be displayed with "make KBUILD_VERBOSE=0". 487 - 488 - 3.12 Command change detection 167 + Built-in object goals - obj-y 489 168 ----------------------------- 490 169 491 - When the rule is evaluated, timestamps are compared between the target 492 - and its prerequisite files. GNU Make updates the target when any of the 493 - prerequisites is newer than that. 170 + The kbuild Makefile specifies object files for vmlinux 171 + in the $(obj-y) lists. These lists depend on the kernel 172 + configuration. 494 173 495 - The target should be rebuilt also when the command line has changed 496 - since the last invocation. This is not supported by Make itself, so 497 - Kbuild achieves this by a kind of meta-programming. 174 + Kbuild compiles all the $(obj-y) files. It then calls 175 + ``$(AR) rcSTP`` to merge these files into one built-in.a file. 176 + This is a thin archive without a symbol table. It will be later 177 + linked into vmlinux by scripts/link-vmlinux.sh 498 178 499 - if_changed is the macro used for this purpose, in the following form:: 179 + The order of files in $(obj-y) is significant. Duplicates in 180 + the lists are allowed: the first instance will be linked into 181 + built-in.a and succeeding instances will be ignored. 500 182 501 - quiet_cmd_<command> = ... 502 - cmd_<command> = ... 183 + Link order is significant, because certain functions 184 + (module_init() / __initcall) will be called during boot in the 185 + order they appear. So keep in mind that changing the link 186 + order may e.g. change the order in which your SCSI 187 + controllers are detected, and thus your disks are renumbered. 503 188 504 - <target>: <source(s)> FORCE 505 - $(call if_changed,<command>) 189 + Example:: 506 190 507 - Any target that utilizes if_changed must be listed in $(targets), 508 - otherwise the command line check will fail, and the target will 509 - always be built. 191 + #drivers/isdn/i4l/Makefile 192 + # Makefile for the kernel ISDN subsystem and device drivers. 193 + # Each configuration option enables a list of files. 194 + obj-$(CONFIG_ISDN_I4L) += isdn.o 195 + obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 510 196 511 - If the target is already listed in the recognized syntax such as 512 - obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, Kbuild 513 - automatically adds it to $(targets). Otherwise, the target must be 514 - explicitly added to $(targets). 197 + Loadable module goals - obj-m 198 + ----------------------------- 515 199 516 - Assignments to $(targets) are without $(obj)/ prefix. if_changed may be 517 - used in conjunction with custom rules as defined in "3.11 Custom Rules". 200 + $(obj-m) specifies object files which are built as loadable 201 + kernel modules. 518 202 519 - Note: It is a typical mistake to forget the FORCE prerequisite. 520 - Another common pitfall is that whitespace is sometimes significant; for 521 - instance, the below will fail (note the extra space after the comma):: 203 + A module may be built from one source file or several source 204 + files. In the case of one source file, the kbuild makefile 205 + simply adds the file to $(obj-m). 522 206 523 - target: source(s) FORCE 207 + Example:: 524 208 525 - **WRONG!** $(call if_changed, objcopy) 209 + #drivers/isdn/i4l/Makefile 210 + obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 526 211 527 - Note: 528 - if_changed should not be used more than once per target. 529 - It stores the executed command in a corresponding .cmd 530 - file and multiple calls would result in overwrites and 531 - unwanted results when the target is up to date and only the 532 - tests on changed commands trigger execution of commands. 212 + Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to "m" 533 213 534 - 3.13 $(CC) support functions 535 - ---------------------------- 214 + If a kernel module is built from several source files, you specify 215 + that you want to build a module in the same way as above; however, 216 + kbuild needs to know which object files you want to build your 217 + module from, so you have to tell it by setting a $(<module_name>-y) 218 + variable. 536 219 537 - The kernel may be built with several different versions of 538 - $(CC), each supporting a unique set of features and options. 539 - kbuild provides basic support to check for valid options for $(CC). 540 - $(CC) is usually the gcc compiler, but other alternatives are 541 - available. 220 + Example:: 542 221 543 - as-option 544 - as-option is used to check if $(CC) -- when used to compile 545 - assembler (`*.S`) files -- supports the given option. An optional 546 - second option may be specified if the first option is not supported. 222 + #drivers/isdn/i4l/Makefile 223 + obj-$(CONFIG_ISDN_I4L) += isdn.o 224 + isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o 547 225 548 - Example:: 226 + In this example, the module name will be isdn.o. Kbuild will 227 + compile the objects listed in $(isdn-y) and then run 228 + ``$(LD) -r`` on the list of these files to generate isdn.o. 549 229 550 - #arch/sh/Makefile 551 - cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) 230 + Due to kbuild recognizing $(<module_name>-y) for composite objects, 231 + you can use the value of a ``CONFIG_`` symbol to optionally include an 232 + object file as part of a composite object. 552 233 553 - In the above example, cflags-y will be assigned the option 554 - -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). 555 - The second argument is optional, and if supplied will be used 556 - if first argument is not supported. 234 + Example:: 557 235 558 - as-instr 559 - as-instr checks if the assembler reports a specific instruction 560 - and then outputs either option1 or option2 561 - C escapes are supported in the test instruction 562 - Note: as-instr-option uses KBUILD_AFLAGS for assembler options 236 + #fs/ext2/Makefile 237 + obj-$(CONFIG_EXT2_FS) += ext2.o 238 + ext2-y := balloc.o dir.o file.o ialloc.o inode.o ioctl.o \ 239 + namei.o super.o symlink.o 240 + ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o \ 241 + xattr_trusted.o 563 242 564 - cc-option 565 - cc-option is used to check if $(CC) supports a given option, and if 566 - not supported to use an optional second option. 243 + In this example, xattr.o, xattr_user.o and xattr_trusted.o are only 244 + part of the composite object ext2.o if $(CONFIG_EXT2_FS_XATTR) 245 + evaluates to "y". 567 246 568 - Example:: 247 + Note: Of course, when you are building objects into the kernel, 248 + the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, 249 + kbuild will build an ext2.o file for you out of the individual 250 + parts and then link this into built-in.a, as you would expect. 569 251 570 - #arch/x86/Makefile 571 - cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) 252 + Library file goals - lib-y 253 + -------------------------- 572 254 573 - In the above example, cflags-y will be assigned the option 574 - -march=pentium-mmx if supported by $(CC), otherwise -march=i586. 575 - The second argument to cc-option is optional, and if omitted, 576 - cflags-y will be assigned no value if first option is not supported. 577 - Note: cc-option uses KBUILD_CFLAGS for $(CC) options 255 + Objects listed with obj-* are used for modules, or 256 + combined in a built-in.a for that specific directory. 257 + There is also the possibility to list objects that will 258 + be included in a library, lib.a. 259 + All objects listed with lib-y are combined in a single 260 + library for that directory. 261 + Objects that are listed in obj-y and additionally listed in 262 + lib-y will not be included in the library, since they will 263 + be accessible anyway. 264 + For consistency, objects listed in lib-m will be included in lib.a. 578 265 579 - cc-option-yn 580 - cc-option-yn is used to check if gcc supports a given option 581 - and return 'y' if supported, otherwise 'n'. 266 + Note that the same kbuild makefile may list files to be built-in 267 + and to be part of a library. Therefore the same directory 268 + may contain both a built-in.a and a lib.a file. 582 269 583 - Example:: 270 + Example:: 584 271 585 - #arch/ppc/Makefile 586 - biarch := $(call cc-option-yn, -m32) 587 - aflags-$(biarch) += -a32 588 - cflags-$(biarch) += -m32 272 + #arch/x86/lib/Makefile 273 + lib-y := delay.o 589 274 590 - In the above example, $(biarch) is set to y if $(CC) supports the -m32 591 - option. When $(biarch) equals 'y', the expanded variables $(aflags-y) 592 - and $(cflags-y) will be assigned the values -a32 and -m32, 593 - respectively. 594 - Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options 275 + This will create a library lib.a based on delay.o. For kbuild to 276 + actually recognize that there is a lib.a being built, the directory 277 + shall be listed in libs-y. 595 278 596 - cc-disable-warning 597 - cc-disable-warning checks if gcc supports a given warning and returns 598 - the commandline switch to disable it. This special function is needed, 599 - because gcc 4.4 and later accept any unknown -Wno-* option and only 600 - warn about it if there is another warning in the source file. 279 + See also `List directories to visit when descending`_. 601 280 602 - Example:: 281 + Use of lib-y is normally restricted to ``lib/`` and ``arch/*/lib``. 603 282 604 - KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 283 + Descending down in directories 284 + ------------------------------ 605 285 606 - In the above example, -Wno-unused-but-set-variable will be added to 607 - KBUILD_CFLAGS only if gcc really accepts it. 286 + A Makefile is only responsible for building objects in its own 287 + directory. Files in subdirectories should be taken care of by 288 + Makefiles in these subdirs. The build system will automatically 289 + invoke make recursively in subdirectories, provided you let it know of 290 + them. 608 291 609 - gcc-min-version 610 - gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than 611 - or equal to the provided value and evaluates to y if so. 292 + To do so, obj-y and obj-m are used. 293 + ext2 lives in a separate directory, and the Makefile present in fs/ 294 + tells kbuild to descend down using the following assignment. 612 295 613 - Example:: 296 + Example:: 614 297 615 - cflags-$(call gcc-min-version, 70100) := -foo 298 + #fs/Makefile 299 + obj-$(CONFIG_EXT2_FS) += ext2/ 616 300 617 - In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and 618 - $(CONFIG_GCC_VERSION) is >= 7.1. 301 + If CONFIG_EXT2_FS is set to either "y" (built-in) or "m" (modular) 302 + the corresponding obj- variable will be set, and kbuild will descend 303 + down in the ext2 directory. 619 304 620 - clang-min-version 621 - clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater 622 - than or equal to the provided value and evaluates to y if so. 305 + Kbuild uses this information not only to decide that it needs to visit 306 + the directory, but also to decide whether or not to link objects from 307 + the directory into vmlinux. 623 308 624 - Example:: 309 + When Kbuild descends into the directory with "y", all built-in objects 310 + from that directory are combined into the built-in.a, which will be 311 + eventually linked into vmlinux. 625 312 626 - cflags-$(call clang-min-version, 110000) := -foo 313 + When Kbuild descends into the directory with "m", in contrast, nothing 314 + from that directory will be linked into vmlinux. If the Makefile in 315 + that directory specifies obj-y, those objects will be left orphan. 316 + It is very likely a bug of the Makefile or of dependencies in Kconfig. 627 317 628 - In this example, cflags-y will be assigned the value -foo if $(CC) is clang 629 - and $(CONFIG_CLANG_VERSION) is >= 11.0.0. 318 + Kbuild also supports dedicated syntax, subdir-y and subdir-m, for 319 + descending into subdirectories. It is a good fit when you know they 320 + do not contain kernel-space objects at all. A typical usage is to let 321 + Kbuild descend into subdirectories to build tools. 630 322 631 - cc-cross-prefix 632 - cc-cross-prefix is used to check if there exists a $(CC) in path with 633 - one of the listed prefixes. The first prefix where there exist a 634 - prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found 635 - then nothing is returned. 636 - Additional prefixes are separated by a single space in the 637 - call of cc-cross-prefix. 638 - This functionality is useful for architecture Makefiles that try 639 - to set CROSS_COMPILE to well-known values but may have several 640 - values to select between. 641 - It is recommended only to try to set CROSS_COMPILE if it is a cross 642 - build (host arch is different from target arch). And if CROSS_COMPILE 643 - is already set then leave it with the old value. 323 + Examples:: 644 324 645 - Example:: 325 + # scripts/Makefile 326 + subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins 327 + subdir-$(CONFIG_MODVERSIONS) += genksyms 328 + subdir-$(CONFIG_SECURITY_SELINUX) += selinux 646 329 647 - #arch/m68k/Makefile 648 - ifneq ($(SUBARCH),$(ARCH)) 649 - ifeq ($(CROSS_COMPILE),) 650 - CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-) 651 - endif 652 - endif 330 + Unlike obj-y/m, subdir-y/m does not need the trailing slash since this 331 + syntax is always used for directories. 653 332 654 - 3.14 $(LD) support functions 655 - ---------------------------- 333 + It is good practice to use a ``CONFIG_`` variable when assigning directory 334 + names. This allows kbuild to totally skip the directory if the 335 + corresponding ``CONFIG_`` option is neither "y" nor "m". 656 336 657 - ld-option 658 - ld-option is used to check if $(LD) supports the supplied option. 659 - ld-option takes two options as arguments. 660 - The second argument is an optional option that can be used if the 661 - first option is not supported by $(LD). 337 + Non-builtin vmlinux targets - extra-y 338 + ------------------------------------- 662 339 663 - Example:: 340 + extra-y specifies targets which are needed for building vmlinux, 341 + but not combined into built-in.a. 664 342 665 - #Makefile 666 - LDFLAGS_vmlinux += $(call ld-option, -X) 343 + Examples are: 667 344 668 - 3.15 Script invocation 669 - ---------------------- 345 + 1) vmlinux linker script 670 346 671 - Make rules may invoke scripts to build the kernel. The rules shall 672 - always provide the appropriate interpreter to execute the script. They 673 - shall not rely on the execute bits being set, and shall not invoke the 674 - script directly. For the convenience of manual script invocation, such 675 - as invoking ./scripts/checkpatch.pl, it is recommended to set execute 676 - bits on the scripts nonetheless. 347 + The linker script for vmlinux is located at 348 + arch/$(SRCARCH)/kernel/vmlinux.lds 677 349 678 - Kbuild provides variables $(CONFIG_SHELL), $(AWK), $(PERL), 679 - and $(PYTHON3) to refer to interpreters for the respective 680 - scripts. 350 + Example:: 681 351 682 - Example:: 352 + # arch/x86/kernel/Makefile 353 + extra-y += vmlinux.lds 683 354 684 - #Makefile 685 - cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 686 - $(KERNELRELEASE) 355 + $(extra-y) should only contain targets needed for vmlinux. 687 356 688 - 4 Host Program support 689 - ====================== 357 + Kbuild skips extra-y when vmlinux is apparently not a final goal. 358 + (e.g. ``make modules``, or building external modules) 359 + 360 + If you intend to build targets unconditionally, always-y (explained 361 + in the next section) is the correct syntax to use. 362 + 363 + Always built goals - always-y 364 + ----------------------------- 365 + 366 + always-y specifies targets which are literally always built when 367 + Kbuild visits the Makefile. 368 + 369 + Example:: 370 + 371 + # ./Kbuild 372 + offsets-file := include/generated/asm-offsets.h 373 + always-y += $(offsets-file) 374 + 375 + Compilation flags 376 + ----------------- 377 + 378 + ccflags-y, asflags-y and ldflags-y 379 + These three flags apply only to the kbuild makefile in which they 380 + are assigned. They are used for all the normal cc, as and ld 381 + invocations happening during a recursive build. 382 + Note: Flags with the same behaviour were previously named: 383 + EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS. 384 + They are still supported but their usage is deprecated. 385 + 386 + ccflags-y specifies options for compiling with $(CC). 387 + 388 + Example:: 389 + 390 + # drivers/acpi/acpica/Makefile 391 + ccflags-y := -Os -D_LINUX -DBUILDING_ACPICA 392 + ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT 393 + 394 + This variable is necessary because the top Makefile owns the 395 + variable $(KBUILD_CFLAGS) and uses it for compilation flags for the 396 + entire tree. 397 + 398 + asflags-y specifies assembler options. 399 + 400 + Example:: 401 + 402 + #arch/sparc/kernel/Makefile 403 + asflags-y := -ansi 404 + 405 + ldflags-y specifies options for linking with $(LD). 406 + 407 + Example:: 408 + 409 + #arch/cris/boot/compressed/Makefile 410 + ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds 411 + 412 + subdir-ccflags-y, subdir-asflags-y 413 + The two flags listed above are similar to ccflags-y and asflags-y. 414 + The difference is that the subdir- variants have effect for the kbuild 415 + file where they are present and all subdirectories. 416 + Options specified using subdir-* are added to the commandline before 417 + the options specified using the non-subdir variants. 418 + 419 + Example:: 420 + 421 + subdir-ccflags-y := -Werror 422 + 423 + ccflags-remove-y, asflags-remove-y 424 + These flags are used to remove particular flags for the compiler, 425 + assembler invocations. 426 + 427 + Example:: 428 + 429 + ccflags-remove-$(CONFIG_MCOUNT) += -pg 430 + 431 + CFLAGS_$@, AFLAGS_$@ 432 + CFLAGS_$@ and AFLAGS_$@ only apply to commands in current 433 + kbuild makefile. 434 + 435 + $(CFLAGS_$@) specifies per-file options for $(CC). The $@ 436 + part has a literal value which specifies the file that it is for. 437 + 438 + CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@ 439 + can re-add compiler flags that were removed by ccflags-remove-y. 440 + 441 + Example:: 442 + 443 + # drivers/scsi/Makefile 444 + CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF 445 + 446 + This line specify compilation flags for aha152x.o. 447 + 448 + $(AFLAGS_$@) is a similar feature for source files in assembly 449 + languages. 450 + 451 + AFLAGS_$@ has the higher priority than asflags-remove-y; AFLAGS_$@ 452 + can re-add assembler flags that were removed by asflags-remove-y. 453 + 454 + Example:: 455 + 456 + # arch/arm/kernel/Makefile 457 + AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 458 + AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312 459 + AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt 460 + 461 + Dependency tracking 462 + ------------------- 463 + 464 + Kbuild tracks dependencies on the following: 465 + 466 + 1) All prerequisite files (both ``*.c`` and ``*.h``) 467 + 2) ``CONFIG_`` options used in all prerequisite files 468 + 3) Command-line used to compile target 469 + 470 + Thus, if you change an option to $(CC) all affected files will 471 + be re-compiled. 472 + 473 + Custom Rules 474 + ------------ 475 + 476 + Custom rules are used when the kbuild infrastructure does 477 + not provide the required support. A typical example is 478 + header files generated during the build process. 479 + Another example are the architecture-specific Makefiles which 480 + need custom rules to prepare boot images etc. 481 + 482 + Custom rules are written as normal Make rules. 483 + Kbuild is not executing in the directory where the Makefile is 484 + located, so all custom rules shall use a relative 485 + path to prerequisite files and target files. 486 + 487 + Two variables are used when defining custom rules: 488 + 489 + $(src) 490 + $(src) is a relative path which points to the directory 491 + where the Makefile is located. Always use $(src) when 492 + referring to files located in the src tree. 493 + 494 + $(obj) 495 + $(obj) is a relative path which points to the directory 496 + where the target is saved. Always use $(obj) when 497 + referring to generated files. 498 + 499 + Example:: 500 + 501 + #drivers/scsi/Makefile 502 + $(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl 503 + $(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl 504 + 505 + This is a custom rule, following the normal syntax 506 + required by make. 507 + 508 + The target file depends on two prerequisite files. References 509 + to the target file are prefixed with $(obj), references 510 + to prerequisites are referenced with $(src) (because they are not 511 + generated files). 512 + 513 + $(kecho) 514 + echoing information to user in a rule is often a good practice 515 + but when execution ``make -s`` one does not expect to see any output 516 + except for warnings/errors. 517 + To support this kbuild defines $(kecho) which will echo out the 518 + text following $(kecho) to stdout except if ``make -s`` is used. 519 + 520 + Example:: 521 + 522 + # arch/arm/Makefile 523 + $(BOOT_TARGETS): vmlinux 524 + $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 525 + @$(kecho) ' Kernel: $(boot)/$@ is ready' 526 + 527 + When kbuild is executing with KBUILD_VERBOSE unset, then only a shorthand 528 + of a command is normally displayed. 529 + To enable this behaviour for custom commands kbuild requires 530 + two variables to be set:: 531 + 532 + quiet_cmd_<command> - what shall be echoed 533 + cmd_<command> - the command to execute 534 + 535 + Example:: 536 + 537 + # lib/Makefile 538 + quiet_cmd_crc32 = GEN $@ 539 + cmd_crc32 = $< > $@ 540 + 541 + $(obj)/crc32table.h: $(obj)/gen_crc32table 542 + $(call cmd,crc32) 543 + 544 + When updating the $(obj)/crc32table.h target, the line:: 545 + 546 + GEN lib/crc32table.h 547 + 548 + will be displayed with ``make KBUILD_VERBOSE=``. 549 + 550 + Command change detection 551 + ------------------------ 552 + 553 + When the rule is evaluated, timestamps are compared between the target 554 + and its prerequisite files. GNU Make updates the target when any of the 555 + prerequisites is newer than that. 556 + 557 + The target should be rebuilt also when the command line has changed 558 + since the last invocation. This is not supported by Make itself, so 559 + Kbuild achieves this by a kind of meta-programming. 560 + 561 + if_changed is the macro used for this purpose, in the following form:: 562 + 563 + quiet_cmd_<command> = ... 564 + cmd_<command> = ... 565 + 566 + <target>: <source(s)> FORCE 567 + $(call if_changed,<command>) 568 + 569 + Any target that utilizes if_changed must be listed in $(targets), 570 + otherwise the command line check will fail, and the target will 571 + always be built. 572 + 573 + If the target is already listed in the recognized syntax such as 574 + obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, Kbuild 575 + automatically adds it to $(targets). Otherwise, the target must be 576 + explicitly added to $(targets). 577 + 578 + Assignments to $(targets) are without $(obj)/ prefix. if_changed may be 579 + used in conjunction with custom rules as defined in `Custom Rules`_. 580 + 581 + Note: It is a typical mistake to forget the FORCE prerequisite. 582 + Another common pitfall is that whitespace is sometimes significant; for 583 + instance, the below will fail (note the extra space after the comma):: 584 + 585 + target: source(s) FORCE 586 + 587 + **WRONG!** $(call if_changed, objcopy) 588 + 589 + Note: 590 + if_changed should not be used more than once per target. 591 + It stores the executed command in a corresponding .cmd 592 + file and multiple calls would result in overwrites and 593 + unwanted results when the target is up to date and only the 594 + tests on changed commands trigger execution of commands. 595 + 596 + $(CC) support functions 597 + ----------------------- 598 + 599 + The kernel may be built with several different versions of 600 + $(CC), each supporting a unique set of features and options. 601 + kbuild provides basic support to check for valid options for $(CC). 602 + $(CC) is usually the gcc compiler, but other alternatives are 603 + available. 604 + 605 + as-option 606 + as-option is used to check if $(CC) -- when used to compile 607 + assembler (``*.S``) files -- supports the given option. An optional 608 + second option may be specified if the first option is not supported. 609 + 610 + Example:: 611 + 612 + #arch/sh/Makefile 613 + cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) 614 + 615 + In the above example, cflags-y will be assigned the option 616 + -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). 617 + The second argument is optional, and if supplied will be used 618 + if first argument is not supported. 619 + 620 + as-instr 621 + as-instr checks if the assembler reports a specific instruction 622 + and then outputs either option1 or option2 623 + C escapes are supported in the test instruction 624 + Note: as-instr-option uses KBUILD_AFLAGS for assembler options 625 + 626 + cc-option 627 + cc-option is used to check if $(CC) supports a given option, and if 628 + not supported to use an optional second option. 629 + 630 + Example:: 631 + 632 + #arch/x86/Makefile 633 + cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) 634 + 635 + In the above example, cflags-y will be assigned the option 636 + -march=pentium-mmx if supported by $(CC), otherwise -march=i586. 637 + The second argument to cc-option is optional, and if omitted, 638 + cflags-y will be assigned no value if first option is not supported. 639 + Note: cc-option uses KBUILD_CFLAGS for $(CC) options 640 + 641 + cc-option-yn 642 + cc-option-yn is used to check if gcc supports a given option 643 + and return "y" if supported, otherwise "n". 644 + 645 + Example:: 646 + 647 + #arch/ppc/Makefile 648 + biarch := $(call cc-option-yn, -m32) 649 + aflags-$(biarch) += -a32 650 + cflags-$(biarch) += -m32 651 + 652 + In the above example, $(biarch) is set to y if $(CC) supports the -m32 653 + option. When $(biarch) equals "y", the expanded variables $(aflags-y) 654 + and $(cflags-y) will be assigned the values -a32 and -m32, 655 + respectively. 656 + 657 + Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options 658 + 659 + cc-disable-warning 660 + cc-disable-warning checks if gcc supports a given warning and returns 661 + the commandline switch to disable it. This special function is needed, 662 + because gcc 4.4 and later accept any unknown -Wno-* option and only 663 + warn about it if there is another warning in the source file. 664 + 665 + Example:: 666 + 667 + KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 668 + 669 + In the above example, -Wno-unused-but-set-variable will be added to 670 + KBUILD_CFLAGS only if gcc really accepts it. 671 + 672 + gcc-min-version 673 + gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than 674 + or equal to the provided value and evaluates to y if so. 675 + 676 + Example:: 677 + 678 + cflags-$(call gcc-min-version, 70100) := -foo 679 + 680 + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and 681 + $(CONFIG_GCC_VERSION) is >= 7.1. 682 + 683 + clang-min-version 684 + clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater 685 + than or equal to the provided value and evaluates to y if so. 686 + 687 + Example:: 688 + 689 + cflags-$(call clang-min-version, 110000) := -foo 690 + 691 + In this example, cflags-y will be assigned the value -foo if $(CC) is clang 692 + and $(CONFIG_CLANG_VERSION) is >= 11.0.0. 693 + 694 + cc-cross-prefix 695 + cc-cross-prefix is used to check if there exists a $(CC) in path with 696 + one of the listed prefixes. The first prefix where there exist a 697 + prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found 698 + then nothing is returned. 699 + 700 + Additional prefixes are separated by a single space in the 701 + call of cc-cross-prefix. 702 + 703 + This functionality is useful for architecture Makefiles that try 704 + to set CROSS_COMPILE to well-known values but may have several 705 + values to select between. 706 + 707 + It is recommended only to try to set CROSS_COMPILE if it is a cross 708 + build (host arch is different from target arch). And if CROSS_COMPILE 709 + is already set then leave it with the old value. 710 + 711 + Example:: 712 + 713 + #arch/m68k/Makefile 714 + ifneq ($(SUBARCH),$(ARCH)) 715 + ifeq ($(CROSS_COMPILE),) 716 + CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-) 717 + endif 718 + endif 719 + 720 + $(LD) support functions 721 + ----------------------- 722 + 723 + ld-option 724 + ld-option is used to check if $(LD) supports the supplied option. 725 + ld-option takes two options as arguments. 726 + 727 + The second argument is an optional option that can be used if the 728 + first option is not supported by $(LD). 729 + 730 + Example:: 731 + 732 + #Makefile 733 + LDFLAGS_vmlinux += $(call ld-option, -X) 734 + 735 + Script invocation 736 + ----------------- 737 + 738 + Make rules may invoke scripts to build the kernel. The rules shall 739 + always provide the appropriate interpreter to execute the script. They 740 + shall not rely on the execute bits being set, and shall not invoke the 741 + script directly. For the convenience of manual script invocation, such 742 + as invoking ./scripts/checkpatch.pl, it is recommended to set execute 743 + bits on the scripts nonetheless. 744 + 745 + Kbuild provides variables $(CONFIG_SHELL), $(AWK), $(PERL), 746 + and $(PYTHON3) to refer to interpreters for the respective 747 + scripts. 748 + 749 + Example:: 750 + 751 + #Makefile 752 + cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 753 + $(KERNELRELEASE) 754 + 755 + Host Program support 756 + ==================== 690 757 691 758 Kbuild supports building executables on the host for use during the 692 759 compilation stage. 760 + 693 761 Two steps are required in order to use a host executable. 694 762 695 763 The first step is to tell kbuild that a host program exists. This is 696 - done utilising the variable "hostprogs". 764 + done utilising the variable ``hostprogs``. 697 765 698 766 The second step is to add an explicit dependency to the executable. 699 767 This can be done in two ways. Either add the dependency in a rule, 700 - or utilise the variable "always-y". 768 + or utilise the variable ``always-y``. 701 769 Both possibilities are described in the following. 702 770 703 - 4.1 Simple Host Program 771 + Simple Host Program 772 + ------------------- 773 + 774 + In some cases there is a need to compile and run a program on the 775 + computer where the build is running. 776 + 777 + The following line tells kbuild that the program bin2hex shall be 778 + built on the build host. 779 + 780 + Example:: 781 + 782 + hostprogs := bin2hex 783 + 784 + Kbuild assumes in the above example that bin2hex is made from a single 785 + c-source file named bin2hex.c located in the same directory as 786 + the Makefile. 787 + 788 + Composite Host Programs 704 789 ----------------------- 705 790 706 - In some cases there is a need to compile and run a program on the 707 - computer where the build is running. 708 - The following line tells kbuild that the program bin2hex shall be 709 - built on the build host. 791 + Host programs can be made up based on composite objects. 792 + The syntax used to define composite objects for host programs is 793 + similar to the syntax used for kernel objects. 794 + $(<executable>-objs) lists all objects used to link the final 795 + executable. 710 796 711 - Example:: 797 + Example:: 712 798 713 - hostprogs := bin2hex 799 + #scripts/lxdialog/Makefile 800 + hostprogs := lxdialog 801 + lxdialog-objs := checklist.o lxdialog.o 714 802 715 - Kbuild assumes in the above example that bin2hex is made from a single 716 - c-source file named bin2hex.c located in the same directory as 717 - the Makefile. 803 + Objects with extension .o are compiled from the corresponding .c 804 + files. In the above example, checklist.c is compiled to checklist.o 805 + and lxdialog.c is compiled to lxdialog.o. 718 806 719 - 4.2 Composite Host Programs 807 + Finally, the two .o files are linked to the executable, lxdialog. 808 + Note: The syntax <executable>-y is not permitted for host-programs. 809 + 810 + Using C++ for host programs 720 811 --------------------------- 721 812 722 - Host programs can be made up based on composite objects. 723 - The syntax used to define composite objects for host programs is 724 - similar to the syntax used for kernel objects. 725 - $(<executable>-objs) lists all objects used to link the final 726 - executable. 813 + kbuild offers support for host programs written in C++. This was 814 + introduced solely to support kconfig, and is not recommended 815 + for general use. 727 816 728 - Example:: 817 + Example:: 729 818 730 - #scripts/lxdialog/Makefile 731 - hostprogs := lxdialog 732 - lxdialog-objs := checklist.o lxdialog.o 819 + #scripts/kconfig/Makefile 820 + hostprogs := qconf 821 + qconf-cxxobjs := qconf.o 733 822 734 - Objects with extension .o are compiled from the corresponding .c 735 - files. In the above example, checklist.c is compiled to checklist.o 736 - and lxdialog.c is compiled to lxdialog.o. 823 + In the example above the executable is composed of the C++ file 824 + qconf.cc - identified by $(qconf-cxxobjs). 737 825 738 - Finally, the two .o files are linked to the executable, lxdialog. 739 - Note: The syntax <executable>-y is not permitted for host-programs. 826 + If qconf is composed of a mixture of .c and .cc files, then an 827 + additional line can be used to identify this. 740 828 741 - 4.3 Using C++ for host programs 742 - ------------------------------- 829 + Example:: 743 830 744 - kbuild offers support for host programs written in C++. This was 745 - introduced solely to support kconfig, and is not recommended 746 - for general use. 831 + #scripts/kconfig/Makefile 832 + hostprogs := qconf 833 + qconf-cxxobjs := qconf.o 834 + qconf-objs := check.o 747 835 748 - Example:: 836 + Using Rust for host programs 837 + ---------------------------- 749 838 750 - #scripts/kconfig/Makefile 751 - hostprogs := qconf 752 - qconf-cxxobjs := qconf.o 839 + Kbuild offers support for host programs written in Rust. However, 840 + since a Rust toolchain is not mandatory for kernel compilation, 841 + it may only be used in scenarios where Rust is required to be 842 + available (e.g. when ``CONFIG_RUST`` is enabled). 753 843 754 - In the example above the executable is composed of the C++ file 755 - qconf.cc - identified by $(qconf-cxxobjs). 844 + Example:: 756 845 757 - If qconf is composed of a mixture of .c and .cc files, then an 758 - additional line can be used to identify this. 846 + hostprogs := target 847 + target-rust := y 759 848 760 - Example:: 849 + Kbuild will compile ``target`` using ``target.rs`` as the crate root, 850 + located in the same directory as the ``Makefile``. The crate may 851 + consist of several source files (see ``samples/rust/hostprogs``). 761 852 762 - #scripts/kconfig/Makefile 763 - hostprogs := qconf 764 - qconf-cxxobjs := qconf.o 765 - qconf-objs := check.o 853 + Controlling compiler options for host programs 854 + ---------------------------------------------- 766 855 767 - 4.4 Using Rust for host programs 768 - -------------------------------- 856 + When compiling host programs, it is possible to set specific flags. 857 + The programs will always be compiled utilising $(HOSTCC) passed 858 + the options specified in $(KBUILD_HOSTCFLAGS). 769 859 770 - Kbuild offers support for host programs written in Rust. However, 771 - since a Rust toolchain is not mandatory for kernel compilation, 772 - it may only be used in scenarios where Rust is required to be 773 - available (e.g. when ``CONFIG_RUST`` is enabled). 860 + To set flags that will take effect for all host programs created 861 + in that Makefile, use the variable HOST_EXTRACFLAGS. 774 862 775 - Example:: 863 + Example:: 776 864 777 - hostprogs := target 778 - target-rust := y 865 + #scripts/lxdialog/Makefile 866 + HOST_EXTRACFLAGS += -I/usr/include/ncurses 779 867 780 - Kbuild will compile ``target`` using ``target.rs`` as the crate root, 781 - located in the same directory as the ``Makefile``. The crate may 782 - consist of several source files (see ``samples/rust/hostprogs``). 868 + To set specific flags for a single file the following construction 869 + is used: 783 870 784 - 4.5 Controlling compiler options for host programs 785 - -------------------------------------------------- 871 + Example:: 786 872 787 - When compiling host programs, it is possible to set specific flags. 788 - The programs will always be compiled utilising $(HOSTCC) passed 789 - the options specified in $(KBUILD_HOSTCFLAGS). 790 - To set flags that will take effect for all host programs created 791 - in that Makefile, use the variable HOST_EXTRACFLAGS. 873 + #arch/ppc64/boot/Makefile 874 + HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) 792 875 793 - Example:: 876 + It is also possible to specify additional options to the linker. 794 877 795 - #scripts/lxdialog/Makefile 796 - HOST_EXTRACFLAGS += -I/usr/include/ncurses 878 + Example:: 797 879 798 - To set specific flags for a single file the following construction 799 - is used: 880 + #scripts/kconfig/Makefile 881 + HOSTLDLIBS_qconf := -L$(QTDIR)/lib 800 882 801 - Example:: 883 + When linking qconf, it will be passed the extra option 884 + ``-L$(QTDIR)/lib``. 802 885 803 - #arch/ppc64/boot/Makefile 804 - HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) 886 + When host programs are actually built 887 + ------------------------------------- 805 888 806 - It is also possible to specify additional options to the linker. 889 + Kbuild will only build host-programs when they are referenced 890 + as a prerequisite. 807 891 808 - Example:: 892 + This is possible in two ways: 809 893 810 - #scripts/kconfig/Makefile 811 - HOSTLDLIBS_qconf := -L$(QTDIR)/lib 894 + (1) List the prerequisite explicitly in a custom rule. 812 895 813 - When linking qconf, it will be passed the extra option 814 - "-L$(QTDIR)/lib". 896 + Example:: 815 897 816 - 4.6 When host programs are actually built 817 - ----------------------------------------- 898 + #drivers/pci/Makefile 899 + hostprogs := gen-devlist 900 + $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist 901 + ( cd $(obj); ./gen-devlist ) < $< 818 902 819 - Kbuild will only build host-programs when they are referenced 820 - as a prerequisite. 821 - This is possible in two ways: 903 + The target $(obj)/devlist.h will not be built before 904 + $(obj)/gen-devlist is updated. Note that references to 905 + the host programs in custom rules must be prefixed with $(obj). 822 906 823 - (1) List the prerequisite explicitly in a custom rule. 907 + (2) Use always-y 824 908 825 - Example:: 909 + When there is no suitable custom rule, and the host program 910 + shall be built when a makefile is entered, the always-y 911 + variable shall be used. 826 912 827 - #drivers/pci/Makefile 828 - hostprogs := gen-devlist 829 - $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist 830 - ( cd $(obj); ./gen-devlist ) < $< 913 + Example:: 831 914 832 - The target $(obj)/devlist.h will not be built before 833 - $(obj)/gen-devlist is updated. Note that references to 834 - the host programs in custom rules must be prefixed with $(obj). 915 + #scripts/lxdialog/Makefile 916 + hostprogs := lxdialog 917 + always-y := $(hostprogs) 835 918 836 - (2) Use always-y 919 + Kbuild provides the following shorthand for this:: 837 920 838 - When there is no suitable custom rule, and the host program 839 - shall be built when a makefile is entered, the always-y 840 - variable shall be used. 921 + hostprogs-always-y := lxdialog 841 922 842 - Example:: 923 + This will tell kbuild to build lxdialog even if not referenced in 924 + any rule. 843 925 844 - #scripts/lxdialog/Makefile 845 - hostprogs := lxdialog 846 - always-y := $(hostprogs) 847 - 848 - Kbuild provides the following shorthand for this: 849 - 850 - hostprogs-always-y := lxdialog 851 - 852 - This will tell kbuild to build lxdialog even if not referenced in 853 - any rule. 854 - 855 - 5 Userspace Program support 856 - =========================== 926 + Userspace Program support 927 + ========================= 857 928 858 929 Just like host programs, Kbuild also supports building userspace executables 859 930 for the target architecture (i.e. the same architecture as you are building 860 931 the kernel for). 861 932 862 - The syntax is quite similar. The difference is to use "userprogs" instead of 863 - "hostprogs". 933 + The syntax is quite similar. The difference is to use ``userprogs`` instead of 934 + ``hostprogs``. 864 935 865 - 5.1 Simple Userspace Program 936 + Simple Userspace Program 937 + ------------------------ 938 + 939 + The following line tells kbuild that the program bpf-direct shall be 940 + built for the target architecture. 941 + 942 + Example:: 943 + 944 + userprogs := bpf-direct 945 + 946 + Kbuild assumes in the above example that bpf-direct is made from a 947 + single C source file named bpf-direct.c located in the same directory 948 + as the Makefile. 949 + 950 + Composite Userspace Programs 866 951 ---------------------------- 867 952 868 - The following line tells kbuild that the program bpf-direct shall be 869 - built for the target architecture. 953 + Userspace programs can be made up based on composite objects. 954 + The syntax used to define composite objects for userspace programs is 955 + similar to the syntax used for kernel objects. 956 + $(<executable>-objs) lists all objects used to link the final 957 + executable. 870 958 871 - Example:: 959 + Example:: 872 960 873 - userprogs := bpf-direct 961 + #samples/seccomp/Makefile 962 + userprogs := bpf-fancy 963 + bpf-fancy-objs := bpf-fancy.o bpf-helper.o 874 964 875 - Kbuild assumes in the above example that bpf-direct is made from a 876 - single C source file named bpf-direct.c located in the same directory 877 - as the Makefile. 965 + Objects with extension .o are compiled from the corresponding .c 966 + files. In the above example, bpf-fancy.c is compiled to bpf-fancy.o 967 + and bpf-helper.c is compiled to bpf-helper.o. 878 968 879 - 5.2 Composite Userspace Programs 880 - -------------------------------- 969 + Finally, the two .o files are linked to the executable, bpf-fancy. 970 + Note: The syntax <executable>-y is not permitted for userspace programs. 881 971 882 - Userspace programs can be made up based on composite objects. 883 - The syntax used to define composite objects for userspace programs is 884 - similar to the syntax used for kernel objects. 885 - $(<executable>-objs) lists all objects used to link the final 886 - executable. 972 + Controlling compiler options for userspace programs 973 + --------------------------------------------------- 887 974 888 - Example:: 975 + When compiling userspace programs, it is possible to set specific flags. 976 + The programs will always be compiled utilising $(CC) passed 977 + the options specified in $(KBUILD_USERCFLAGS). 889 978 890 - #samples/seccomp/Makefile 891 - userprogs := bpf-fancy 892 - bpf-fancy-objs := bpf-fancy.o bpf-helper.o 979 + To set flags that will take effect for all userspace programs created 980 + in that Makefile, use the variable userccflags. 893 981 894 - Objects with extension .o are compiled from the corresponding .c 895 - files. In the above example, bpf-fancy.c is compiled to bpf-fancy.o 896 - and bpf-helper.c is compiled to bpf-helper.o. 982 + Example:: 897 983 898 - Finally, the two .o files are linked to the executable, bpf-fancy. 899 - Note: The syntax <executable>-y is not permitted for userspace programs. 984 + # samples/seccomp/Makefile 985 + userccflags += -I usr/include 900 986 901 - 5.3 Controlling compiler options for userspace programs 902 - ------------------------------------------------------- 987 + To set specific flags for a single file the following construction 988 + is used: 903 989 904 - When compiling userspace programs, it is possible to set specific flags. 905 - The programs will always be compiled utilising $(CC) passed 906 - the options specified in $(KBUILD_USERCFLAGS). 907 - To set flags that will take effect for all userspace programs created 908 - in that Makefile, use the variable userccflags. 990 + Example:: 909 991 910 - Example:: 992 + bpf-helper-userccflags += -I user/include 911 993 912 - # samples/seccomp/Makefile 913 - userccflags += -I usr/include 994 + It is also possible to specify additional options to the linker. 914 995 915 - To set specific flags for a single file the following construction 916 - is used: 996 + Example:: 917 997 918 - Example:: 998 + # net/bpfilter/Makefile 999 + bpfilter_umh-userldflags += -static 919 1000 920 - bpf-helper-userccflags += -I user/include 1001 + When linking bpfilter_umh, it will be passed the extra option -static. 921 1002 922 - It is also possible to specify additional options to the linker. 1003 + From command line, :ref:`USERCFLAGS and USERLDFLAGS <userkbuildflags>` will also be used. 923 1004 924 - Example:: 1005 + When userspace programs are actually built 1006 + ------------------------------------------ 925 1007 926 - # net/bpfilter/Makefile 927 - bpfilter_umh-userldflags += -static 1008 + Kbuild builds userspace programs only when told to do so. 1009 + There are two ways to do this. 928 1010 929 - When linking bpfilter_umh, it will be passed the extra option -static. 1011 + (1) Add it as the prerequisite of another file 930 1012 931 - From command line, :ref:`USERCFLAGS and USERLDFLAGS <userkbuildflags>` will also be used. 1013 + Example:: 932 1014 933 - 5.4 When userspace programs are actually built 934 - ---------------------------------------------- 1015 + #net/bpfilter/Makefile 1016 + userprogs := bpfilter_umh 1017 + $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 935 1018 936 - Kbuild builds userspace programs only when told to do so. 937 - There are two ways to do this. 1019 + $(obj)/bpfilter_umh is built before $(obj)/bpfilter_umh_blob.o 938 1020 939 - (1) Add it as the prerequisite of another file 1021 + (2) Use always-y 940 1022 941 - Example:: 1023 + Example:: 942 1024 943 - #net/bpfilter/Makefile 944 - userprogs := bpfilter_umh 945 - $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 1025 + userprogs := binderfs_example 1026 + always-y := $(userprogs) 946 1027 947 - $(obj)/bpfilter_umh is built before $(obj)/bpfilter_umh_blob.o 1028 + Kbuild provides the following shorthand for this:: 948 1029 949 - (2) Use always-y 1030 + userprogs-always-y := binderfs_example 950 1031 951 - Example:: 1032 + This will tell Kbuild to build binderfs_example when it visits this 1033 + Makefile. 952 1034 953 - userprogs := binderfs_example 954 - always-y := $(userprogs) 1035 + Kbuild clean infrastructure 1036 + =========================== 955 1037 956 - Kbuild provides the following shorthand for this: 957 - 958 - userprogs-always-y := binderfs_example 959 - 960 - This will tell Kbuild to build binderfs_example when it visits this 961 - Makefile. 962 - 963 - 6 Kbuild clean infrastructure 964 - ============================= 965 - 966 - "make clean" deletes most generated files in the obj tree where the kernel 1038 + ``make clean`` deletes most generated files in the obj tree where the kernel 967 1039 is compiled. This includes generated files such as host programs. 968 1040 Kbuild knows targets listed in $(hostprogs), $(always-y), $(always-m), 969 1041 $(always-), $(extra-y), $(extra-) and $(targets). They are all deleted 970 - during "make clean". Files matching the patterns "*.[oas]", "*.ko", plus 1042 + during ``make clean``. Files matching the patterns ``*.[oas]``, ``*.ko``, plus 971 1043 some additional files generated by kbuild are deleted all over the kernel 972 - source tree when "make clean" is executed. 1044 + source tree when ``make clean`` is executed. 973 1045 974 1046 Additional files or directories can be specified in kbuild makefiles by use of 975 1047 $(clean-files). 976 1048 977 - Example:: 1049 + Example:: 978 1050 979 - #lib/Makefile 980 - clean-files := crc32table.h 1051 + #lib/Makefile 1052 + clean-files := crc32table.h 981 1053 982 - When executing "make clean", the file "crc32table.h" will be deleted. 1054 + When executing ``make clean``, the file ``crc32table.h`` will be deleted. 983 1055 Kbuild will assume files to be in the same relative directory as the 984 1056 Makefile. 985 1057 986 1058 To exclude certain files or directories from make clean, use the 987 1059 $(no-clean-files) variable. 988 1060 989 - Usually kbuild descends down in subdirectories due to "obj-* := dir/", 1061 + Usually kbuild descends down in subdirectories due to ``obj-* := dir/``, 990 1062 but in the architecture makefiles where the kbuild infrastructure 991 1063 is not sufficient this sometimes needs to be explicit. 992 1064 993 - Example:: 1065 + Example:: 994 1066 995 - #arch/x86/boot/Makefile 996 - subdir- := compressed 1067 + #arch/x86/boot/Makefile 1068 + subdir- := compressed 997 1069 998 1070 The above assignment instructs kbuild to descend down in the 999 - directory compressed/ when "make clean" is executed. 1071 + directory compressed/ when ``make clean`` is executed. 1000 1072 1001 - Note 1: arch/$(SRCARCH)/Makefile cannot use "subdir-", because that file is 1073 + Note 1: arch/$(SRCARCH)/Makefile cannot use ``subdir-``, because that file is 1002 1074 included in the top level makefile. Instead, arch/$(SRCARCH)/Kbuild can use 1003 - "subdir-". 1075 + ``subdir-``. 1004 1076 1005 1077 Note 2: All directories listed in core-y, libs-y, drivers-y and net-y will 1006 - be visited during "make clean". 1078 + be visited during ``make clean``. 1007 1079 1008 - 7 Architecture Makefiles 1009 - ======================== 1080 + Architecture Makefiles 1081 + ====================== 1010 1082 1011 1083 The top level Makefile sets up the environment and does the preparation, 1012 1084 before starting to descend down in the individual directories. 1085 + 1013 1086 The top level makefile contains the generic part, whereas 1014 1087 arch/$(SRCARCH)/Makefile contains what is required to set up kbuild 1015 1088 for said architecture. 1089 + 1016 1090 To do so, arch/$(SRCARCH)/Makefile sets up a number of variables and defines 1017 1091 a few targets. 1018 1092 1019 1093 When kbuild executes, the following steps are followed (roughly): 1020 1094 1021 1095 1) Configuration of the kernel => produce .config 1096 + 1022 1097 2) Store kernel version in include/linux/version.h 1098 + 1023 1099 3) Updating all other prerequisites to the target prepare: 1100 + 1024 1101 - Additional prerequisites are specified in arch/$(SRCARCH)/Makefile 1102 + 1025 1103 4) Recursively descend down in all directories listed in 1026 1104 init-* core* drivers-* net-* libs-* and build all targets. 1105 + 1027 1106 - The values of the above variables are expanded in arch/$(SRCARCH)/Makefile. 1107 + 1028 1108 5) All object files are then linked and the resulting file vmlinux is 1029 1109 located at the root of the obj tree. 1030 1110 The very first objects linked are listed in scripts/head-object-list.txt. 1111 + 1031 1112 6) Finally, the architecture-specific part does any required post processing 1032 1113 and builds the final bootimage. 1114 + 1033 1115 - This includes building boot records 1034 1116 - Preparing initrd images and the like 1035 1117 1118 + Set variables to tweak the build to the architecture 1119 + ---------------------------------------------------- 1036 1120 1037 - 7.1 Set variables to tweak the build to the architecture 1038 - -------------------------------------------------------- 1121 + KBUILD_LDFLAGS 1122 + Generic $(LD) options 1039 1123 1040 - KBUILD_LDFLAGS 1041 - Generic $(LD) options 1124 + Flags used for all invocations of the linker. 1125 + Often specifying the emulation is sufficient. 1042 1126 1043 - Flags used for all invocations of the linker. 1044 - Often specifying the emulation is sufficient. 1127 + Example:: 1045 1128 1046 - Example:: 1129 + #arch/s390/Makefile 1130 + KBUILD_LDFLAGS := -m elf_s390 1047 1131 1048 - #arch/s390/Makefile 1049 - KBUILD_LDFLAGS := -m elf_s390 1132 + Note: ldflags-y can be used to further customise 1133 + the flags used. See `Non-builtin vmlinux targets - extra-y`_. 1050 1134 1051 - Note: ldflags-y can be used to further customise 1052 - the flags used. See section 3.7. 1135 + LDFLAGS_vmlinux 1136 + Options for $(LD) when linking vmlinux 1053 1137 1054 - LDFLAGS_vmlinux 1055 - Options for $(LD) when linking vmlinux 1138 + LDFLAGS_vmlinux is used to specify additional flags to pass to 1139 + the linker when linking the final vmlinux image. 1056 1140 1057 - LDFLAGS_vmlinux is used to specify additional flags to pass to 1058 - the linker when linking the final vmlinux image. 1059 - LDFLAGS_vmlinux uses the LDFLAGS_$@ support. 1141 + LDFLAGS_vmlinux uses the LDFLAGS_$@ support. 1060 1142 1061 - Example:: 1143 + Example:: 1062 1144 1063 - #arch/x86/Makefile 1064 - LDFLAGS_vmlinux := -e stext 1145 + #arch/x86/Makefile 1146 + LDFLAGS_vmlinux := -e stext 1065 1147 1066 - OBJCOPYFLAGS 1067 - objcopy flags 1148 + OBJCOPYFLAGS 1149 + objcopy flags 1068 1150 1069 - When $(call if_changed,objcopy) is used to translate a .o file, 1070 - the flags specified in OBJCOPYFLAGS will be used. 1071 - $(call if_changed,objcopy) is often used to generate raw binaries on 1072 - vmlinux. 1151 + When $(call if_changed,objcopy) is used to translate a .o file, 1152 + the flags specified in OBJCOPYFLAGS will be used. 1073 1153 1074 - Example:: 1154 + $(call if_changed,objcopy) is often used to generate raw binaries on 1155 + vmlinux. 1075 1156 1076 - #arch/s390/Makefile 1077 - OBJCOPYFLAGS := -O binary 1157 + Example:: 1078 1158 1079 - #arch/s390/boot/Makefile 1080 - $(obj)/image: vmlinux FORCE 1081 - $(call if_changed,objcopy) 1159 + #arch/s390/Makefile 1160 + OBJCOPYFLAGS := -O binary 1082 1161 1083 - In this example, the binary $(obj)/image is a binary version of 1084 - vmlinux. The usage of $(call if_changed,xxx) will be described later. 1162 + #arch/s390/boot/Makefile 1163 + $(obj)/image: vmlinux FORCE 1164 + $(call if_changed,objcopy) 1085 1165 1086 - KBUILD_AFLAGS 1087 - Assembler flags 1166 + In this example, the binary $(obj)/image is a binary version of 1167 + vmlinux. The usage of $(call if_changed,xxx) will be described later. 1088 1168 1089 - Default value - see top level Makefile 1090 - Append or modify as required per architecture. 1169 + KBUILD_AFLAGS 1170 + Assembler flags 1091 1171 1092 - Example:: 1172 + Default value - see top level Makefile. 1093 1173 1094 - #arch/sparc64/Makefile 1095 - KBUILD_AFLAGS += -m64 -mcpu=ultrasparc 1174 + Append or modify as required per architecture. 1096 1175 1097 - KBUILD_CFLAGS 1098 - $(CC) compiler flags 1176 + Example:: 1099 1177 1100 - Default value - see top level Makefile 1101 - Append or modify as required per architecture. 1178 + #arch/sparc64/Makefile 1179 + KBUILD_AFLAGS += -m64 -mcpu=ultrasparc 1102 1180 1103 - Often, the KBUILD_CFLAGS variable depends on the configuration. 1181 + KBUILD_CFLAGS 1182 + $(CC) compiler flags 1104 1183 1105 - Example:: 1184 + Default value - see top level Makefile. 1106 1185 1107 - #arch/x86/boot/compressed/Makefile 1108 - cflags-$(CONFIG_X86_32) := -march=i386 1109 - cflags-$(CONFIG_X86_64) := -mcmodel=small 1110 - KBUILD_CFLAGS += $(cflags-y) 1186 + Append or modify as required per architecture. 1111 1187 1112 - Many arch Makefiles dynamically run the target C compiler to 1113 - probe supported options:: 1188 + Often, the KBUILD_CFLAGS variable depends on the configuration. 1114 1189 1115 - #arch/x86/Makefile 1190 + Example:: 1116 1191 1117 - ... 1118 - cflags-$(CONFIG_MPENTIUMII) += $(call cc-option,\ 1192 + #arch/x86/boot/compressed/Makefile 1193 + cflags-$(CONFIG_X86_32) := -march=i386 1194 + cflags-$(CONFIG_X86_64) := -mcmodel=small 1195 + KBUILD_CFLAGS += $(cflags-y) 1196 + 1197 + Many arch Makefiles dynamically run the target C compiler to 1198 + probe supported options:: 1199 + 1200 + #arch/x86/Makefile 1201 + 1202 + ... 1203 + cflags-$(CONFIG_MPENTIUMII) += $(call cc-option,\ 1119 1204 -march=pentium2,-march=i686) 1120 - ... 1121 - # Disable unit-at-a-time mode ... 1122 - KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time) 1123 - ... 1205 + ... 1206 + # Disable unit-at-a-time mode ... 1207 + KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time) 1208 + ... 1124 1209 1125 1210 1126 - The first example utilises the trick that a config option expands 1127 - to 'y' when selected. 1211 + The first example utilises the trick that a config option expands 1212 + to "y" when selected. 1128 1213 1129 - KBUILD_RUSTFLAGS 1130 - $(RUSTC) compiler flags 1214 + KBUILD_RUSTFLAGS 1215 + $(RUSTC) compiler flags 1131 1216 1132 - Default value - see top level Makefile 1133 - Append or modify as required per architecture. 1217 + Default value - see top level Makefile. 1134 1218 1135 - Often, the KBUILD_RUSTFLAGS variable depends on the configuration. 1219 + Append or modify as required per architecture. 1136 1220 1137 - Note that target specification file generation (for ``--target``) 1138 - is handled in ``scripts/generate_rust_target.rs``. 1221 + Often, the KBUILD_RUSTFLAGS variable depends on the configuration. 1139 1222 1140 - KBUILD_AFLAGS_KERNEL 1141 - Assembler options specific for built-in 1223 + Note that target specification file generation (for ``--target``) 1224 + is handled in ``scripts/generate_rust_target.rs``. 1142 1225 1143 - $(KBUILD_AFLAGS_KERNEL) contains extra C compiler flags used to compile 1144 - resident kernel code. 1226 + KBUILD_AFLAGS_KERNEL 1227 + Assembler options specific for built-in 1145 1228 1146 - KBUILD_AFLAGS_MODULE 1147 - Assembler options specific for modules 1229 + $(KBUILD_AFLAGS_KERNEL) contains extra C compiler flags used to compile 1230 + resident kernel code. 1148 1231 1149 - $(KBUILD_AFLAGS_MODULE) is used to add arch-specific options that 1150 - are used for assembler. 1232 + KBUILD_AFLAGS_MODULE 1233 + Assembler options specific for modules 1151 1234 1152 - From commandline AFLAGS_MODULE shall be used (see kbuild.rst). 1235 + $(KBUILD_AFLAGS_MODULE) is used to add arch-specific options that 1236 + are used for assembler. 1153 1237 1154 - KBUILD_CFLAGS_KERNEL 1155 - $(CC) options specific for built-in 1238 + From commandline AFLAGS_MODULE shall be used (see kbuild.rst). 1156 1239 1157 - $(KBUILD_CFLAGS_KERNEL) contains extra C compiler flags used to compile 1158 - resident kernel code. 1240 + KBUILD_CFLAGS_KERNEL 1241 + $(CC) options specific for built-in 1159 1242 1160 - KBUILD_CFLAGS_MODULE 1161 - Options for $(CC) when building modules 1243 + $(KBUILD_CFLAGS_KERNEL) contains extra C compiler flags used to compile 1244 + resident kernel code. 1162 1245 1163 - $(KBUILD_CFLAGS_MODULE) is used to add arch-specific options that 1164 - are used for $(CC). 1165 - From commandline CFLAGS_MODULE shall be used (see kbuild.rst). 1246 + KBUILD_CFLAGS_MODULE 1247 + Options for $(CC) when building modules 1166 1248 1167 - KBUILD_RUSTFLAGS_KERNEL 1168 - $(RUSTC) options specific for built-in 1249 + $(KBUILD_CFLAGS_MODULE) is used to add arch-specific options that 1250 + are used for $(CC). 1169 1251 1170 - $(KBUILD_RUSTFLAGS_KERNEL) contains extra Rust compiler flags used to 1171 - compile resident kernel code. 1252 + From commandline CFLAGS_MODULE shall be used (see kbuild.rst). 1172 1253 1173 - KBUILD_RUSTFLAGS_MODULE 1174 - Options for $(RUSTC) when building modules 1254 + KBUILD_RUSTFLAGS_KERNEL 1255 + $(RUSTC) options specific for built-in 1175 1256 1176 - $(KBUILD_RUSTFLAGS_MODULE) is used to add arch-specific options that 1177 - are used for $(RUSTC). 1178 - From commandline RUSTFLAGS_MODULE shall be used (see kbuild.rst). 1257 + $(KBUILD_RUSTFLAGS_KERNEL) contains extra Rust compiler flags used to 1258 + compile resident kernel code. 1179 1259 1180 - KBUILD_LDFLAGS_MODULE 1181 - Options for $(LD) when linking modules 1260 + KBUILD_RUSTFLAGS_MODULE 1261 + Options for $(RUSTC) when building modules 1182 1262 1183 - $(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options 1184 - used when linking modules. This is often a linker script. 1263 + $(KBUILD_RUSTFLAGS_MODULE) is used to add arch-specific options that 1264 + are used for $(RUSTC). 1185 1265 1186 - From commandline LDFLAGS_MODULE shall be used (see kbuild.rst). 1266 + From commandline RUSTFLAGS_MODULE shall be used (see kbuild.rst). 1187 1267 1188 - KBUILD_LDS 1268 + KBUILD_LDFLAGS_MODULE 1269 + Options for $(LD) when linking modules 1189 1270 1190 - The linker script with full path. Assigned by the top-level Makefile. 1271 + $(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options 1272 + used when linking modules. This is often a linker script. 1191 1273 1192 - KBUILD_LDS_MODULE 1274 + From commandline LDFLAGS_MODULE shall be used (see kbuild.rst). 1193 1275 1194 - The module linker script with full path. Assigned by the top-level 1195 - Makefile and additionally by the arch Makefile. 1276 + KBUILD_LDS 1277 + The linker script with full path. Assigned by the top-level Makefile. 1196 1278 1197 - KBUILD_VMLINUX_OBJS 1279 + KBUILD_VMLINUX_OBJS 1280 + All object files for vmlinux. They are linked to vmlinux in the same 1281 + order as listed in KBUILD_VMLINUX_OBJS. 1198 1282 1199 - All object files for vmlinux. They are linked to vmlinux in the same 1200 - order as listed in KBUILD_VMLINUX_OBJS. 1283 + The objects listed in scripts/head-object-list.txt are exceptions; 1284 + they are placed before the other objects. 1201 1285 1202 - The objects listed in scripts/head-object-list.txt are exceptions; 1203 - they are placed before the other objects. 1286 + KBUILD_VMLINUX_LIBS 1287 + All .a ``lib`` files for vmlinux. KBUILD_VMLINUX_OBJS and 1288 + KBUILD_VMLINUX_LIBS together specify all the object files used to 1289 + link vmlinux. 1204 1290 1205 - KBUILD_VMLINUX_LIBS 1206 - 1207 - All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and 1208 - KBUILD_VMLINUX_LIBS together specify all the object files used to 1209 - link vmlinux. 1210 - 1211 - 7.2 Add prerequisites to archheaders 1212 - ------------------------------------ 1213 - 1214 - The archheaders: rule is used to generate header files that 1215 - may be installed into user space by "make header_install". 1216 - 1217 - It is run before "make archprepare" when run on the 1218 - architecture itself. 1219 - 1220 - 1221 - 7.3 Add prerequisites to archprepare 1222 - ------------------------------------ 1223 - 1224 - The archprepare: rule is used to list prerequisites that need to be 1225 - built before starting to descend down in the subdirectories. 1226 - This is usually used for header files containing assembler constants. 1227 - 1228 - Example:: 1229 - 1230 - #arch/arm/Makefile 1231 - archprepare: maketools 1232 - 1233 - In this example, the file target maketools will be processed 1234 - before descending down in the subdirectories. 1235 - See also chapter XXX-TODO that describes how kbuild supports 1236 - generating offset header files. 1237 - 1238 - 1239 - 7.4 List directories to visit when descending 1240 - --------------------------------------------- 1241 - 1242 - An arch Makefile cooperates with the top Makefile to define variables 1243 - which specify how to build the vmlinux file. Note that there is no 1244 - corresponding arch-specific section for modules; the module-building 1245 - machinery is all architecture-independent. 1246 - 1247 - 1248 - core-y, libs-y, drivers-y 1249 - 1250 - $(libs-y) lists directories where a lib.a archive can be located. 1251 - 1252 - The rest list directories where a built-in.a object file can be 1253 - located. 1254 - 1255 - Then the rest follows in this order: 1256 - 1257 - $(core-y), $(libs-y), $(drivers-y) 1258 - 1259 - The top level Makefile defines values for all generic directories, 1260 - and arch/$(SRCARCH)/Makefile only adds architecture-specific 1261 - directories. 1262 - 1263 - Example:: 1264 - 1265 - # arch/sparc/Makefile 1266 - core-y += arch/sparc/ 1267 - 1268 - libs-y += arch/sparc/prom/ 1269 - libs-y += arch/sparc/lib/ 1270 - 1271 - drivers-$(CONFIG_PM) += arch/sparc/power/ 1272 - 1273 - 7.5 Architecture-specific boot images 1274 - ------------------------------------- 1275 - 1276 - An arch Makefile specifies goals that take the vmlinux file, compress 1277 - it, wrap it in bootstrapping code, and copy the resulting files 1278 - somewhere. This includes various kinds of installation commands. 1279 - The actual goals are not standardized across architectures. 1280 - 1281 - It is common to locate any additional processing in a boot/ 1282 - directory below arch/$(SRCARCH)/. 1283 - 1284 - Kbuild does not provide any smart way to support building a 1285 - target specified in boot/. Therefore arch/$(SRCARCH)/Makefile shall 1286 - call make manually to build a target in boot/. 1287 - 1288 - The recommended approach is to include shortcuts in 1289 - arch/$(SRCARCH)/Makefile, and use the full path when calling down 1290 - into the arch/$(SRCARCH)/boot/Makefile. 1291 - 1292 - Example:: 1293 - 1294 - #arch/x86/Makefile 1295 - boot := arch/x86/boot 1296 - bzImage: vmlinux 1297 - $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 1298 - 1299 - "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke 1300 - make in a subdirectory. 1301 - 1302 - There are no rules for naming architecture-specific targets, 1303 - but executing "make help" will list all relevant targets. 1304 - To support this, $(archhelp) must be defined. 1305 - 1306 - Example:: 1307 - 1308 - #arch/x86/Makefile 1309 - define archhelp 1310 - echo '* bzImage - Compressed kernel image (arch/x86/boot/bzImage)' 1311 - endif 1312 - 1313 - When make is executed without arguments, the first goal encountered 1314 - will be built. In the top level Makefile the first goal present 1315 - is all:. 1316 - An architecture shall always, per default, build a bootable image. 1317 - In "make help", the default goal is highlighted with a '*'. 1318 - Add a new prerequisite to all: to select a default goal different 1319 - from vmlinux. 1320 - 1321 - Example:: 1322 - 1323 - #arch/x86/Makefile 1324 - all: bzImage 1325 - 1326 - When "make" is executed without arguments, bzImage will be built. 1327 - 1328 - 7.7 Commands useful for building a boot image 1329 - --------------------------------------------- 1330 - 1331 - Kbuild provides a few macros that are useful when building a 1332 - boot image. 1333 - 1334 - ld 1335 - Link target. Often, LDFLAGS_$@ is used to set specific options to ld. 1336 - 1337 - Example:: 1338 - 1339 - #arch/x86/boot/Makefile 1340 - LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary 1341 - LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext 1342 - 1343 - targets += setup setup.o bootsect bootsect.o 1344 - $(obj)/setup $(obj)/bootsect: %: %.o FORCE 1345 - $(call if_changed,ld) 1346 - 1347 - In this example, there are two possible targets, requiring different 1348 - options to the linker. The linker options are specified using the 1349 - LDFLAGS_$@ syntax - one for each potential target. 1350 - $(targets) are assigned all potential targets, by which kbuild knows 1351 - the targets and will: 1352 - 1353 - 1) check for commandline changes 1354 - 2) delete target during make clean 1355 - 1356 - The ": %: %.o" part of the prerequisite is a shorthand that 1357 - frees us from listing the setup.o and bootsect.o files. 1358 - 1359 - Note: 1360 - It is a common mistake to forget the "targets :=" assignment, 1361 - resulting in the target file being recompiled for no 1362 - obvious reason. 1363 - 1364 - objcopy 1365 - Copy binary. Uses OBJCOPYFLAGS usually specified in 1366 - arch/$(SRCARCH)/Makefile. 1367 - OBJCOPYFLAGS_$@ may be used to set additional options. 1368 - 1369 - gzip 1370 - Compress target. Use maximum compression to compress target. 1371 - 1372 - Example:: 1373 - 1374 - #arch/x86/boot/compressed/Makefile 1375 - $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 1376 - $(call if_changed,gzip) 1377 - 1378 - dtc 1379 - Create flattened device tree blob object suitable for linking 1380 - into vmlinux. Device tree blobs linked into vmlinux are placed 1381 - in an init section in the image. Platform code *must* copy the 1382 - blob to non-init memory prior to calling unflatten_device_tree(). 1383 - 1384 - To use this command, simply add `*.dtb` into obj-y or targets, or make 1385 - some other target depend on `%.dtb` 1386 - 1387 - A central rule exists to create `$(obj)/%.dtb` from `$(src)/%.dts`; 1388 - architecture Makefiles do no need to explicitly write out that rule. 1389 - 1390 - Example:: 1391 - 1392 - targets += $(dtb-y) 1393 - DTC_FLAGS ?= -p 1024 1394 - 1395 - 7.9 Preprocessing linker scripts 1291 + Add prerequisites to archheaders 1396 1292 -------------------------------- 1397 1293 1398 - When the vmlinux image is built, the linker script 1399 - arch/$(SRCARCH)/kernel/vmlinux.lds is used. 1400 - The script is a preprocessed variant of the file vmlinux.lds.S 1401 - located in the same directory. 1402 - kbuild knows .lds files and includes a rule `*lds.S` -> `*lds`. 1294 + The archheaders: rule is used to generate header files that 1295 + may be installed into user space by ``make header_install``. 1403 1296 1404 - Example:: 1297 + It is run before ``make archprepare`` when run on the 1298 + architecture itself. 1405 1299 1406 - #arch/x86/kernel/Makefile 1407 - extra-y := vmlinux.lds 1300 + Add prerequisites to archprepare 1301 + -------------------------------- 1408 1302 1409 - The assignment to extra-y is used to tell kbuild to build the 1410 - target vmlinux.lds. 1411 - The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the 1412 - specified options when building the target vmlinux.lds. 1303 + The archprepare: rule is used to list prerequisites that need to be 1304 + built before starting to descend down in the subdirectories. 1413 1305 1414 - When building the `*.lds` target, kbuild uses the variables:: 1306 + This is usually used for header files containing assembler constants. 1415 1307 1416 - KBUILD_CPPFLAGS : Set in top-level Makefile 1417 - cppflags-y : May be set in the kbuild makefile 1418 - CPPFLAGS_$(@F) : Target-specific flags. 1419 - Note that the full filename is used in this 1420 - assignment. 1308 + Example:: 1421 1309 1422 - The kbuild infrastructure for `*lds` files is used in several 1423 - architecture-specific files. 1310 + #arch/arm/Makefile 1311 + archprepare: maketools 1424 1312 1425 - 7.10 Generic header files 1426 - ------------------------- 1313 + In this example, the file target maketools will be processed 1314 + before descending down in the subdirectories. 1427 1315 1428 - The directory include/asm-generic contains the header files 1429 - that may be shared between individual architectures. 1430 - The recommended approach how to use a generic header file is 1431 - to list the file in the Kbuild file. 1432 - See "8.2 generic-y" for further info on syntax etc. 1316 + See also chapter XXX-TODO that describes how kbuild supports 1317 + generating offset header files. 1433 1318 1434 - 7.11 Post-link pass 1435 - ------------------- 1319 + List directories to visit when descending 1320 + ----------------------------------------- 1436 1321 1437 - If the file arch/xxx/Makefile.postlink exists, this makefile 1438 - will be invoked for post-link objects (vmlinux and modules.ko) 1439 - for architectures to run post-link passes on. Must also handle 1440 - the clean target. 1322 + An arch Makefile cooperates with the top Makefile to define variables 1323 + which specify how to build the vmlinux file. Note that there is no 1324 + corresponding arch-specific section for modules; the module-building 1325 + machinery is all architecture-independent. 1441 1326 1442 - This pass runs after kallsyms generation. If the architecture 1443 - needs to modify symbol locations, rather than manipulate the 1444 - kallsyms, it may be easier to add another postlink target for 1445 - .tmp_vmlinux? targets to be called from link-vmlinux.sh. 1327 + core-y, libs-y, drivers-y 1328 + $(libs-y) lists directories where a lib.a archive can be located. 1446 1329 1447 - For example, powerpc uses this to check relocation sanity of 1448 - the linked vmlinux file. 1330 + The rest list directories where a built-in.a object file can be 1331 + located. 1449 1332 1450 - 8 Kbuild syntax for exported headers 1451 - ------------------------------------ 1333 + Then the rest follows in this order: 1334 + 1335 + $(core-y), $(libs-y), $(drivers-y) 1336 + 1337 + The top level Makefile defines values for all generic directories, 1338 + and arch/$(SRCARCH)/Makefile only adds architecture-specific 1339 + directories. 1340 + 1341 + Example:: 1342 + 1343 + # arch/sparc/Makefile 1344 + core-y += arch/sparc/ 1345 + 1346 + libs-y += arch/sparc/prom/ 1347 + libs-y += arch/sparc/lib/ 1348 + 1349 + drivers-$(CONFIG_PM) += arch/sparc/power/ 1350 + 1351 + Architecture-specific boot images 1352 + --------------------------------- 1353 + 1354 + An arch Makefile specifies goals that take the vmlinux file, compress 1355 + it, wrap it in bootstrapping code, and copy the resulting files 1356 + somewhere. This includes various kinds of installation commands. 1357 + The actual goals are not standardized across architectures. 1358 + 1359 + It is common to locate any additional processing in a boot/ 1360 + directory below arch/$(SRCARCH)/. 1361 + 1362 + Kbuild does not provide any smart way to support building a 1363 + target specified in boot/. Therefore arch/$(SRCARCH)/Makefile shall 1364 + call make manually to build a target in boot/. 1365 + 1366 + The recommended approach is to include shortcuts in 1367 + arch/$(SRCARCH)/Makefile, and use the full path when calling down 1368 + into the arch/$(SRCARCH)/boot/Makefile. 1369 + 1370 + Example:: 1371 + 1372 + #arch/x86/Makefile 1373 + boot := arch/x86/boot 1374 + bzImage: vmlinux 1375 + $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 1376 + 1377 + ``$(Q)$(MAKE) $(build)=<dir>`` is the recommended way to invoke 1378 + make in a subdirectory. 1379 + 1380 + There are no rules for naming architecture-specific targets, 1381 + but executing ``make help`` will list all relevant targets. 1382 + To support this, $(archhelp) must be defined. 1383 + 1384 + Example:: 1385 + 1386 + #arch/x86/Makefile 1387 + define archhelp 1388 + echo '* bzImage - Compressed kernel image (arch/x86/boot/bzImage)' 1389 + endif 1390 + 1391 + When make is executed without arguments, the first goal encountered 1392 + will be built. In the top level Makefile the first goal present 1393 + is all:. 1394 + 1395 + An architecture shall always, per default, build a bootable image. 1396 + In ``make help``, the default goal is highlighted with a ``*``. 1397 + 1398 + Add a new prerequisite to all: to select a default goal different 1399 + from vmlinux. 1400 + 1401 + Example:: 1402 + 1403 + #arch/x86/Makefile 1404 + all: bzImage 1405 + 1406 + When ``make`` is executed without arguments, bzImage will be built. 1407 + 1408 + Commands useful for building a boot image 1409 + ----------------------------------------- 1410 + 1411 + Kbuild provides a few macros that are useful when building a 1412 + boot image. 1413 + 1414 + ld 1415 + Link target. Often, LDFLAGS_$@ is used to set specific options to ld. 1416 + 1417 + Example:: 1418 + 1419 + #arch/x86/boot/Makefile 1420 + LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary 1421 + LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext 1422 + 1423 + targets += setup setup.o bootsect bootsect.o 1424 + $(obj)/setup $(obj)/bootsect: %: %.o FORCE 1425 + $(call if_changed,ld) 1426 + 1427 + In this example, there are two possible targets, requiring different 1428 + options to the linker. The linker options are specified using the 1429 + LDFLAGS_$@ syntax - one for each potential target. 1430 + 1431 + $(targets) are assigned all potential targets, by which kbuild knows 1432 + the targets and will: 1433 + 1434 + 1) check for commandline changes 1435 + 2) delete target during make clean 1436 + 1437 + The ``: %: %.o`` part of the prerequisite is a shorthand that 1438 + frees us from listing the setup.o and bootsect.o files. 1439 + 1440 + Note: 1441 + It is a common mistake to forget the ``targets :=`` assignment, 1442 + resulting in the target file being recompiled for no 1443 + obvious reason. 1444 + 1445 + objcopy 1446 + Copy binary. Uses OBJCOPYFLAGS usually specified in 1447 + arch/$(SRCARCH)/Makefile. 1448 + 1449 + OBJCOPYFLAGS_$@ may be used to set additional options. 1450 + 1451 + gzip 1452 + Compress target. Use maximum compression to compress target. 1453 + 1454 + Example:: 1455 + 1456 + #arch/x86/boot/compressed/Makefile 1457 + $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 1458 + $(call if_changed,gzip) 1459 + 1460 + dtc 1461 + Create flattened device tree blob object suitable for linking 1462 + into vmlinux. Device tree blobs linked into vmlinux are placed 1463 + in an init section in the image. Platform code *must* copy the 1464 + blob to non-init memory prior to calling unflatten_device_tree(). 1465 + 1466 + To use this command, simply add ``*.dtb`` into obj-y or targets, or make 1467 + some other target depend on ``%.dtb`` 1468 + 1469 + A central rule exists to create ``$(obj)/%.dtb`` from ``$(src)/%.dts``; 1470 + architecture Makefiles do no need to explicitly write out that rule. 1471 + 1472 + Example:: 1473 + 1474 + targets += $(dtb-y) 1475 + DTC_FLAGS ?= -p 1024 1476 + 1477 + Preprocessing linker scripts 1478 + ---------------------------- 1479 + 1480 + When the vmlinux image is built, the linker script 1481 + arch/$(SRCARCH)/kernel/vmlinux.lds is used. 1482 + 1483 + The script is a preprocessed variant of the file vmlinux.lds.S 1484 + located in the same directory. 1485 + 1486 + kbuild knows .lds files and includes a rule ``*lds.S`` -> ``*lds``. 1487 + 1488 + Example:: 1489 + 1490 + #arch/x86/kernel/Makefile 1491 + extra-y := vmlinux.lds 1492 + 1493 + The assignment to extra-y is used to tell kbuild to build the 1494 + target vmlinux.lds. 1495 + 1496 + The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the 1497 + specified options when building the target vmlinux.lds. 1498 + 1499 + When building the ``*.lds`` target, kbuild uses the variables:: 1500 + 1501 + KBUILD_CPPFLAGS : Set in top-level Makefile 1502 + cppflags-y : May be set in the kbuild makefile 1503 + CPPFLAGS_$(@F) : Target-specific flags. 1504 + Note that the full filename is used in this 1505 + assignment. 1506 + 1507 + The kbuild infrastructure for ``*lds`` files is used in several 1508 + architecture-specific files. 1509 + 1510 + Generic header files 1511 + -------------------- 1512 + 1513 + The directory include/asm-generic contains the header files 1514 + that may be shared between individual architectures. 1515 + 1516 + The recommended approach how to use a generic header file is 1517 + to list the file in the Kbuild file. 1518 + 1519 + See `generic-y`_ for further info on syntax etc. 1520 + 1521 + Post-link pass 1522 + -------------- 1523 + 1524 + If the file arch/xxx/Makefile.postlink exists, this makefile 1525 + will be invoked for post-link objects (vmlinux and modules.ko) 1526 + for architectures to run post-link passes on. Must also handle 1527 + the clean target. 1528 + 1529 + This pass runs after kallsyms generation. If the architecture 1530 + needs to modify symbol locations, rather than manipulate the 1531 + kallsyms, it may be easier to add another postlink target for 1532 + .tmp_vmlinux? targets to be called from link-vmlinux.sh. 1533 + 1534 + For example, powerpc uses this to check relocation sanity of 1535 + the linked vmlinux file. 1536 + 1537 + Kbuild syntax for exported headers 1538 + ================================== 1452 1539 1453 1540 The kernel includes a set of headers that is exported to userspace. 1454 1541 Many headers can be exported as-is but other headers require a 1455 1542 minimal pre-processing before they are ready for user-space. 1543 + 1456 1544 The pre-processing does: 1457 1545 1458 1546 - drop kernel-specific annotations 1459 1547 - drop include of compiler.h 1460 - - drop all sections that are kernel internal (guarded by `ifdef __KERNEL__`) 1548 + - drop all sections that are kernel internal (guarded by ``ifdef __KERNEL__``) 1461 1549 1462 1550 All headers under include/uapi/, include/generated/uapi/, 1463 1551 arch/<arch>/include/uapi/ and arch/<arch>/include/generated/uapi/ ··· 1492 1526 1493 1527 A Kbuild file may be defined under arch/<arch>/include/uapi/asm/ and 1494 1528 arch/<arch>/include/asm/ to list asm files coming from asm-generic. 1529 + 1495 1530 See subsequent chapter for the syntax of the Kbuild file. 1496 1531 1497 - 8.1 no-export-headers 1498 - --------------------- 1532 + no-export-headers 1533 + ----------------- 1499 1534 1500 - no-export-headers is essentially used by include/uapi/linux/Kbuild to 1501 - avoid exporting specific headers (e.g. kvm.h) on architectures that do 1502 - not support it. It should be avoided as much as possible. 1535 + no-export-headers is essentially used by include/uapi/linux/Kbuild to 1536 + avoid exporting specific headers (e.g. kvm.h) on architectures that do 1537 + not support it. It should be avoided as much as possible. 1503 1538 1504 - 8.2 generic-y 1505 - ------------- 1539 + generic-y 1540 + --------- 1506 1541 1507 - If an architecture uses a verbatim copy of a header from 1508 - include/asm-generic then this is listed in the file 1509 - arch/$(SRCARCH)/include/asm/Kbuild like this: 1542 + If an architecture uses a verbatim copy of a header from 1543 + include/asm-generic then this is listed in the file 1544 + arch/$(SRCARCH)/include/asm/Kbuild like this: 1510 1545 1511 - Example:: 1546 + Example:: 1512 1547 1513 - #arch/x86/include/asm/Kbuild 1514 - generic-y += termios.h 1515 - generic-y += rtc.h 1548 + #arch/x86/include/asm/Kbuild 1549 + generic-y += termios.h 1550 + generic-y += rtc.h 1516 1551 1517 - During the prepare phase of the build a wrapper include 1518 - file is generated in the directory:: 1552 + During the prepare phase of the build a wrapper include 1553 + file is generated in the directory:: 1519 1554 1520 - arch/$(SRCARCH)/include/generated/asm 1555 + arch/$(SRCARCH)/include/generated/asm 1521 1556 1522 - When a header is exported where the architecture uses 1523 - the generic header a similar wrapper is generated as part 1524 - of the set of exported headers in the directory:: 1557 + When a header is exported where the architecture uses 1558 + the generic header a similar wrapper is generated as part 1559 + of the set of exported headers in the directory:: 1525 1560 1526 - usr/include/asm 1561 + usr/include/asm 1527 1562 1528 - The generated wrapper will in both cases look like the following: 1563 + The generated wrapper will in both cases look like the following: 1529 1564 1530 - Example: termios.h:: 1565 + Example: termios.h:: 1531 1566 1532 - #include <asm-generic/termios.h> 1567 + #include <asm-generic/termios.h> 1533 1568 1534 - 8.3 generated-y 1535 - --------------- 1569 + generated-y 1570 + ----------- 1536 1571 1537 - If an architecture generates other header files alongside generic-y 1538 - wrappers, generated-y specifies them. 1572 + If an architecture generates other header files alongside generic-y 1573 + wrappers, generated-y specifies them. 1539 1574 1540 - This prevents them being treated as stale asm-generic wrappers and 1541 - removed. 1575 + This prevents them being treated as stale asm-generic wrappers and 1576 + removed. 1542 1577 1543 - Example:: 1578 + Example:: 1544 1579 1545 - #arch/x86/include/asm/Kbuild 1546 - generated-y += syscalls_32.h 1580 + #arch/x86/include/asm/Kbuild 1581 + generated-y += syscalls_32.h 1547 1582 1548 - 8.4 mandatory-y 1549 - --------------- 1583 + mandatory-y 1584 + ----------- 1550 1585 1551 - mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild 1552 - to define the minimum set of ASM headers that all architectures must have. 1586 + mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild 1587 + to define the minimum set of ASM headers that all architectures must have. 1553 1588 1554 - This works like optional generic-y. If a mandatory header is missing 1555 - in arch/$(SRCARCH)/include/(uapi/)/asm, Kbuild will automatically 1556 - generate a wrapper of the asm-generic one. 1589 + This works like optional generic-y. If a mandatory header is missing 1590 + in arch/$(SRCARCH)/include/(uapi/)/asm, Kbuild will automatically 1591 + generate a wrapper of the asm-generic one. 1557 1592 1558 - 9 Kbuild Variables 1559 - ================== 1593 + Kbuild Variables 1594 + ================ 1560 1595 1561 1596 The top Makefile exports the following variables: 1562 1597 1563 - VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION 1564 - These variables define the current kernel version. A few arch 1565 - Makefiles actually use these values directly; they should use 1566 - $(KERNELRELEASE) instead. 1598 + VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION 1599 + These variables define the current kernel version. A few arch 1600 + Makefiles actually use these values directly; they should use 1601 + $(KERNELRELEASE) instead. 1567 1602 1568 - $(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic 1569 - three-part version number, such as "2", "4", and "0". These three 1570 - values are always numeric. 1603 + $(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic 1604 + three-part version number, such as "2", "4", and "0". These three 1605 + values are always numeric. 1571 1606 1572 - $(EXTRAVERSION) defines an even tinier sublevel for pre-patches 1573 - or additional patches. It is usually some non-numeric string 1574 - such as "-pre4", and is often blank. 1607 + $(EXTRAVERSION) defines an even tinier sublevel for pre-patches 1608 + or additional patches. It is usually some non-numeric string 1609 + such as "-pre4", and is often blank. 1575 1610 1576 - KERNELRELEASE 1577 - $(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable 1578 - for constructing installation directory names or showing in 1579 - version strings. Some arch Makefiles use it for this purpose. 1611 + KERNELRELEASE 1612 + $(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable 1613 + for constructing installation directory names or showing in 1614 + version strings. Some arch Makefiles use it for this purpose. 1580 1615 1581 - ARCH 1582 - This variable defines the target architecture, such as "i386", 1583 - "arm", or "sparc". Some kbuild Makefiles test $(ARCH) to 1584 - determine which files to compile. 1616 + ARCH 1617 + This variable defines the target architecture, such as "i386", 1618 + "arm", or "sparc". Some kbuild Makefiles test $(ARCH) to 1619 + determine which files to compile. 1585 1620 1586 - By default, the top Makefile sets $(ARCH) to be the same as the 1587 - host system architecture. For a cross build, a user may 1588 - override the value of $(ARCH) on the command line:: 1621 + By default, the top Makefile sets $(ARCH) to be the same as the 1622 + host system architecture. For a cross build, a user may 1623 + override the value of $(ARCH) on the command line:: 1589 1624 1590 - make ARCH=m68k ... 1625 + make ARCH=m68k ... 1591 1626 1592 - SRCARCH 1593 - This variable specifies the directory in arch/ to build. 1627 + SRCARCH 1628 + This variable specifies the directory in arch/ to build. 1594 1629 1595 - ARCH and SRCARCH may not necessarily match. A couple of arch 1596 - directories are biarch, that is, a single `arch/*/` directory supports 1597 - both 32-bit and 64-bit. 1630 + ARCH and SRCARCH may not necessarily match. A couple of arch 1631 + directories are biarch, that is, a single ``arch/*/`` directory supports 1632 + both 32-bit and 64-bit. 1598 1633 1599 - For example, you can pass in ARCH=i386, ARCH=x86_64, or ARCH=x86. 1600 - For all of them, SRCARCH=x86 because arch/x86/ supports both i386 and 1601 - x86_64. 1634 + For example, you can pass in ARCH=i386, ARCH=x86_64, or ARCH=x86. 1635 + For all of them, SRCARCH=x86 because arch/x86/ supports both i386 and 1636 + x86_64. 1602 1637 1603 - INSTALL_PATH 1604 - This variable defines a place for the arch Makefiles to install 1605 - the resident kernel image and System.map file. 1606 - Use this for architecture-specific install targets. 1638 + INSTALL_PATH 1639 + This variable defines a place for the arch Makefiles to install 1640 + the resident kernel image and System.map file. 1641 + Use this for architecture-specific install targets. 1607 1642 1608 - INSTALL_MOD_PATH, MODLIB 1609 - $(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module 1610 - installation. This variable is not defined in the Makefile but 1611 - may be passed in by the user if desired. 1643 + INSTALL_MOD_PATH, MODLIB 1644 + $(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module 1645 + installation. This variable is not defined in the Makefile but 1646 + may be passed in by the user if desired. 1612 1647 1613 - $(MODLIB) specifies the directory for module installation. 1614 - The top Makefile defines $(MODLIB) to 1615 - $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may 1616 - override this value on the command line if desired. 1648 + $(MODLIB) specifies the directory for module installation. 1649 + The top Makefile defines $(MODLIB) to 1650 + $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may 1651 + override this value on the command line if desired. 1617 1652 1618 - INSTALL_MOD_STRIP 1619 - If this variable is specified, it will cause modules to be stripped 1620 - after they are installed. If INSTALL_MOD_STRIP is '1', then the 1621 - default option --strip-debug will be used. Otherwise, the 1622 - INSTALL_MOD_STRIP value will be used as the option(s) to the strip 1623 - command. 1653 + INSTALL_MOD_STRIP 1654 + If this variable is specified, it will cause modules to be stripped 1655 + after they are installed. If INSTALL_MOD_STRIP is "1", then the 1656 + default option --strip-debug will be used. Otherwise, the 1657 + INSTALL_MOD_STRIP value will be used as the option(s) to the strip 1658 + command. 1624 1659 1625 - 1626 - 10 Makefile language 1627 - ==================== 1660 + Makefile language 1661 + ================= 1628 1662 1629 1663 The kernel Makefiles are designed to be run with GNU Make. The Makefiles 1630 1664 use only the documented features of GNU Make, but they do use many ··· 1632 1666 1633 1667 GNU Make supports elementary list-processing functions. The kernel 1634 1668 Makefiles use a novel style of list building and manipulation with few 1635 - "if" statements. 1669 + ``if`` statements. 1636 1670 1637 - GNU Make has two assignment operators, ":=" and "=". ":=" performs 1671 + GNU Make has two assignment operators, ``:=`` and ``=``. ``:=`` performs 1638 1672 immediate evaluation of the right-hand side and stores an actual string 1639 - into the left-hand side. "=" is like a formula definition; it stores the 1673 + into the left-hand side. ``=`` is like a formula definition; it stores the 1640 1674 right-hand side in an unevaluated form and then evaluates this form each 1641 1675 time the left-hand side is used. 1642 1676 1643 - There are some cases where "=" is appropriate. Usually, though, ":=" 1677 + There are some cases where ``=`` is appropriate. Usually, though, ``:=`` 1644 1678 is the right choice. 1645 1679 1646 - 11 Credits 1647 - ========== 1680 + Credits 1681 + ======= 1648 1682 1649 1683 - Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net> 1650 1684 - Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de> 1651 1685 - Updates by Sam Ravnborg <sam@ravnborg.org> 1652 1686 - Language QA by Jan Engelhardt <jengelh@gmx.de> 1653 1687 1654 - 12 TODO 1655 - ======= 1688 + TODO 1689 + ==== 1656 1690 1657 1691 - Describe how kbuild supports shipped files with _shipped. 1658 1692 - Generating offset header files.
+1 -1
MAINTAINERS
··· 11085 11085 L: linux-kbuild@vger.kernel.org 11086 11086 S: Maintained 11087 11087 Q: https://patchwork.kernel.org/project/linux-kbuild/list/ 11088 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kconfig 11088 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kbuild 11089 11089 F: Documentation/kbuild/kconfig* 11090 11090 F: scripts/Kconfig.include 11091 11091 F: scripts/kconfig/
+47 -46
Makefile
··· 56 56 # Beautify output 57 57 # --------------------------------------------------------------------------- 58 58 # 59 - # Normally, we echo the whole command before executing it. By making 60 - # that echo $($(quiet)$(cmd)), we now have the possibility to set 61 - # $(quiet) to choose other forms of output instead, e.g. 59 + # Most of build commands in Kbuild start with "cmd_". You can optionally define 60 + # "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from 61 + # that command is printed by default. 62 62 # 63 - # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ 64 - # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 65 - # 66 - # If $(quiet) is empty, the whole command will be printed. 67 - # If it is set to "quiet_", only the short version will be printed. 68 - # If it is set to "silent_", nothing will be printed at all, since 69 - # the variable $(silent_cmd_cc_o_c) doesn't exist. 63 + # e.g.) 64 + # quiet_cmd_depmod = DEPMOD $(MODLIB) 65 + # cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE) 70 66 # 71 67 # A simple variant is to prefix commands with $(Q) - that's useful 72 68 # for commands that shall be hidden in non-verbose mode. 73 69 # 74 - # $(Q)ln $@ :< 70 + # $(Q)$(MAKE) $(build)=scripts/basic 75 71 # 76 - # If KBUILD_VERBOSE equals 0 then the above command will be hidden. 77 - # If KBUILD_VERBOSE equals 1 then the above command is displayed. 78 - # If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt. 72 + # If KBUILD_VERBOSE contains 1, the whole command is echoed. 73 + # If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed. 79 74 # 80 75 # To put more focus on warnings, be less verbose as default 81 76 # Use 'make V=1' to see the full commands ··· 78 83 ifeq ("$(origin V)", "command line") 79 84 KBUILD_VERBOSE = $(V) 80 85 endif 81 - ifndef KBUILD_VERBOSE 82 - KBUILD_VERBOSE = 0 83 - endif 84 86 85 - ifeq ($(KBUILD_VERBOSE),1) 87 + quiet = quiet_ 88 + Q = @ 89 + 90 + ifneq ($(findstring 1, $(KBUILD_VERBOSE)),) 86 91 quiet = 87 92 Q = 88 - else 89 - quiet=quiet_ 90 - Q = @ 91 93 endif 92 94 93 95 # If the user is running make -s (silent mode), suppress echoing of ··· 92 100 # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. 93 101 94 102 ifeq ($(filter 3.%,$(MAKE_VERSION)),) 95 - silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) 103 + short-opts := $(firstword -$(MAKEFLAGS)) 96 104 else 97 - silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS))) 105 + short-opts := $(filter-out --%,$(MAKEFLAGS)) 98 106 endif 99 107 100 - ifeq ($(silence),s) 108 + ifneq ($(findstring s,$(short-opts)),) 101 109 quiet=silent_ 102 - KBUILD_VERBOSE = 0 110 + override KBUILD_VERBOSE := 103 111 endif 104 112 105 113 export quiet Q KBUILD_VERBOSE ··· 203 211 $(error source directory cannot contain spaces or colons) 204 212 endif 205 213 206 - ifneq ($(abs_srctree),$(abs_objtree)) 207 - # Look for make include files relative to root of kernel src 208 - # 209 - # --included-dir is added for backward compatibility, but you should not rely on 210 - # it. Please add $(srctree)/ prefix to include Makefiles in the source tree. 211 - MAKEFLAGS += --include-dir=$(abs_srctree) 212 - endif 213 - 214 214 ifneq ($(filter 3.%,$(MAKE_VERSION)),) 215 215 # 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x 216 216 # We need to invoke sub-make to avoid implicit rules in the top Makefile. ··· 274 290 cscope gtags TAGS tags help% %docs check% coccicheck \ 275 291 $(version_h) headers headers_% archheaders archscripts \ 276 292 %asm-generic kernelversion %src-pkg dt_binding_check \ 277 - outputmakefile rustavailable rustfmt rustfmtcheck 293 + outputmakefile rustavailable rustfmt rustfmtcheck \ 294 + scripts_package 278 295 # Installation targets should not require compiler. Unfortunately, vdso_install 279 296 # is an exception where build artifacts may be updated. This must be fixed. 280 297 no-compiler-targets := $(no-dot-config-targets) install dtbs_install \ ··· 562 577 -std=gnu11 563 578 KBUILD_CPPFLAGS := -D__KERNEL__ 564 579 KBUILD_RUSTFLAGS := $(rust_common_flags) \ 565 - --target=$(objtree)/rust/target.json \ 580 + --target=$(objtree)/scripts/target.json \ 566 581 -Cpanic=abort -Cembed-bitcode=n -Clto=n \ 567 582 -Cforce-unwind-tables=n -Ccodegen-units=1 \ 568 583 -Csymbol-mangling-version=v0 \ ··· 863 878 KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y) 864 879 865 880 ifdef CONFIG_CC_IS_CLANG 866 - KBUILD_CPPFLAGS += -Qunused-arguments 867 881 # The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable. 868 882 KBUILD_CFLAGS += -Wno-gnu 869 883 else ··· 905 921 KBUILD_CFLAGS += -ftrivial-auto-var-init=zero 906 922 ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER 907 923 # https://github.com/llvm/llvm-project/issues/44842 908 - KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 924 + CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 925 + export CC_AUTO_VAR_INIT_ZERO_ENABLER 926 + KBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER) 909 927 endif 910 928 endif 911 929 ··· 1253 1267 # make sure no implicit rule kicks in 1254 1268 $(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ; 1255 1269 1256 - filechk_kernel.release = \ 1257 - echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" 1270 + ifeq ($(origin KERNELRELEASE),file) 1271 + filechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree) 1272 + else 1273 + filechk_kernel.release = echo $(KERNELRELEASE) 1274 + endif 1258 1275 1259 1276 # Store (new) KERNELRELEASE string in include/config/kernel.release 1260 1277 include/config/kernel.release: FORCE ··· 1534 1545 # Build modules 1535 1546 # 1536 1547 1537 - # *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFOBTF_MODULES 1548 + # *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES 1538 1549 # is an exception. 1539 1550 ifdef CONFIG_DEBUG_INFO_BTF_MODULES 1540 1551 KBUILD_BUILTIN := 1 ··· 1606 1617 certs/x509.genkey \ 1607 1618 vmlinux-gdb.py \ 1608 1619 *.spec \ 1609 - rust/target.json rust/libmacros.so 1620 + rust/libmacros.so 1610 1621 1611 1622 # clean - Delete most, but leave enough to build external modules 1612 1623 # ··· 1655 1666 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 1656 1667 %pkg: include/config/kernel.release FORCE 1657 1668 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 1669 + 1670 + PHONY += scripts_package 1671 + scripts_package: scripts_basic 1672 + $(Q)$(MAKE) $(build)=scripts scripts/list-gitignored 1658 1673 1659 1674 # Brief documentation of the typical targets used 1660 1675 # --------------------------------------------------------------------------- ··· 1775 1782 printf " %-16s - Show all of the above\\n" help-boards; \ 1776 1783 echo '') 1777 1784 1778 - @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' 1779 - @echo ' make V=2 [targets] 2 => give reason for rebuild of target' 1785 + @echo ' make V=n [targets] 1: verbose build' 1786 + @echo ' 2: give reason for rebuild of target' 1787 + @echo ' V=1 and V=2 can be combined with V=12' 1780 1788 @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 1781 1789 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' 1782 1790 @echo ' (sparse by default)' ··· 1868 1874 1869 1875 # Misc 1870 1876 # --------------------------------------------------------------------------- 1877 + 1878 + PHONY += misc-check 1879 + misc-check: 1880 + $(Q)$(srctree)/scripts/misc-check 1881 + 1882 + all: misc-check 1871 1883 1872 1884 PHONY += scripts_gdb 1873 1885 scripts_gdb: prepare0 ··· 2046 2046 -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 2047 2047 -o -name '*.asn1.[ch]' \ 2048 2048 -o -name '*.symtypes' -o -name 'modules.order' \ 2049 - -o -name '.tmp_*' \ 2050 2049 -o -name '*.c.[012]*.*' \ 2051 2050 -o -name '*.ll' \ 2052 2051 -o -name '*.gcno' \ 2053 - -o -name '*.*.symversions' \) -type f -print | xargs rm -f 2052 + -o -name '*.*.symversions' \) -type f -print \ 2053 + -o -name '.tmp_*' -print \ 2054 + | xargs rm -rf 2054 2055 2055 2056 # Generate tags for editors 2056 2057 # --------------------------------------------------------------------------- ··· 2133 2132 $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) 2134 2133 2135 2134 kernelrelease: 2136 - @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" 2135 + @$(filechk_kernel.release) 2137 2136 2138 2137 kernelversion: 2139 2138 @echo $(KERNELVERSION)
+1 -1
arch/arm/mach-s3c/Makefile
··· 2 2 # 3 3 # Copyright 2009 Simtec Electronics 4 4 5 - include $(src)/Makefile.s3c64xx 5 + include $(srctree)/$(src)/Makefile.s3c64xx 6 6 7 7 # Objects we always build independent of SoC choice 8 8
+1 -1
arch/ia64/kernel/Makefile
··· 43 43 CFLAGS_traps.o += -mfixed-range=f2-f5,f16-f31 44 44 45 45 # The gate DSO image is built using a special linker script. 46 - include $(src)/Makefile.gate 46 + include $(srctree)/$(src)/Makefile.gate
+1 -1
arch/mips/Kbuild
··· 7 7 endif 8 8 9 9 # platform specific definitions 10 - include arch/mips/Kbuild.platforms 10 + include $(srctree)/arch/mips/Kbuild.platforms 11 11 obj-y := $(platform-y) 12 12 13 13 # make clean traverses $(obj-) without having included .config, so
+2 -11
arch/mips/Makefile
··· 95 95 # crossformat linking we rely on the elf2ecoff tool for format conversion. 96 96 # 97 97 cflags-y += -G 0 -mno-abicalls -fno-pic -pipe 98 - cflags-y += -msoft-float 98 + cflags-y += -msoft-float -Wa,-msoft-float 99 99 LDFLAGS_vmlinux += -G 0 -static -n -nostdlib 100 100 KBUILD_AFLAGS_MODULE += -mlong-calls 101 101 KBUILD_CFLAGS_MODULE += -mlong-calls 102 102 103 103 ifeq ($(CONFIG_RELOCATABLE),y) 104 104 LDFLAGS_vmlinux += --emit-relocs 105 - endif 106 - 107 - # 108 - # pass -msoft-float to GAS if it supports it. However on newer binutils 109 - # (specifically newer than 2.24.51.20140728) we then also need to explicitly 110 - # set ".set hardfloat" in all files which manipulate floating point registers. 111 - # 112 - ifneq ($(call as-option,-Wa$(comma)-msoft-float,),) 113 - cflags-y += -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float 114 105 endif 115 106 116 107 cflags-y += -ffreestanding ··· 143 152 # 144 153 # Avoid this by explicitly disabling that assembler behaviour. 145 154 # 146 - cflags-y += $(call as-option,-Wa$(comma)-mno-fix-loongson3-llsc,) 155 + cflags-y += $(call cc-option,-Wa$(comma)-mno-fix-loongson3-llsc,) 147 156 148 157 # 149 158 # CPU-dependent compiler/assembler options for optimization.
+2 -2
arch/mips/include/asm/asmmacro-32.h
··· 15 15 16 16 .macro fpu_save_single thread tmp=t0 17 17 .set push 18 - SET_HARDFLOAT 18 + .set hardfloat 19 19 cfc1 \tmp, fcr31 20 20 s.d $f0, THREAD_FPR0(\thread) 21 21 s.d $f2, THREAD_FPR2(\thread) ··· 39 39 40 40 .macro fpu_restore_single thread tmp=t0 41 41 .set push 42 - SET_HARDFLOAT 42 + .set hardfloat 43 43 lw \tmp, THREAD_FCR31(\thread) 44 44 l.d $f0, THREAD_FPR0(\thread) 45 45 l.d $f2, THREAD_FPR2(\thread)
+21 -21
arch/mips/include/asm/asmmacro.h
··· 83 83 84 84 .macro fpu_save_16even thread tmp=t0 85 85 .set push 86 - SET_HARDFLOAT 86 + .set hardfloat 87 87 cfc1 \tmp, fcr31 88 88 sdc1 $f0, THREAD_FPR0(\thread) 89 89 sdc1 $f2, THREAD_FPR2(\thread) ··· 109 109 .set push 110 110 .set mips64r2 111 111 .set fp=64 112 - SET_HARDFLOAT 112 + .set hardfloat 113 113 sdc1 $f1, THREAD_FPR1(\thread) 114 114 sdc1 $f3, THREAD_FPR3(\thread) 115 115 sdc1 $f5, THREAD_FPR5(\thread) ··· 142 142 143 143 .macro fpu_restore_16even thread tmp=t0 144 144 .set push 145 - SET_HARDFLOAT 145 + .set hardfloat 146 146 lw \tmp, THREAD_FCR31(\thread) 147 147 ldc1 $f0, THREAD_FPR0(\thread) 148 148 ldc1 $f2, THREAD_FPR2(\thread) ··· 168 168 .set push 169 169 .set mips64r2 170 170 .set fp=64 171 - SET_HARDFLOAT 171 + .set hardfloat 172 172 ldc1 $f1, THREAD_FPR1(\thread) 173 173 ldc1 $f3, THREAD_FPR3(\thread) 174 174 ldc1 $f5, THREAD_FPR5(\thread) ··· 373 373 .macro _cfcmsa rd, cs 374 374 .set push 375 375 .set noat 376 - SET_HARDFLOAT 376 + .set hardfloat 377 377 insn_if_mips 0x787e0059 | (\cs << 11) 378 378 insn32_if_mm 0x587e0056 | (\cs << 11) 379 379 move \rd, $1 ··· 383 383 .macro _ctcmsa cd, rs 384 384 .set push 385 385 .set noat 386 - SET_HARDFLOAT 386 + .set hardfloat 387 387 move $1, \rs 388 388 insn_if_mips 0x783e0819 | (\cd << 6) 389 389 insn32_if_mm 0x583e0816 | (\cd << 6) ··· 393 393 .macro ld_b wd, off, base 394 394 .set push 395 395 .set noat 396 - SET_HARDFLOAT 396 + .set hardfloat 397 397 PTR_ADDU $1, \base, \off 398 398 insn_if_mips 0x78000820 | (\wd << 6) 399 399 insn32_if_mm 0x58000807 | (\wd << 6) ··· 403 403 .macro ld_h wd, off, base 404 404 .set push 405 405 .set noat 406 - SET_HARDFLOAT 406 + .set hardfloat 407 407 PTR_ADDU $1, \base, \off 408 408 insn_if_mips 0x78000821 | (\wd << 6) 409 409 insn32_if_mm 0x58000817 | (\wd << 6) ··· 413 413 .macro ld_w wd, off, base 414 414 .set push 415 415 .set noat 416 - SET_HARDFLOAT 416 + .set hardfloat 417 417 PTR_ADDU $1, \base, \off 418 418 insn_if_mips 0x78000822 | (\wd << 6) 419 419 insn32_if_mm 0x58000827 | (\wd << 6) ··· 423 423 .macro ld_d wd, off, base 424 424 .set push 425 425 .set noat 426 - SET_HARDFLOAT 426 + .set hardfloat 427 427 PTR_ADDU $1, \base, \off 428 428 insn_if_mips 0x78000823 | (\wd << 6) 429 429 insn32_if_mm 0x58000837 | (\wd << 6) ··· 433 433 .macro st_b wd, off, base 434 434 .set push 435 435 .set noat 436 - SET_HARDFLOAT 436 + .set hardfloat 437 437 PTR_ADDU $1, \base, \off 438 438 insn_if_mips 0x78000824 | (\wd << 6) 439 439 insn32_if_mm 0x5800080f | (\wd << 6) ··· 443 443 .macro st_h wd, off, base 444 444 .set push 445 445 .set noat 446 - SET_HARDFLOAT 446 + .set hardfloat 447 447 PTR_ADDU $1, \base, \off 448 448 insn_if_mips 0x78000825 | (\wd << 6) 449 449 insn32_if_mm 0x5800081f | (\wd << 6) ··· 453 453 .macro st_w wd, off, base 454 454 .set push 455 455 .set noat 456 - SET_HARDFLOAT 456 + .set hardfloat 457 457 PTR_ADDU $1, \base, \off 458 458 insn_if_mips 0x78000826 | (\wd << 6) 459 459 insn32_if_mm 0x5800082f | (\wd << 6) ··· 463 463 .macro st_d wd, off, base 464 464 .set push 465 465 .set noat 466 - SET_HARDFLOAT 466 + .set hardfloat 467 467 PTR_ADDU $1, \base, \off 468 468 insn_if_mips 0x78000827 | (\wd << 6) 469 469 insn32_if_mm 0x5800083f | (\wd << 6) ··· 473 473 .macro copy_s_w ws, n 474 474 .set push 475 475 .set noat 476 - SET_HARDFLOAT 476 + .set hardfloat 477 477 insn_if_mips 0x78b00059 | (\n << 16) | (\ws << 11) 478 478 insn32_if_mm 0x58b00056 | (\n << 16) | (\ws << 11) 479 479 .set pop ··· 482 482 .macro copy_s_d ws, n 483 483 .set push 484 484 .set noat 485 - SET_HARDFLOAT 485 + .set hardfloat 486 486 insn_if_mips 0x78b80059 | (\n << 16) | (\ws << 11) 487 487 insn32_if_mm 0x58b80056 | (\n << 16) | (\ws << 11) 488 488 .set pop ··· 491 491 .macro insert_w wd, n 492 492 .set push 493 493 .set noat 494 - SET_HARDFLOAT 494 + .set hardfloat 495 495 insn_if_mips 0x79300819 | (\n << 16) | (\wd << 6) 496 496 insn32_if_mm 0x59300816 | (\n << 16) | (\wd << 6) 497 497 .set pop ··· 500 500 .macro insert_d wd, n 501 501 .set push 502 502 .set noat 503 - SET_HARDFLOAT 503 + .set hardfloat 504 504 insn_if_mips 0x79380819 | (\n << 16) | (\wd << 6) 505 505 insn32_if_mm 0x59380816 | (\n << 16) | (\wd << 6) 506 506 .set pop ··· 553 553 st_d 29, THREAD_FPR29 - FPR_BASE_OFFS, FPR_BASE 554 554 st_d 30, THREAD_FPR30 - FPR_BASE_OFFS, FPR_BASE 555 555 st_d 31, THREAD_FPR31 - FPR_BASE_OFFS, FPR_BASE 556 - SET_HARDFLOAT 556 + .set hardfloat 557 557 _cfcmsa $1, MSA_CSR 558 558 sw $1, THREAD_MSA_CSR(\thread) 559 559 .set pop ··· 562 562 .macro msa_restore_all thread 563 563 .set push 564 564 .set noat 565 - SET_HARDFLOAT 565 + .set hardfloat 566 566 lw $1, THREAD_MSA_CSR(\thread) 567 567 _ctcmsa MSA_CSR, $1 568 568 #ifdef TOOLCHAIN_SUPPORTS_MSA ··· 618 618 .macro msa_init_all_upper 619 619 .set push 620 620 .set noat 621 - SET_HARDFLOAT 621 + .set hardfloat 622 622 not $1, zero 623 623 msa_init_upper 0 624 624 msa_init_upper 1
-14
arch/mips/include/asm/fpregdef.h
··· 14 14 15 15 #include <asm/sgidefs.h> 16 16 17 - /* 18 - * starting with binutils 2.24.51.20140729, MIPS binutils warn about mixing 19 - * hardfloat and softfloat object files. The kernel build uses soft-float by 20 - * default, so we also need to pass -msoft-float along to GAS if it supports it. 21 - * But this in turn causes assembler errors in files which access hardfloat 22 - * registers. We detect if GAS supports "-msoft-float" in the Makefile and 23 - * explicitly put ".set hardfloat" where floating point registers are touched. 24 - */ 25 - #ifdef GAS_HAS_SET_HARDFLOAT 26 - #define SET_HARDFLOAT .set hardfloat 27 - #else 28 - #define SET_HARDFLOAT 29 - #endif 30 - 31 17 #if _MIPS_SIM == _MIPS_SIM_ABI32 32 18 33 19 /*
+4 -16
arch/mips/include/asm/mipsregs.h
··· 2367 2367 /* 2368 2368 * Macros to access the floating point coprocessor control registers 2369 2369 */ 2370 - #define _read_32bit_cp1_register(source, gas_hardfloat) \ 2370 + #define read_32bit_cp1_register(source) \ 2371 2371 ({ \ 2372 2372 unsigned int __res; \ 2373 2373 \ ··· 2377 2377 " # gas fails to assemble cfc1 for some archs, \n" \ 2378 2378 " # like Octeon. \n" \ 2379 2379 " .set mips1 \n" \ 2380 - " "STR(gas_hardfloat)" \n" \ 2380 + " .set hardfloat \n" \ 2381 2381 " cfc1 %0,"STR(source)" \n" \ 2382 2382 " .set pop \n" \ 2383 2383 : "=r" (__res)); \ 2384 2384 __res; \ 2385 2385 }) 2386 2386 2387 - #define _write_32bit_cp1_register(dest, val, gas_hardfloat) \ 2387 + #define write_32bit_cp1_register(dest, val) \ 2388 2388 do { \ 2389 2389 __asm__ __volatile__( \ 2390 2390 " .set push \n" \ 2391 2391 " .set reorder \n" \ 2392 - " "STR(gas_hardfloat)" \n" \ 2392 + " .set hardfloat \n" \ 2393 2393 " ctc1 %0,"STR(dest)" \n" \ 2394 2394 " .set pop \n" \ 2395 2395 : : "r" (val)); \ 2396 2396 } while (0) 2397 - 2398 - #ifdef GAS_HAS_SET_HARDFLOAT 2399 - #define read_32bit_cp1_register(source) \ 2400 - _read_32bit_cp1_register(source, .set hardfloat) 2401 - #define write_32bit_cp1_register(dest, val) \ 2402 - _write_32bit_cp1_register(dest, val, .set hardfloat) 2403 - #else 2404 - #define read_32bit_cp1_register(source) \ 2405 - _read_32bit_cp1_register(source, ) 2406 - #define write_32bit_cp1_register(dest, val) \ 2407 - _write_32bit_cp1_register(dest, val, ) 2408 - #endif 2409 2397 2410 2398 #ifdef TOOLCHAIN_SUPPORTS_DSP 2411 2399 #define rddsp(mask) \
+1 -1
arch/mips/kernel/genex.S
··· 480 480 .set push 481 481 /* gas fails to assemble cfc1 for some archs (octeon).*/ \ 482 482 .set mips1 483 - SET_HARDFLOAT 483 + .set hardfloat 484 484 cfc1 a1, fcr31 485 485 .set pop 486 486 .endm
+2 -2
arch/mips/kernel/r2300_fpu.S
··· 64 64 */ 65 65 LEAF(_save_fp_context) 66 66 .set push 67 - SET_HARDFLOAT 67 + .set hardfloat 68 68 li v0, 0 # assume success 69 69 cfc1 t1, fcr31 70 70 EX2(s.d $f0, 0(a0)) ··· 98 98 */ 99 99 LEAF(_restore_fp_context) 100 100 .set push 101 - SET_HARDFLOAT 101 + .set hardfloat 102 102 li v0, 0 # assume success 103 103 EX(lw t0, (a1)) 104 104 EX2(l.d $f0, 0(a0))
+6 -6
arch/mips/kernel/r4k_fpu.S
··· 26 26 27 27 .macro EX insn, reg, src 28 28 .set push 29 - SET_HARDFLOAT 29 + .set hardfloat 30 30 .set nomacro 31 31 .ex\@: \insn \reg, \src 32 32 .set pop ··· 98 98 */ 99 99 LEAF(_save_fp_context) 100 100 .set push 101 - SET_HARDFLOAT 101 + .set hardfloat 102 102 cfc1 t1, fcr31 103 103 .set pop 104 104 105 105 #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \ 106 106 defined(CONFIG_CPU_MIPSR5) || defined(CONFIG_CPU_MIPSR6) 107 107 .set push 108 - SET_HARDFLOAT 108 + .set hardfloat 109 109 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) 110 110 .set mips32r2 111 111 .set fp=64 ··· 135 135 #endif 136 136 137 137 .set push 138 - SET_HARDFLOAT 138 + .set hardfloat 139 139 /* Store the 16 even double precision registers */ 140 140 EX sdc1 $f0, 0(a0) 141 141 EX sdc1 $f2, 16(a0) ··· 173 173 #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \ 174 174 defined(CONFIG_CPU_MIPSR5) || defined(CONFIG_CPU_MIPSR6) 175 175 .set push 176 - SET_HARDFLOAT 176 + .set hardfloat 177 177 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) 178 178 .set mips32r2 179 179 .set fp=64 ··· 201 201 1: .set pop 202 202 #endif 203 203 .set push 204 - SET_HARDFLOAT 204 + .set hardfloat 205 205 EX ldc1 $f0, 0(a0) 206 206 EX ldc1 $f2, 16(a0) 207 207 EX ldc1 $f4, 32(a0)
+3 -3
arch/mips/kvm/fpu.S
··· 22 22 23 23 LEAF(__kvm_save_fpu) 24 24 .set push 25 - SET_HARDFLOAT 25 + .set hardfloat 26 26 .set fp=64 27 27 mfc0 t0, CP0_STATUS 28 28 sll t0, t0, 5 # is Status.FR set? ··· 66 66 67 67 LEAF(__kvm_restore_fpu) 68 68 .set push 69 - SET_HARDFLOAT 69 + .set hardfloat 70 70 .set fp=64 71 71 mfc0 t0, CP0_STATUS 72 72 sll t0, t0, 5 # is Status.FR set? ··· 110 110 111 111 LEAF(__kvm_restore_fcsr) 112 112 .set push 113 - SET_HARDFLOAT 113 + .set hardfloat 114 114 lw t0, VCPU_FCR31(a0) 115 115 /* 116 116 * The ctc1 must stay at this offset in __kvm_restore_fcsr.
+1 -1
arch/mips/loongson2ef/Platform
··· 25 25 # binutils does not merge support for the flag then we can revisit & remove 26 26 # this later - for now it ensures vendor toolchains don't cause problems. 27 27 # 28 - cflags-$(CONFIG_CPU_LOONGSON2EF) += $(call as-option,-Wa$(comma)-mno-fix-loongson3-llsc,) 28 + cflags-$(CONFIG_CPU_LOONGSON2EF) += $(call cc-option,-Wa$(comma)-mno-fix-loongson3-llsc,) 29 29 30 30 # Enable the workarounds for Loongson2f 31 31 ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS
+1 -1
arch/powerpc/Makefile
··· 90 90 91 91 ifeq ($(HAS_BIARCH),y) 92 92 KBUILD_CFLAGS += -m$(BITS) 93 - KBUILD_AFLAGS += -m$(BITS) -Wl,-a$(BITS) 93 + KBUILD_AFLAGS += -m$(BITS) 94 94 KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION) 95 95 endif 96 96
+4 -5
arch/powerpc/kernel/prom_init_check.sh
··· 51 51 # a leading . on the name, so strip it off here. 52 52 UNDEF="${UNDEF#.}" 53 53 54 - if [ $KBUILD_VERBOSE ]; then 55 - if [ $KBUILD_VERBOSE -ne 0 ]; then 56 - echo "Checking prom_init.o symbol '$UNDEF'" 57 - fi 58 - fi 54 + case "$KBUILD_VERBOSE" in 55 + *1*) 56 + echo "Checking prom_init.o symbol '$UNDEF'" ;; 57 + esac 59 58 60 59 OK=0 61 60 for WHITE in $WHITELIST
+18 -9
arch/powerpc/kernel/vdso/Makefile
··· 16 16 CFLAGS_vgettimeofday-32.o += -ffreestanding -fasynchronous-unwind-tables 17 17 CFLAGS_REMOVE_vgettimeofday-32.o = $(CC_FLAGS_FTRACE) 18 18 CFLAGS_REMOVE_vgettimeofday-32.o += -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc 19 + # This flag is supported by clang for 64-bit but not 32-bit so it will cause 20 + # an unused command line flag warning for this file. 21 + ifdef CONFIG_CC_IS_CLANG 22 + CFLAGS_REMOVE_vgettimeofday-32.o += -fno-stack-clash-protection 23 + endif 19 24 CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) 20 25 CFLAGS_vgettimeofday-64.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) 21 26 CFLAGS_vgettimeofday-64.o += $(call cc-option, -fno-stack-protector) ··· 53 48 KASAN_SANITIZE := n 54 49 KCSAN_SANITIZE := n 55 50 56 - ccflags-y := -shared -fno-common -fno-builtin -nostdlib -Wl,--hash-style=both 57 - ccflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) 51 + ccflags-y := -fno-common -fno-builtin 52 + ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack 53 + ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) 54 + # Filter flags that clang will warn are unused for linking 55 + ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS)) 58 56 59 - CC32FLAGS := -Wl,-soname=linux-vdso32.so.1 -m32 60 - AS32FLAGS := -D__VDSO32__ -s 57 + CC32FLAGS := -m32 58 + LD32FLAGS := -Wl,-soname=linux-vdso32.so.1 59 + AS32FLAGS := -D__VDSO32__ 61 60 62 - CC64FLAGS := -Wl,-soname=linux-vdso64.so.1 63 - AS64FLAGS := -D__VDSO64__ -s 61 + LD64FLAGS := -Wl,-soname=linux-vdso64.so.1 62 + AS64FLAGS := -D__VDSO64__ 64 63 65 64 targets += vdso32.lds 66 65 CPPFLAGS_vdso32.lds += -P -C -Upowerpc ··· 102 93 103 94 # actual build commands 104 95 quiet_cmd_vdso32ld_and_check = VDSO32L $@ 105 - cmd_vdso32ld_and_check = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) -z noexecstack ; $(cmd_vdso_check) 96 + cmd_vdso32ld_and_check = $(VDSOCC) $(ldflags-y) $(CC32FLAGS) $(LD32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) 106 97 quiet_cmd_vdso32as = VDSO32A $@ 107 98 cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $< 108 99 quiet_cmd_vdso32cc = VDSO32C $@ 109 100 cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< 110 101 111 102 quiet_cmd_vdso64ld_and_check = VDSO64L $@ 112 - cmd_vdso64ld_and_check = $(VDSOCC) $(c_flags) $(CC64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) -z noexecstack ; $(cmd_vdso_check) 103 + cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) 113 104 quiet_cmd_vdso64as = VDSO64A $@ 114 - cmd_vdso64as = $(VDSOCC) $(a_flags) $(CC64FLAGS) $(AS64FLAGS) -c -o $@ $< 105 + cmd_vdso64as = $(VDSOCC) $(a_flags) $(AS64FLAGS) -c -o $@ $< 115 106 116 107 OBJECT_FILES_NON_STANDARD := y
+2 -2
arch/s390/kernel/vdso64/Makefile
··· 22 22 KBUILD_CFLAGS += -DBUILD_VDSO -DDISABLE_BRANCH_PROFILING 23 23 24 24 KBUILD_AFLAGS_64 := $(filter-out -m64,$(KBUILD_AFLAGS)) 25 - KBUILD_AFLAGS_64 += -m64 -s 25 + KBUILD_AFLAGS_64 += -m64 26 26 27 27 KBUILD_CFLAGS_64 := $(filter-out -m64,$(KBUILD_CFLAGS)) 28 - KBUILD_CFLAGS_64 += -m64 -fPIC -shared -fno-common -fno-builtin 28 + KBUILD_CFLAGS_64 += -m64 -fPIC -fno-common -fno-builtin 29 29 ldflags-y := -fPIC -shared -soname=linux-vdso64.so.1 \ 30 30 --hash-style=both --build-id=sha1 -T 31 31
+1 -1
arch/s390/purgatory/Makefile
··· 24 24 KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes 25 25 KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare 26 26 KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding 27 - KBUILD_CFLAGS += -c -MD -Os -m64 -msoft-float -fno-common 27 + KBUILD_CFLAGS += -Os -m64 -msoft-float -fno-common 28 28 KBUILD_CFLAGS += -fno-stack-protector 29 29 KBUILD_CFLAGS += $(CLANG_FLAGS) 30 30 KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
-7
arch/sh/boot/compressed/Makefile
··· 8 8 OBJECTS := head_32.o misc.o cache.o piggy.o \ 9 9 ashiftrt.o ashldi3.o ashrsi3.o ashlsi3.o lshrsi3.o 10 10 11 - # These were previously generated files. When you are building the kernel 12 - # with O=, make sure to remove the stale files in the output tree. Otherwise, 13 - # the build system wrongly compiles the stale ones. 14 - ifdef building_out_of_srctree 15 - $(shell rm -f $(addprefix $(obj)/, ashiftrt.S ashldi3.c ashrsi3.S ashlsi3.S lshrsi3.S)) 16 - endif 17 - 18 11 targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \ 19 12 vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS) 20 13
+1 -1
arch/um/drivers/Makefile
··· 72 72 73 73 CFLAGS_xterm.o += '-DCONFIG_XTERM_CHAN_DEFAULT_EMULATOR="$(CONFIG_XTERM_CHAN_DEFAULT_EMULATOR)"' 74 74 75 - include arch/um/scripts/Makefile.rules 75 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/um/kernel/Makefile
··· 29 29 30 30 USER_OBJS := config.o 31 31 32 - include arch/um/scripts/Makefile.rules 32 + include $(srctree)/arch/um/scripts/Makefile.rules 33 33 34 34 targets := config.c config.tmp capflags.c 35 35
+1 -1
arch/um/kernel/skas/Makefile
··· 14 14 15 15 KCOV_INSTRUMENT := n 16 16 17 - include arch/um/scripts/Makefile.rules 17 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/um/os-Linux/Makefile
··· 18 18 main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ 19 19 tty.o umid.o util.o 20 20 21 - include arch/um/scripts/Makefile.rules 21 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/um/os-Linux/drivers/Makefile
··· 10 10 obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap.o 11 11 obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o 12 12 13 - include arch/um/scripts/Makefile.rules 13 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/um/os-Linux/skas/Makefile
··· 7 7 8 8 USER_OBJS := $(obj-y) 9 9 10 - include arch/um/scripts/Makefile.rules 10 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/x86/Makefile.um
··· 17 17 export LDS_EXTRA 18 18 19 19 # First of all, tune CFLAGS for the specific CPU. This actually sets cflags-y. 20 - include arch/x86/Makefile_32.cpu 20 + include $(srctree)/arch/x86/Makefile_32.cpu 21 21 22 22 # prevent gcc from keeping the stack 16 byte aligned. Taken from i386. 23 23 cflags-y += $(call cc-option,-mpreferred-stack-boundary=2)
+1 -1
arch/x86/boot/compressed/Makefile
··· 50 50 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 51 51 KBUILD_CFLAGS += -D__DISABLE_EXPORTS 52 52 # Disable relocation relaxation in case the link is not PIE. 53 - KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 53 + KBUILD_CFLAGS += $(call cc-option,-Wa$(comma)-mrelax-relocations=no) 54 54 KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h 55 55 56 56 # sev.c indirectly inludes inat-table.h which is generated during
+1 -1
arch/x86/tools/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 PHONY += posttest 3 3 4 - ifeq ($(KBUILD_VERBOSE),1) 4 + ifneq ($(findstring 1, $(KBUILD_VERBOSE)),) 5 5 posttest_verbose = -v 6 6 else 7 7 posttest_verbose =
+1 -1
arch/x86/um/Makefile
··· 48 48 UNPROFILE_OBJS := stub_segv.o 49 49 CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING) 50 50 51 - include arch/um/scripts/Makefile.rules 51 + include $(srctree)/arch/um/scripts/Makefile.rules
+1 -1
arch/x86/um/os-Linux/Makefile
··· 10 10 11 11 USER_OBJS := $(obj-y) 12 12 13 - include arch/um/scripts/Makefile.rules 13 + include $(srctree)/arch/um/scripts/Makefile.rules
+6 -3
certs/extract-cert.c
··· 78 78 static const char *key_pass; 79 79 static BIO *wb; 80 80 static char *cert_dst; 81 - static int kbuild_verbose; 81 + static bool verbose; 82 82 83 83 static void write_cert(X509 *x509) 84 84 { ··· 90 90 } 91 91 X509_NAME_oneline(X509_get_subject_name(x509), buf, sizeof(buf)); 92 92 ERR(!i2d_X509_bio(wb, x509), "%s", cert_dst); 93 - if (kbuild_verbose) 93 + if (verbose) 94 94 fprintf(stderr, "Extracted cert: %s\n", buf); 95 95 } 96 96 97 97 int main(int argc, char **argv) 98 98 { 99 99 char *cert_src; 100 + char *verbose_env; 100 101 101 102 OpenSSL_add_all_algorithms(); 102 103 ERR_load_crypto_strings(); 103 104 ERR_clear_error(); 104 105 105 - kbuild_verbose = atoi(getenv("KBUILD_VERBOSE")?:"0"); 106 + verbose_env = getenv("KBUILD_VERBOSE"); 107 + if (verbose_env && strchr(verbose_env, '1')) 108 + verbose = true; 106 109 107 110 key_pass = getenv("KBUILD_SIGN_PIN"); 108 111
+5
drivers/Makefile
··· 6 6 # Rewritten to use lists instead of if-statements. 7 7 # 8 8 9 + # Some driver Makefiles miss $(srctree)/ for include directive. 10 + ifdef building_out_of_srctree 11 + MAKEFLAGS += --include-dir=$(srctree) 12 + endif 13 + 9 14 obj-y += irqchip/ 10 15 obj-y += bus/ 11 16
+2 -1
drivers/gpu/drm/amd/display/dc/dml/Makefile
··· 26 26 # subcomponents. 27 27 28 28 ifdef CONFIG_X86 29 - dml_ccflags := -mhard-float -msse 29 + dml_ccflags-$(CONFIG_CC_IS_GCC) := -mhard-float 30 + dml_ccflags := $(dml_ccflags-y) -msse 30 31 endif 31 32 32 33 ifdef CONFIG_PPC64
+1 -1
fs/hostfs/Makefile
··· 8 8 obj-y := 9 9 obj-$(CONFIG_HOSTFS) += hostfs.o 10 10 11 - include arch/um/scripts/Makefile.rules 11 + include $(srctree)/arch/um/scripts/Makefile.rules
-4
init/Kconfig
··· 682 682 683 683 source "kernel/rcu/Kconfig" 684 684 685 - config BUILD_BIN2C 686 - bool 687 - default n 688 - 689 685 config IKCONFIG 690 686 tristate "Kernel .config support" 691 687 help
+1 -1
kernel/gen_kheaders.sh
··· 7 7 sfile="$(readlink -f "$0")" 8 8 outdir="$(pwd)" 9 9 tarfile=$1 10 - cpio_dir=$outdir/$tarfile.tmp 10 + cpio_dir=$outdir/${tarfile%/*}/.tmp_cpio_dir 11 11 12 12 dir_list=" 13 13 include/
-1
rust/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - target.json 4 3 bindings_generated.rs 5 4 bindings_helpers_generated.rs 6 5 exports_*_generated.h
+8 -19
rust/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - always-$(CONFIG_RUST) += target.json 4 - no-clean-files += target.json 5 - 6 3 obj-$(CONFIG_RUST) += core.o compiler_builtins.o 7 4 always-$(CONFIG_RUST) += exports_core_generated.h 8 5 ··· 229 232 $(call if_changed,rustc_test) 230 233 $(call if_changed,rustc_test_library) 231 234 232 - filechk_rust_target = $(objtree)/scripts/generate_rust_target < $< 233 - 234 - $(obj)/target.json: $(objtree)/include/config/auto.conf FORCE 235 - $(call filechk,rust_target) 236 - 237 235 ifdef CONFIG_CC_IS_CLANG 238 236 bindgen_c_flags = $(c_flags) 239 237 else ··· 324 332 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ 325 333 cmd_rustc_procmacro = \ 326 334 $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ 327 - --emit=dep-info,link --extern proc_macro \ 328 - --crate-type proc-macro --out-dir $(objtree)/$(obj) \ 329 - --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \ 330 - mv $(objtree)/$(obj)/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \ 331 - sed -i '/^\#/d' $(depfile) 335 + --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ 336 + --crate-type proc-macro \ 337 + --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< 332 338 333 339 # Procedural macros can only be used with the `rustc` that compiled it. 334 340 # Therefore, to get `libmacros.so` automatically recompiled when the compiler ··· 339 349 OBJTREE=$(abspath $(objtree)) \ 340 350 $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \ 341 351 $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \ 342 - --emit=dep-info,obj,metadata --crate-type rlib \ 343 - --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \ 344 - --crate-name $(patsubst %.o,%,$(notdir $@)) $<; \ 345 - mv $(objtree)/$(obj)/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \ 346 - sed -i '/^\#/d' $(depfile) \ 352 + --emit=dep-info=$(depfile) --emit=obj=$@ \ 353 + --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \ 354 + --crate-type rlib -L$(objtree)/$(obj) \ 355 + --crate-name $(patsubst %.o,%,$(notdir $@)) $< \ 347 356 $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) 348 357 349 358 rust-analyzer: ··· 366 377 $(obj)/core.o: private skip_flags = -Dunreachable_pub 367 378 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) 368 379 $(obj)/core.o: private rustc_target_flags = $(core-cfgs) 369 - $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs $(obj)/target.json FORCE 380 + $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE 370 381 $(call if_changed_dep,rustc_library) 371 382 372 383 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
+2 -1
scripts/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 /asn1_compiler 3 - /bin2c 4 3 /generate_rust_target 5 4 /insert-sys-cert 6 5 /kallsyms 6 + /list-gitignored 7 7 /module.lds 8 8 /recordmcount 9 9 /sign-file 10 10 /sorttable 11 + /target.json 11 12 /unifdef
+28 -22
scripts/Kbuild.include
··· 99 99 $(check-FORCE) 100 100 $(Q)set -e; \ 101 101 mkdir -p $(dir $@); \ 102 - trap "rm -f $(dot-target).tmp" EXIT; \ 103 - { $(filechk_$(1)); } > $(dot-target).tmp; \ 104 - if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \ 102 + trap "rm -f $(tmp-target)" EXIT; \ 103 + { $(filechk_$(1)); } > $(tmp-target); \ 104 + if [ ! -r $@ ] || ! cmp -s $@ $(tmp-target); then \ 105 105 $(kecho) ' UPD $@'; \ 106 - mv -f $(dot-target).tmp $@; \ 106 + mv -f $(tmp-target) $@; \ 107 107 fi 108 108 endef 109 109 ··· 125 125 # $(Q)$(MAKE) $(clean)=dir 126 126 clean := -f $(srctree)/scripts/Makefile.clean obj 127 127 128 - # echo command. 129 - # Short version is used, if $(quiet) equals `quiet_', otherwise full one. 130 - echo-cmd = $(if $($(quiet)cmd_$(1)),\ 131 - echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 132 - 133 - # sink stdout for 'make -s' 134 - redirect := 135 - quiet_redirect := 136 - silent_redirect := exec >/dev/null; 128 + # pring log 129 + # 130 + # If quiet is "silent_", print nothing and sink stdout 131 + # If quiet is "quiet_", print short log 132 + # If quiet is empty, print short log and whole command 133 + silent_log_print = exec >/dev/null; 134 + quiet_log_print = $(if $(quiet_cmd_$1), echo ' $(call escsq,$(quiet_cmd_$1)$(why))';) 135 + log_print = echo '$(pound) $(call escsq,$(or $(quiet_cmd_$1),cmd_$1 $@)$(why))'; \ 136 + echo ' $(call escsq,$(cmd_$1))'; 137 137 138 138 # Delete the target on interruption 139 139 # ··· 156 156 $(foreach sig, HUP INT QUIT TERM PIPE, \ 157 157 trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);)) 158 158 159 - # printing commands 160 - cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1)) 159 + # print and execute commands 160 + cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cmd_$(1)),:) 161 161 162 162 ### 163 163 # if_changed - execute command if any prerequisite is newer than ··· 170 170 ifneq ($(KBUILD_NOCMDDEP),1) 171 171 # Check if both commands are the same including their order. Result is empty 172 172 # string if equal. User may override this check using make KBUILD_NOCMDDEP=1 173 - cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 173 + # If the target does not exist, the *.cmd file should not be included so 174 + # $(savedcmd_$@) gets empty. Then, target will be built even if $(newer-prereqs) 175 + # happens to become empty. 176 + cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(savedcmd_$@))), \ 174 177 $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 175 178 else 176 - cmd-check = $(if $(strip $(cmd_$@)),,1) 179 + # We still need to detect missing targets. 180 + cmd-check = $(if $(strip $(savedcmd_$@)),,1) 177 181 endif 178 182 179 183 # Replace >$< with >$$< to preserve $ when reloading the .cmd file ··· 190 186 191 187 # Find any prerequisites that are newer than target or that do not exist. 192 188 # PHONY targets skipped in both cases. 189 + # If there is no prerequisite other than phony targets, $(newer-prereqs) becomes 190 + # empty even if the target does not exist. cmd-check saves this corner case. 193 191 newer-prereqs = $(filter-out $(PHONY),$?) 194 192 195 193 # It is a typical mistake to forget the FORCE prerequisite. Check it here so ··· 205 199 206 200 cmd_and_savecmd = \ 207 201 $(cmd); \ 208 - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd 202 + printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd 209 203 210 204 # Execute the command and also postprocess generated .d dependencies file. 211 205 if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) ··· 239 233 # (5) No dir/.target.cmd file (used to store command line) 240 234 # (6) No dir/.target.cmd file and target not listed in $(targets) 241 235 # This is a good hint that there is a bug in the kbuild file 242 - ifeq ($(KBUILD_VERBOSE),2) 243 - why = \ 236 + ifneq ($(findstring 2, $(KBUILD_VERBOSE)),) 237 + _why = \ 244 238 $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 245 239 $(if $(wildcard $@), \ 246 240 $(if $(newer-prereqs),- due to: $(newer-prereqs), \ 247 241 $(if $(cmd-check), \ 248 - $(if $(cmd_$@),- due to command line change, \ 242 + $(if $(savedcmd_$@),- due to command line change, \ 249 243 $(if $(filter $@, $(targets)), \ 250 244 - due to missing .cmd file, \ 251 245 - due to $(notdir $@) not in $$(targets) \ ··· 257 251 ) \ 258 252 ) 259 253 260 - echo-why = $(call escsq, $(strip $(why))) 254 + why = $(space)$(strip $(_why)) 261 255 endif 262 256 263 257 ###############################################################################
+1 -1
scripts/Kconfig.include
··· 33 33 34 34 # $(as-instr,<instr>) 35 35 # Return y if the assembler supports <instr>, n otherwise 36 - as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -) 36 + as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler-with-cpp -o /dev/null -) 37 37 38 38 # check if $(CC) and $(LD) exist 39 39 $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
+8 -3
scripts/Makefile
··· 3 3 # scripts contains sources for various helper programs used throughout 4 4 # the kernel for the build process. 5 5 6 - hostprogs-always-$(CONFIG_BUILD_BIN2C) += bin2c 7 6 hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms 8 7 hostprogs-always-$(BUILD_C_RECORDMCOUNT) += recordmcount 9 8 hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable 10 9 hostprogs-always-$(CONFIG_ASN1) += asn1_compiler 11 10 hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file 12 11 hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert 13 - hostprogs-always-$(CONFIG_RUST) += generate_rust_target 12 + always-$(CONFIG_RUST) += target.json 14 13 14 + filechk_rust_target = $< < include/config/auto.conf 15 + 16 + $(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE 17 + $(call filechk,rust_target) 18 + 19 + hostprogs += generate_rust_target 15 20 generate_rust_target-rust := y 16 21 17 22 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include ··· 38 33 endif 39 34 40 35 # The following programs are only built on demand 41 - hostprogs += unifdef 36 + hostprogs += list-gitignored unifdef 42 37 43 38 # The module linker script is preprocessed on demand 44 39 targets += module.lds
+8 -18
scripts/Makefile.build
··· 285 285 -Zcrate-attr=no_std \ 286 286 -Zcrate-attr='feature($(rust_allowed_features))' \ 287 287 --extern alloc --extern kernel \ 288 - --crate-type rlib --out-dir $(obj) -L $(objtree)/rust/ \ 289 - --crate-name $(basename $(notdir $@)) 290 - 291 - rust_handle_depfile = \ 292 - mv $(obj)/$(basename $(notdir $@)).d $(depfile); \ 293 - sed -i '/^\#/d' $(depfile) 288 + --crate-type rlib -L $(objtree)/rust/ \ 289 + --crate-name $(basename $(notdir $@)) \ 290 + --emit=dep-info=$(depfile) 294 291 295 292 # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit 296 293 # will be used. We explicitly request `-Ccodegen-units=1` in any case, and ··· 298 301 # would not match each other. 299 302 300 303 quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 301 - cmd_rustc_o_rs = \ 302 - $(rust_common_cmd) --emit=dep-info,obj $<; \ 303 - $(rust_handle_depfile) 304 + cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< 304 305 305 306 $(obj)/%.o: $(src)/%.rs FORCE 306 307 $(call if_changed_dep,rustc_o_rs) 307 308 308 309 quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 309 310 cmd_rustc_rsi_rs = \ 310 - $(rust_common_cmd) --emit=dep-info -Zunpretty=expanded $< >$@; \ 311 - command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@; \ 312 - $(rust_handle_depfile) 311 + $(rust_common_cmd) -Zunpretty=expanded $< >$@; \ 312 + command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@ 313 313 314 314 $(obj)/%.rsi: $(src)/%.rs FORCE 315 315 $(call if_changed_dep,rustc_rsi_rs) 316 316 317 317 quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 318 - cmd_rustc_s_rs = \ 319 - $(rust_common_cmd) --emit=dep-info,asm $<; \ 320 - $(rust_handle_depfile) 318 + cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $< 321 319 322 320 $(obj)/%.s: $(src)/%.rs FORCE 323 321 $(call if_changed_dep,rustc_s_rs) 324 322 325 323 quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 326 - cmd_rustc_ll_rs = \ 327 - $(rust_common_cmd) --emit=dep-info,llvm-ir $<; \ 328 - $(rust_handle_depfile) 324 + cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $< 329 325 330 326 $(obj)/%.ll: $(src)/%.rs FORCE 331 327 $(call if_changed_dep,rustc_ll_rs)
+2
scripts/Makefile.clang
··· 36 36 # so they can be implemented or wrapped in cc-option. 37 37 CLANG_FLAGS += -Werror=unknown-warning-option 38 38 CLANG_FLAGS += -Werror=ignored-optimization-argument 39 + CLANG_FLAGS += -Werror=option-ignored 40 + CLANG_FLAGS += -Werror=unused-command-line-argument 39 41 KBUILD_CFLAGS += $(CLANG_FLAGS) 40 42 KBUILD_AFLAGS += $(CLANG_FLAGS) 41 43 export CLANG_FLAGS
+4 -4
scripts/Makefile.compiler
··· 29 29 fi) 30 30 31 31 # as-option 32 - # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 32 + # Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 33 33 34 34 as-option = $(call try-run,\ 35 - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) 35 + $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2)) 36 36 37 37 # as-instr 38 - # Usage: cflags-y += $(call as-instr,instr,option1,option2) 38 + # Usage: aflags-y += $(call as-instr,instr,option1,option2) 39 39 40 40 as-instr = $(call try-run,\ 41 - printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 41 + printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3)) 42 42 43 43 # __cc-option 44 44 # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
+10 -14
scripts/Makefile.host
··· 80 80 ##### 81 81 # Handle options to gcc. Support building with separate output directory 82 82 83 - _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ 83 + hostc_flags = -Wp,-MMD,$(depfile) \ 84 + $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ 84 85 $(HOSTCFLAGS_$(target-stem).o) 85 - _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ 86 + hostcxx_flags = -Wp,-MMD,$(depfile) \ 87 + $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ 86 88 $(HOSTCXXFLAGS_$(target-stem).o) 87 - _hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ 88 - $(HOSTRUSTFLAGS_$(target-stem)) 89 + hostrust_flags = --emit=dep-info=$(depfile) \ 90 + $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ 91 + $(HOSTRUSTFLAGS_$(target-stem)) 89 92 90 93 # $(objtree)/$(obj) for including generated headers from checkin source files 91 94 ifeq ($(KBUILD_EXTMOD),) 92 95 ifdef building_out_of_srctree 93 - _hostc_flags += -I $(objtree)/$(obj) 94 - _hostcxx_flags += -I $(objtree)/$(obj) 96 + hostc_flags += -I $(objtree)/$(obj) 97 + hostcxx_flags += -I $(objtree)/$(obj) 95 98 endif 96 99 endif 97 - 98 - hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags) 99 - hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags) 100 - hostrust_flags = $(_hostrust_flags) 101 100 102 101 ##### 103 102 # Compile programs on the host ··· 148 149 # host-rust -> Executable 149 150 quiet_cmd_host-rust = HOSTRUSTC $@ 150 151 cmd_host-rust = \ 151 - $(HOSTRUSTC) $(hostrust_flags) --emit=dep-info,link \ 152 - --out-dir=$(obj)/ $<; \ 153 - mv $(obj)/$(target-stem).d $(depfile); \ 154 - sed -i '/^\#/d' $(depfile) 152 + $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $< 155 153 $(host-rust): $(obj)/%: $(src)/%.rs FORCE 156 154 $(call if_changed_dep,host-rust) 157 155
+15 -30
scripts/Makefile.lib
··· 368 368 DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) 369 369 370 370 # Generate an assembly file to wrap the output of the device tree compiler 371 - quiet_cmd_dt_S_dtb= DTBS $@ 372 - cmd_dt_S_dtb= \ 373 - { \ 374 - echo '\#include <asm-generic/vmlinux.lds.h>'; \ 375 - echo '.section .dtb.init.rodata,"a"'; \ 376 - echo '.balign STRUCT_ALIGNMENT'; \ 377 - echo '.global __dtb_$(subst -,_,$(*F))_begin'; \ 378 - echo '__dtb_$(subst -,_,$(*F))_begin:'; \ 379 - echo '.incbin "$<" '; \ 380 - echo '__dtb_$(subst -,_,$(*F))_end:'; \ 381 - echo '.global __dtb_$(subst -,_,$(*F))_end'; \ 382 - echo '.balign STRUCT_ALIGNMENT'; \ 383 - } > $@ 371 + quiet_cmd_wrap_S_dtb = WRAP $@ 372 + cmd_wrap_S_dtb = { \ 373 + symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \ 374 + echo '\#include <asm-generic/vmlinux.lds.h>'; \ 375 + echo '.section .dtb.init.rodata,"a"'; \ 376 + echo '.balign STRUCT_ALIGNMENT'; \ 377 + echo ".global $${symbase}_begin"; \ 378 + echo "$${symbase}_begin:"; \ 379 + echo '.incbin "$<" '; \ 380 + echo ".global $${symbase}_end"; \ 381 + echo "$${symbase}_end:"; \ 382 + echo '.balign STRUCT_ALIGNMENT'; \ 383 + } > $@ 384 384 385 385 $(obj)/%.dtb.S: $(obj)/%.dtb FORCE 386 - $(call if_changed,dt_S_dtb) 387 - 388 - # Generate an assembly file to wrap the output of the device tree compiler 389 - quiet_cmd_dt_S_dtbo= DTBOS $@ 390 - cmd_dt_S_dtbo= \ 391 - { \ 392 - echo '\#include <asm-generic/vmlinux.lds.h>'; \ 393 - echo '.section .dtb.init.rodata,"a"'; \ 394 - echo '.balign STRUCT_ALIGNMENT'; \ 395 - echo '.global __dtbo_$(subst -,_,$(*F))_begin'; \ 396 - echo '__dtbo_$(subst -,_,$(*F))_begin:'; \ 397 - echo '.incbin "$<" '; \ 398 - echo '__dtbo_$(subst -,_,$(*F))_end:'; \ 399 - echo '.global __dtbo_$(subst -,_,$(*F))_end'; \ 400 - echo '.balign STRUCT_ALIGNMENT'; \ 401 - } > $@ 386 + $(call if_changed,wrap_S_dtb) 402 387 403 388 $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE 404 - $(call if_changed,dt_S_dtbo) 389 + $(call if_changed,wrap_S_dtb) 405 390 406 391 quiet_cmd_dtc = DTC $@ 407 392 cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+1 -1
scripts/Makefile.modfinal
··· 54 54 # Same as if_changed, but allows to exclude specified extra dependencies 55 55 if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ 56 56 $(cmd); \ 57 - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 57 + printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 58 58 59 59 # Re-generate module BTFs if either module's .ko or vmlinux changed 60 60 %.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE
+3 -5
scripts/Makefile.modpost
··· 121 121 122 122 endif # ($(KBUILD_EXTMOD),) 123 123 124 - ifneq ($(missing-input),) 125 - modpost-args += -w 126 - endif 127 - 128 124 quiet_cmd_modpost = MODPOST $@ 129 125 cmd_modpost = \ 130 126 $(if $(missing-input), \ 131 127 echo >&2 "WARNING: $(missing-input) is missing."; \ 132 128 echo >&2 " Modules may not have dependencies or modversions."; \ 133 - echo >&2 " You may get many unresolved symbol warnings.";) \ 129 + echo >&2 " You may get many unresolved symbol errors."; \ 130 + echo >&2 " You can set KBUILD_MODPOST_WARN=1 to turn errors into warning"; \ 131 + echo >&2 " if you want to proceed at your own risk.";) \ 134 132 $(MODPOST) $(modpost-args) 135 133 136 134 targets += $(output-symdump)
+154 -87
scripts/Makefile.package
··· 3 3 4 4 include $(srctree)/scripts/Kbuild.include 5 5 6 - # RPM target 7 - # --------------------------------------------------------------------------- 8 - # The rpm target generates two rpm files: 9 - # /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm 10 - # /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm 11 - # The src.rpm files includes all source for the kernel being built 12 - # The <arch>.rpm includes kernel configuration, modules etc. 13 - # 14 - # Process to create the rpm files 15 - # a) clean the kernel 16 - # b) Generate .spec file 17 - # c) Build a tar ball, using symlink to make kernel version 18 - # first entry in the path 19 - # d) and pack the result to a tar.gz file 20 - # e) generate the rpm files, based on kernel.spec 21 - # - Use /. to avoid tar packing just the symlink 22 - 23 - # Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT, 24 - # but the binrpm-pkg target can; for some reason O= gets ignored. 25 - 26 - # Remove hyphens since they have special meaning in RPM filenames 27 6 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) 28 - KDEB_SOURCENAME ?= linux-upstream 29 7 KBUILD_PKG_ROOTCMD ?="fakeroot -u" 30 - export KDEB_SOURCENAME 31 8 # Include only those top-level files that are needed by make, plus the GPL copy 32 9 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ 33 10 include init io_uring ipc kernel lib mm net rust \ 34 11 samples scripts security sound tools usr virt \ 35 - .config .scmversion Makefile \ 12 + .config Makefile \ 36 13 Kbuild Kconfig COPYING $(wildcard localversion*) 37 14 MKSPEC := $(srctree)/scripts/package/mkspec 38 15 ··· 19 42 echo >&2; \ 20 43 echo >&2 " ERROR:"; \ 21 44 echo >&2 " Building source tarball is not possible outside the"; \ 22 - echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ 23 - echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \ 45 + echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \ 24 46 echo >&2; \ 25 47 false; \ 26 48 fi ; \ 27 - $(srctree)/scripts/setlocalversion --save-scmversion; \ 28 49 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ 29 - --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \ 30 - rm -f $(objtree)/.scmversion 50 + --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) 51 + 52 + # .tmp_filelist .tmp_filelist_exclude 53 + # --------------------------------------------------------------------------- 54 + 55 + scripts/list-gitignored: FORCE 56 + $(Q)$(MAKE) -f $(srctree)/Makefile scripts_package 57 + 58 + # 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore, 59 + # but it is definitely a generated file. 60 + filechk_filelist = \ 61 + $< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=- 62 + 63 + .tmp_filelist: scripts/list-gitignored FORCE 64 + $(call filechk,filelist) 65 + 66 + # tarball 67 + # --------------------------------------------------------------------------- 68 + 69 + quiet_cmd_tar = TAR $@ 70 + cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \ 71 + --owner=0 --group=0 --sort=name \ 72 + --transform 's:^\.:$*:S' -C $(tar-rootdir) . 73 + 74 + tar-rootdir := $(srctree) 75 + 76 + %.tar: 77 + $(call cmd,tar) 78 + 79 + %.tar.gz: private tar-compress-opt := -I $(KGZIP) 80 + %.tar.gz: 81 + $(call cmd,tar) 82 + 83 + %.tar.bz2: private tar-compress-opt := -I $(KBZIP2) 84 + %.tar.bz2: 85 + $(call cmd,tar) 86 + 87 + %.tar.xz: private tar-compress-opt := -I $(XZ) 88 + %.tar.xz: 89 + $(call cmd,tar) 90 + 91 + %.tar.zst: private tar-compress-opt := -I $(ZSTD) 92 + %.tar.zst: 93 + $(call cmd,tar) 94 + 95 + # Linux source tarball 96 + # --------------------------------------------------------------------------- 97 + 98 + linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude 99 + linux.tar.gz: .tmp_filelist 31 100 32 101 # rpm-pkg 33 102 # --------------------------------------------------------------------------- 34 103 PHONY += rpm-pkg 35 - rpm-pkg: 36 - $(MAKE) clean 37 - $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 38 - $(call cmd,src_tar,$(KERNELPATH),kernel.spec) 39 - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \ 104 + rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) 105 + rpm-pkg: srcrpm-pkg 106 + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ 40 107 --define='_smp_mflags %{nil}' 41 108 42 109 # srcrpm-pkg 43 110 # --------------------------------------------------------------------------- 44 111 PHONY += srcrpm-pkg 45 - srcrpm-pkg: 46 - $(MAKE) clean 112 + srcrpm-pkg: linux.tar.gz 47 113 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 48 - $(call cmd,src_tar,$(KERNELPATH),kernel.spec) 49 - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ts $(KERNELPATH).tar.gz \ 50 - --define='_smp_mflags %{nil}' --define='_srcrpmdir $(srctree)' 114 + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ 115 + --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .' 51 116 52 117 # binrpm-pkg 53 118 # --------------------------------------------------------------------------- ··· 100 81 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ 101 82 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec 102 83 84 + quiet_cmd_debianize = GEN $@ 85 + cmd_debianize = $(srctree)/scripts/package/mkdebian 86 + 87 + debian: FORCE 88 + $(call cmd,debianize) 89 + 90 + PHONY += debian-orig 91 + debian-orig: private source = $(shell dpkg-parsechangelog -S Source) 92 + debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') 93 + debian-orig: private orig-name = $(source)_$(version).orig.tar.gz 94 + debian-orig: linux.tar.gz debian 95 + $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \ 96 + ln -f $< ../$(orig-name); \ 97 + else \ 98 + cp $< ../$(orig-name); \ 99 + fi 100 + 103 101 PHONY += deb-pkg 104 - deb-pkg: 105 - $(MAKE) clean 106 - $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian 107 - $(call cmd,src_tar,$(KDEB_SOURCENAME)) 108 - origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\ 109 - mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz 110 - +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc 102 + deb-pkg: debian-orig 103 + +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ 104 + --build=source,binary -nc -us -uc 111 105 112 106 PHONY += bindeb-pkg 113 - bindeb-pkg: 114 - $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian 107 + bindeb-pkg: debian 115 108 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc 116 109 117 110 PHONY += intdeb-pkg ··· 145 114 cd $(objtree)/snap && \ 146 115 snapcraft --target-arch=$(UTS_MACHINE) 147 116 148 - # tarball targets 149 - # --------------------------------------------------------------------------- 150 - tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg 151 - PHONY += $(tar-pkgs) 152 - $(tar-pkgs): 153 - $(MAKE) -f $(srctree)/Makefile 154 - +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ 155 - 156 - # perf-pkg - generate a source tarball with perf source 117 + # dir-pkg tar*-pkg - tarball targets 157 118 # --------------------------------------------------------------------------- 158 119 159 - perf-tar=perf-$(KERNELVERSION) 120 + tar-pkg-tarball = linux-$(KERNELRELEASE)-$(ARCH).$(1) 121 + tar-pkg-phony = $(subst .,,$(1))-pkg 160 122 161 - quiet_cmd_perf_tar = TAR 162 - cmd_perf_tar = \ 163 - git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \ 164 - HEAD^{tree} $$(cd $(srctree); \ 165 - echo $$(cat tools/perf/MANIFEST)) \ 166 - -o $(perf-tar).tar; \ 167 - mkdir -p $(perf-tar); \ 168 - git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \ 169 - (cd $(srctree)/tools/perf; \ 170 - util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \ 171 - tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \ 172 - rm -r $(perf-tar); \ 173 - $(if $(findstring tar-src,$@),, \ 174 - $(if $(findstring bz2,$@),$(KBZIP2), \ 175 - $(if $(findstring gz,$@),$(KGZIP), \ 176 - $(if $(findstring xz,$@),$(XZ), \ 177 - $(if $(findstring zst,$@),$(ZSTD), \ 178 - $(error unknown target $@))))) \ 179 - -f -9 $(perf-tar).tar) 123 + tar-install: FORCE 124 + $(Q)$(MAKE) -f $(srctree)/Makefile 125 + +$(Q)$(srctree)/scripts/package/buildtar $@ 180 126 181 - perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \ 182 - perf-tarxz-src-pkg perf-tarzst-src-pkg 183 - PHONY += $(perf-tar-pkgs) 184 - $(perf-tar-pkgs): 185 - $(call cmd,perf_tar) 127 + PHONY += dir-pkg 128 + dir-pkg: tar-install 129 + @echo "Kernel tree successfully created in $<" 130 + 131 + define tar-pkg-rule 132 + PHONY += $(tar-pkg-phony) 133 + $(tar-pkg-phony): $(tar-pkg-tarball) 134 + @: 135 + 136 + $(tar-pkg-tarball): private tar-rootdir := tar-install 137 + $(tar-pkg-tarball): tar-install 138 + endef 139 + 140 + $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call tar-pkg-rule,$(x)))) 141 + 142 + # perf-tar*-src-pkg - generate a source tarball with perf source 143 + # --------------------------------------------------------------------------- 144 + 145 + perf-tar-src-pkg-tarball = perf-$(KERNELVERSION).$(1) 146 + perf-tar-src-pkg-phony = perf-$(subst .,,$(1))-src-pkg 147 + 148 + quiet_cmd_stage_perf_src = STAGE $@ 149 + cmd_stage_perf_src = \ 150 + rm -rf $@; \ 151 + mkdir -p $@; \ 152 + tar -c -f - --exclude-from=$<_exclude -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | \ 153 + tar -x -f - -C $@ 154 + 155 + .tmp_perf: .tmp_filelist 156 + $(call cmd,stage_perf_src) 157 + 158 + filechk_perf_head = \ 159 + if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \ 160 + head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \ 161 + echo $$head; \ 162 + else \ 163 + echo "not a git tree"; \ 164 + fi 165 + 166 + .tmp_perf/HEAD: .tmp_perf FORCE 167 + $(call filechk,perf_head) 168 + 169 + quiet_cmd_perf_version_file = GEN $@ 170 + cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@)) 171 + 172 + # PERF-VERSION-FILE and HEAD are independent, but this avoids updating the 173 + # timestamp of PERF-VERSION-FILE. 174 + # The best is to fix tools/perf/util/PERF-VERSION-GEN. 175 + .tmp_perf/PERF-VERSION-FILE: .tmp_perf/HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN 176 + $(call cmd,perf_version_file) 177 + 178 + define perf-tar-src-pkg-rule 179 + PHONY += $(perf-tar-src-pkg-phony) 180 + $(perf-tar-src-pkg-phony): $(perf-tar-src-pkg-tarball) 181 + @: 182 + 183 + $(perf-tar-src-pkg-tarball): private tar-rootdir := .tmp_perf 184 + $(perf-tar-src-pkg-tarball): .tmp_filelist .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE 185 + endef 186 + 187 + $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-tar-src-pkg-rule,$(x)))) 186 188 187 189 # Help text displayed when executing 'make help' 188 190 # --------------------------------------------------------------------------- ··· 234 170 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 235 171 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' 236 172 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' 237 - @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' 238 - @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' 239 - @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' 240 - @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' 241 - @echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball' 173 + @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' 174 + @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' 175 + @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' 176 + @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression' 177 + @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression' 178 + 179 + PHONY += FORCE 180 + FORCE: 242 181 243 182 .PHONY: $(PHONY)
+1 -1
scripts/as-version.sh
··· 45 45 # Get the first line of the --version output. 46 46 IFS=' 47 47 ' 48 - set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null) 48 + set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler-with-cpp /dev/null -o /dev/null 2>/dev/null) 49 49 50 50 # Split the line on spaces. 51 51 IFS=' '
+2 -2
scripts/asn1_compiler.c
··· 567 567 int fd; 568 568 569 569 kbuild_verbose = getenv("KBUILD_VERBOSE"); 570 - if (kbuild_verbose) 571 - verbose_opt = atoi(kbuild_verbose); 570 + if (kbuild_verbose && strchr(kbuild_verbose, '1')) 571 + verbose_opt = true; 572 572 573 573 while (argc > 4) { 574 574 if (strcmp(argv[1], "-v") == 0)
+162 -80
scripts/basic/fixdep.c
··· 70 70 * 71 71 * It first generates a line 72 72 * 73 - * cmd_<target> = <cmdline> 73 + * savedcmd_<target> = <cmdline> 74 74 * 75 75 * and then basically copies the .<target>.d file to stdout, in the 76 76 * process filtering out the dependency on autoconf.h and adding ··· 94 94 #include <unistd.h> 95 95 #include <fcntl.h> 96 96 #include <string.h> 97 + #include <stdbool.h> 97 98 #include <stdlib.h> 98 99 #include <stdio.h> 99 100 #include <ctype.h> ··· 113 112 }; 114 113 115 114 #define HASHSZ 256 116 - static struct item *hashtab[HASHSZ]; 115 + static struct item *config_hashtab[HASHSZ], *file_hashtab[HASHSZ]; 117 116 118 117 static unsigned int strhash(const char *str, unsigned int sz) 119 118 { ··· 126 125 } 127 126 128 127 /* 129 - * Lookup a value in the configuration string. 130 - */ 131 - static int is_defined_config(const char *name, int len, unsigned int hash) 132 - { 133 - struct item *aux; 134 - 135 - for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { 136 - if (aux->hash == hash && aux->len == len && 137 - memcmp(aux->name, name, len) == 0) 138 - return 1; 139 - } 140 - return 0; 141 - } 142 - 143 - /* 144 128 * Add a new value to the configuration string. 145 129 */ 146 - static void define_config(const char *name, int len, unsigned int hash) 130 + static void add_to_hashtable(const char *name, int len, unsigned int hash, 131 + struct item *hashtab[]) 147 132 { 148 133 struct item *aux = malloc(sizeof(*aux) + len); 149 134 ··· 145 158 } 146 159 147 160 /* 161 + * Lookup a string in the hash table. If found, just return true. 162 + * If not, add it to the hashtable and return false. 163 + */ 164 + static bool in_hashtable(const char *name, int len, struct item *hashtab[]) 165 + { 166 + struct item *aux; 167 + unsigned int hash = strhash(name, len); 168 + 169 + for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { 170 + if (aux->hash == hash && aux->len == len && 171 + memcmp(aux->name, name, len) == 0) 172 + return true; 173 + } 174 + 175 + add_to_hashtable(name, len, hash, hashtab); 176 + 177 + return false; 178 + } 179 + 180 + /* 148 181 * Record the use of a CONFIG_* word. 149 182 */ 150 183 static void use_config(const char *m, int slen) 151 184 { 152 - unsigned int hash = strhash(m, slen); 185 + if (in_hashtable(m, slen, config_hashtab)) 186 + return; 153 187 154 - if (is_defined_config(m, slen, hash)) 155 - return; 156 - 157 - define_config(m, slen, hash); 158 188 /* Print out a dependency path from a symbol name. */ 159 189 printf(" $(wildcard include/config/%.*s) \\\n", slen, m); 160 190 } ··· 250 246 str_ends_with(s, len, "include/generated/autoksyms.h"); 251 247 } 252 248 249 + /* Do not parse these files */ 250 + static int is_no_parse_file(const char *s, int len) 251 + { 252 + /* rustc may list binary files in dep-info */ 253 + return str_ends_with(s, len, ".rlib") || 254 + str_ends_with(s, len, ".rmeta") || 255 + str_ends_with(s, len, ".so"); 256 + } 257 + 253 258 /* 254 259 * Important: The below generated source_foo.o and deps_foo.o variable 255 260 * assignments are parsed not only by make, but also by the rather simple 256 261 * parser in scripts/mod/sumversion.c. 257 262 */ 258 - static void parse_dep_file(char *m, const char *target) 263 + static void parse_dep_file(char *p, const char *target) 259 264 { 260 - char *p; 261 - int is_last, is_target; 262 - int saw_any_target = 0; 263 - int is_first_dep = 0; 264 - void *buf; 265 + bool saw_any_target = false; 266 + bool is_target = true; 267 + bool is_source = false; 268 + bool need_parse; 269 + char *q, saved_c; 265 270 266 - while (1) { 267 - /* Skip any "white space" */ 268 - while (*m == ' ' || *m == '\\' || *m == '\n') 269 - m++; 270 - 271 - if (!*m) 272 - break; 273 - 274 - /* Find next "white space" */ 275 - p = m; 276 - while (*p && *p != ' ' && *p != '\\' && *p != '\n') 277 - p++; 278 - is_last = (*p == '\0'); 279 - /* Is the token we found a target name? */ 280 - is_target = (*(p-1) == ':'); 281 - /* Don't write any target names into the dependency file */ 282 - if (is_target) { 283 - /* The /next/ file is the first dependency */ 284 - is_first_dep = 1; 285 - } else if (!is_ignored_file(m, p - m)) { 286 - *p = '\0'; 287 - 271 + while (*p) { 272 + /* handle some special characters first. */ 273 + switch (*p) { 274 + case '#': 288 275 /* 289 - * Do not list the source file as dependency, so that 290 - * kbuild is not confused if a .c file is rewritten 291 - * into .S or vice versa. Storing it in source_* is 292 - * needed for modpost to compute srcversions. 276 + * skip comments. 277 + * rustc may emit comments to dep-info. 293 278 */ 294 - if (is_first_dep) { 279 + p++; 280 + while (*p != '\0' && *p != '\n') { 295 281 /* 296 - * If processing the concatenation of multiple 297 - * dependency files, only process the first 298 - * target name, which will be the original 299 - * source name, and ignore any other target 300 - * names, which will be intermediate temporary 301 - * files. 282 + * escaped newlines continue the comment across 283 + * multiple lines. 302 284 */ 303 - if (!saw_any_target) { 304 - saw_any_target = 1; 305 - printf("source_%s := %s\n\n", 306 - target, m); 307 - printf("deps_%s := \\\n", target); 285 + if (*p == '\\') 286 + p++; 287 + p++; 288 + } 289 + continue; 290 + case ' ': 291 + case '\t': 292 + /* skip whitespaces */ 293 + p++; 294 + continue; 295 + case '\\': 296 + /* 297 + * backslash/newline combinations continue the 298 + * statement. Skip it just like a whitespace. 299 + */ 300 + if (*(p + 1) == '\n') { 301 + p += 2; 302 + continue; 303 + } 304 + break; 305 + case '\n': 306 + /* 307 + * Makefiles use a line-based syntax, where the newline 308 + * is the end of a statement. After seeing a newline, 309 + * we expect the next token is a target. 310 + */ 311 + p++; 312 + is_target = true; 313 + continue; 314 + case ':': 315 + /* 316 + * assume the first dependency after a colon as the 317 + * source file. 318 + */ 319 + p++; 320 + is_target = false; 321 + is_source = true; 322 + continue; 323 + } 324 + 325 + /* find the end of the token */ 326 + q = p; 327 + while (*q != ' ' && *q != '\t' && *q != '\n' && *q != '#' && *q != ':') { 328 + if (*q == '\\') { 329 + /* 330 + * backslash/newline combinations work like as 331 + * a whitespace, so this is the end of token. 332 + */ 333 + if (*(q + 1) == '\n') 334 + break; 335 + 336 + /* escaped special characters */ 337 + if (*(q + 1) == '#' || *(q + 1) == ':') { 338 + memmove(p + 1, p, q - p); 339 + p++; 308 340 } 309 - is_first_dep = 0; 310 - } else { 311 - printf(" %s \\\n", m); 341 + 342 + q++; 312 343 } 313 344 314 - buf = read_file(m); 345 + if (*q == '\0') 346 + break; 347 + q++; 348 + } 349 + 350 + /* Just discard the target */ 351 + if (is_target) { 352 + p = q; 353 + continue; 354 + } 355 + 356 + saved_c = *q; 357 + *q = '\0'; 358 + need_parse = false; 359 + 360 + /* 361 + * Do not list the source file as dependency, so that kbuild is 362 + * not confused if a .c file is rewritten into .S or vice versa. 363 + * Storing it in source_* is needed for modpost to compute 364 + * srcversions. 365 + */ 366 + if (is_source) { 367 + /* 368 + * The DT build rule concatenates multiple dep files. 369 + * When processing them, only process the first source 370 + * name, which will be the original one, and ignore any 371 + * other source names, which will be intermediate 372 + * temporary files. 373 + * 374 + * rustc emits the same dependency list for each 375 + * emission type. It is enough to list the source name 376 + * just once. 377 + */ 378 + if (!saw_any_target) { 379 + saw_any_target = true; 380 + printf("source_%s := %s\n\n", target, p); 381 + printf("deps_%s := \\\n", target); 382 + need_parse = true; 383 + } 384 + } else if (!is_ignored_file(p, q - p) && 385 + !in_hashtable(p, q - p, file_hashtab)) { 386 + printf(" %s \\\n", p); 387 + need_parse = true; 388 + } 389 + 390 + if (need_parse && !is_no_parse_file(p, q - p)) { 391 + void *buf; 392 + 393 + buf = read_file(p); 315 394 parse_config_file(buf); 316 395 free(buf); 317 396 } 318 397 319 - if (is_last) 320 - break; 321 - 322 - /* 323 - * Start searching for next token immediately after the first 324 - * "whitespace" character that follows this token. 325 - */ 326 - m = p + 1; 398 + is_source = false; 399 + *q = saved_c; 400 + p = q; 327 401 } 328 402 329 403 if (!saw_any_target) { ··· 425 343 target = argv[2]; 426 344 cmdline = argv[3]; 427 345 428 - printf("cmd_%s := %s\n\n", target, cmdline); 346 + printf("savedcmd_%s := %s\n\n", target, cmdline); 429 347 430 348 buf = read_file(depfile); 431 349 parse_dep_file(buf, target);
-36
scripts/bin2c.c
··· 1 - /* 2 - * Unloved program to convert a binary on stdin to a C include on stdout 3 - * 4 - * Jan 1999 Matt Mackall <mpm@selenic.com> 5 - * 6 - * This software may be used and distributed according to the terms 7 - * of the GNU General Public License, incorporated herein by reference. 8 - */ 9 - 10 - #include <stdio.h> 11 - 12 - int main(int argc, char *argv[]) 13 - { 14 - int ch, total = 0; 15 - 16 - if (argc > 1) 17 - printf("const char %s[] %s=\n", 18 - argv[1], argc > 2 ? argv[2] : ""); 19 - 20 - do { 21 - printf("\t\""); 22 - while ((ch = getchar()) != EOF) { 23 - total++; 24 - printf("\\x%02x", ch); 25 - if (total % 16 == 0) 26 - break; 27 - } 28 - printf("\"\n"); 29 - } while (ch != EOF); 30 - 31 - if (argc > 1) 32 - printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n", 33 - argv[1], total); 34 - 35 - return 0; 36 - }
+12 -1
scripts/checkkconfigsymbols.py
··· 115 115 return args 116 116 117 117 118 - def main(): 118 + def print_undefined_symbols(): 119 119 """Main function of this module.""" 120 120 args = parse_options() 121 121 ··· 465 465 references.append(symbol) 466 466 467 467 return defined, references 468 + 469 + 470 + def main(): 471 + try: 472 + print_undefined_symbols() 473 + except BrokenPipeError: 474 + # Python flushes standard streams on exit; redirect remaining output 475 + # to devnull to avoid another BrokenPipeError at shutdown 476 + devnull = os.open(os.devnull, os.O_WRONLY) 477 + os.dup2(devnull, sys.stdout.fileno()) 478 + sys.exit(1) # Python exits with error code 1 on EPIPE 468 479 469 480 470 481 if __name__ == "__main__":
+1 -1
scripts/clang-tools/gen_compile_commands.py
··· 19 19 _DEFAULT_LOG_LEVEL = 'WARNING' 20 20 21 21 _FILENAME_PATTERN = r'^\..*\.cmd$' 22 - _LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)' 22 + _LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)' 23 23 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] 24 24 # The tools/ directory adopts a different build system, and produces .cmd 25 25 # files in a different format. Do not support it.
+14 -7
scripts/clang-tools/run-clang-tools.py
··· 61 61 62 62 63 63 def main(): 64 - args = parse_arguments() 64 + try: 65 + args = parse_arguments() 65 66 66 - lock = multiprocessing.Lock() 67 - pool = multiprocessing.Pool(initializer=init, initargs=(lock, args)) 68 - # Read JSON data into the datastore variable 69 - with open(args.path, "r") as f: 70 - datastore = json.load(f) 71 - pool.map(run_analysis, datastore) 67 + lock = multiprocessing.Lock() 68 + pool = multiprocessing.Pool(initializer=init, initargs=(lock, args)) 69 + # Read JSON data into the datastore variable 70 + with open(args.path, "r") as f: 71 + datastore = json.load(f) 72 + pool.map(run_analysis, datastore) 73 + except BrokenPipeError: 74 + # Python flushes standard streams on exit; redirect remaining output 75 + # to devnull to avoid another BrokenPipeError at shutdown 76 + devnull = os.open(os.devnull, os.O_WRONLY) 77 + os.dup2(devnull, sys.stdout.fileno()) 78 + sys.exit(1) # Python exits with error code 1 on EPIPE 72 79 73 80 74 81 if __name__ == "__main__":
+14 -2
scripts/diffconfig
··· 65 65 else: 66 66 print(" %s %s -> %s" % (config, value, new_value)) 67 67 68 - def main(): 68 + def show_diff(): 69 69 global merge_style 70 70 71 71 # parse command line args ··· 129 129 for config in new: 130 130 print_config("+", config, None, b[config]) 131 131 132 - main() 132 + def main(): 133 + try: 134 + show_diff() 135 + except BrokenPipeError: 136 + # Python flushes standard streams on exit; redirect remaining output 137 + # to devnull to avoid another BrokenPipeError at shutdown 138 + devnull = os.open(os.devnull, os.O_WRONLY) 139 + os.dup2(devnull, sys.stdout.fileno()) 140 + sys.exit(1) # Python exits with error code 1 on EPIPE 141 + 142 + 143 + if __name__ == '__main__': 144 + main()
+2 -2
scripts/kernel-doc
··· 175 175 my ($type, $declaration_name, $return_type); 176 176 my ($newsection, $newcontents, $prototype, $brcount, %source_map); 177 177 178 - if (defined($ENV{'KBUILD_VERBOSE'})) { 179 - $verbose = "$ENV{'KBUILD_VERBOSE'}"; 178 + if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { 179 + $verbose = 1; 180 180 } 181 181 182 182 if (defined($ENV{'KCFLAGS'})) {
+1057
scripts/list-gitignored.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // 3 + // Traverse the source tree, parsing all .gitignore files, and print file paths 4 + // that are ignored by git. 5 + // The output is suitable to the --exclude-from option of tar. 6 + // This is useful until the --exclude-vcs-ignores option gets working correctly. 7 + // 8 + // Copyright (C) 2023 Masahiro Yamada <masahiroy@kernel.org> 9 + // (a lot of code imported from GIT) 10 + 11 + #include <assert.h> 12 + #include <dirent.h> 13 + #include <errno.h> 14 + #include <fcntl.h> 15 + #include <getopt.h> 16 + #include <stdarg.h> 17 + #include <stdbool.h> 18 + #include <stdio.h> 19 + #include <stdlib.h> 20 + #include <string.h> 21 + #include <sys/stat.h> 22 + #include <sys/types.h> 23 + #include <unistd.h> 24 + 25 + // Imported from commit 23c56f7bd5f1667f8b793d796bf30e39545920f6 in GIT 26 + // 27 + //---------------------------(IMPORT FROM GIT BEGIN)--------------------------- 28 + 29 + // Copied from environment.c 30 + 31 + static bool ignore_case; 32 + 33 + // Copied from git-compat-util.h 34 + 35 + /* Sane ctype - no locale, and works with signed chars */ 36 + #undef isascii 37 + #undef isspace 38 + #undef isdigit 39 + #undef isalpha 40 + #undef isalnum 41 + #undef isprint 42 + #undef islower 43 + #undef isupper 44 + #undef tolower 45 + #undef toupper 46 + #undef iscntrl 47 + #undef ispunct 48 + #undef isxdigit 49 + 50 + static const unsigned char sane_ctype[256]; 51 + #define GIT_SPACE 0x01 52 + #define GIT_DIGIT 0x02 53 + #define GIT_ALPHA 0x04 54 + #define GIT_GLOB_SPECIAL 0x08 55 + #define GIT_REGEX_SPECIAL 0x10 56 + #define GIT_PATHSPEC_MAGIC 0x20 57 + #define GIT_CNTRL 0x40 58 + #define GIT_PUNCT 0x80 59 + #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) 60 + #define isascii(x) (((x) & ~0x7f) == 0) 61 + #define isspace(x) sane_istest(x,GIT_SPACE) 62 + #define isdigit(x) sane_istest(x,GIT_DIGIT) 63 + #define isalpha(x) sane_istest(x,GIT_ALPHA) 64 + #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) 65 + #define isprint(x) ((x) >= 0x20 && (x) <= 0x7e) 66 + #define islower(x) sane_iscase(x, 1) 67 + #define isupper(x) sane_iscase(x, 0) 68 + #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) 69 + #define iscntrl(x) (sane_istest(x,GIT_CNTRL)) 70 + #define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \ 71 + GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC) 72 + #define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1) 73 + #define tolower(x) sane_case((unsigned char)(x), 0x20) 74 + #define toupper(x) sane_case((unsigned char)(x), 0) 75 + 76 + static inline int sane_case(int x, int high) 77 + { 78 + if (sane_istest(x, GIT_ALPHA)) 79 + x = (x & ~0x20) | high; 80 + return x; 81 + } 82 + 83 + static inline int sane_iscase(int x, int is_lower) 84 + { 85 + if (!sane_istest(x, GIT_ALPHA)) 86 + return 0; 87 + 88 + if (is_lower) 89 + return (x & 0x20) != 0; 90 + else 91 + return (x & 0x20) == 0; 92 + } 93 + 94 + // Copied from ctype.c 95 + 96 + enum { 97 + S = GIT_SPACE, 98 + A = GIT_ALPHA, 99 + D = GIT_DIGIT, 100 + G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */ 101 + R = GIT_REGEX_SPECIAL, /* $, (, ), +, ., ^, {, | */ 102 + P = GIT_PATHSPEC_MAGIC, /* other non-alnum, except for ] and } */ 103 + X = GIT_CNTRL, 104 + U = GIT_PUNCT, 105 + Z = GIT_CNTRL | GIT_SPACE 106 + }; 107 + 108 + static const unsigned char sane_ctype[256] = { 109 + X, X, X, X, X, X, X, X, X, Z, Z, X, X, Z, X, X, /* 0.. 15 */ 110 + X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 16.. 31 */ 111 + S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P, /* 32.. 47 */ 112 + D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G, /* 48.. 63 */ 113 + P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 64.. 79 */ 114 + A, A, A, A, A, A, A, A, A, A, A, G, G, U, R, P, /* 80.. 95 */ 115 + P, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, /* 96..111 */ 116 + A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */ 117 + /* Nothing in the 128.. range */ 118 + }; 119 + 120 + // Copied from hex.c 121 + 122 + static const signed char hexval_table[256] = { 123 + -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ 124 + -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */ 125 + -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */ 126 + -1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */ 127 + -1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */ 128 + -1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */ 129 + 0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */ 130 + 8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */ 131 + -1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */ 132 + -1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */ 133 + -1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */ 134 + -1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */ 135 + -1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */ 136 + -1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */ 137 + -1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */ 138 + -1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */ 139 + -1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */ 140 + -1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */ 141 + -1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */ 142 + -1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */ 143 + -1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */ 144 + -1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */ 145 + -1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */ 146 + -1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */ 147 + -1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */ 148 + -1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */ 149 + -1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */ 150 + -1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */ 151 + -1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */ 152 + -1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */ 153 + -1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */ 154 + -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */ 155 + }; 156 + 157 + // Copied from wildmatch.h 158 + 159 + #define WM_CASEFOLD 1 160 + #define WM_PATHNAME 2 161 + 162 + #define WM_NOMATCH 1 163 + #define WM_MATCH 0 164 + #define WM_ABORT_ALL -1 165 + #define WM_ABORT_TO_STARSTAR -2 166 + 167 + // Copied from wildmatch.c 168 + 169 + typedef unsigned char uchar; 170 + 171 + // local modification: remove NEGATE_CLASS(2) 172 + 173 + #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \ 174 + && *(class) == *(litmatch) \ 175 + && strncmp((char*)class, litmatch, len) == 0) 176 + 177 + // local modification: simpilify macros 178 + #define ISBLANK(c) ((c) == ' ' || (c) == '\t') 179 + #define ISGRAPH(c) (isprint(c) && !isspace(c)) 180 + #define ISPRINT(c) isprint(c) 181 + #define ISDIGIT(c) isdigit(c) 182 + #define ISALNUM(c) isalnum(c) 183 + #define ISALPHA(c) isalpha(c) 184 + #define ISCNTRL(c) iscntrl(c) 185 + #define ISLOWER(c) islower(c) 186 + #define ISPUNCT(c) ispunct(c) 187 + #define ISSPACE(c) isspace(c) 188 + #define ISUPPER(c) isupper(c) 189 + #define ISXDIGIT(c) isxdigit(c) 190 + 191 + /* Match pattern "p" against "text" */ 192 + static int dowild(const uchar *p, const uchar *text, unsigned int flags) 193 + { 194 + uchar p_ch; 195 + const uchar *pattern = p; 196 + 197 + for ( ; (p_ch = *p) != '\0'; text++, p++) { 198 + int matched, match_slash, negated; 199 + uchar t_ch, prev_ch; 200 + if ((t_ch = *text) == '\0' && p_ch != '*') 201 + return WM_ABORT_ALL; 202 + if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) 203 + t_ch = tolower(t_ch); 204 + if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) 205 + p_ch = tolower(p_ch); 206 + switch (p_ch) { 207 + case '\\': 208 + /* Literal match with following character. Note that the test 209 + * in "default" handles the p[1] == '\0' failure case. */ 210 + p_ch = *++p; 211 + /* FALLTHROUGH */ 212 + default: 213 + if (t_ch != p_ch) 214 + return WM_NOMATCH; 215 + continue; 216 + case '?': 217 + /* Match anything but '/'. */ 218 + if ((flags & WM_PATHNAME) && t_ch == '/') 219 + return WM_NOMATCH; 220 + continue; 221 + case '*': 222 + if (*++p == '*') { 223 + const uchar *prev_p = p - 2; 224 + while (*++p == '*') {} 225 + if (!(flags & WM_PATHNAME)) 226 + /* without WM_PATHNAME, '*' == '**' */ 227 + match_slash = 1; 228 + else if ((prev_p < pattern || *prev_p == '/') && 229 + (*p == '\0' || *p == '/' || 230 + (p[0] == '\\' && p[1] == '/'))) { 231 + /* 232 + * Assuming we already match 'foo/' and are at 233 + * <star star slash>, just assume it matches 234 + * nothing and go ahead match the rest of the 235 + * pattern with the remaining string. This 236 + * helps make foo/<*><*>/bar (<> because 237 + * otherwise it breaks C comment syntax) match 238 + * both foo/bar and foo/a/bar. 239 + */ 240 + if (p[0] == '/' && 241 + dowild(p + 1, text, flags) == WM_MATCH) 242 + return WM_MATCH; 243 + match_slash = 1; 244 + } else /* WM_PATHNAME is set */ 245 + match_slash = 0; 246 + } else 247 + /* without WM_PATHNAME, '*' == '**' */ 248 + match_slash = flags & WM_PATHNAME ? 0 : 1; 249 + if (*p == '\0') { 250 + /* Trailing "**" matches everything. Trailing "*" matches 251 + * only if there are no more slash characters. */ 252 + if (!match_slash) { 253 + if (strchr((char *)text, '/')) 254 + return WM_NOMATCH; 255 + } 256 + return WM_MATCH; 257 + } else if (!match_slash && *p == '/') { 258 + /* 259 + * _one_ asterisk followed by a slash 260 + * with WM_PATHNAME matches the next 261 + * directory 262 + */ 263 + const char *slash = strchr((char*)text, '/'); 264 + if (!slash) 265 + return WM_NOMATCH; 266 + text = (const uchar*)slash; 267 + /* the slash is consumed by the top-level for loop */ 268 + break; 269 + } 270 + while (1) { 271 + if (t_ch == '\0') 272 + break; 273 + /* 274 + * Try to advance faster when an asterisk is 275 + * followed by a literal. We know in this case 276 + * that the string before the literal 277 + * must belong to "*". 278 + * If match_slash is false, do not look past 279 + * the first slash as it cannot belong to '*'. 280 + */ 281 + if (!is_glob_special(*p)) { 282 + p_ch = *p; 283 + if ((flags & WM_CASEFOLD) && ISUPPER(p_ch)) 284 + p_ch = tolower(p_ch); 285 + while ((t_ch = *text) != '\0' && 286 + (match_slash || t_ch != '/')) { 287 + if ((flags & WM_CASEFOLD) && ISUPPER(t_ch)) 288 + t_ch = tolower(t_ch); 289 + if (t_ch == p_ch) 290 + break; 291 + text++; 292 + } 293 + if (t_ch != p_ch) 294 + return WM_NOMATCH; 295 + } 296 + if ((matched = dowild(p, text, flags)) != WM_NOMATCH) { 297 + if (!match_slash || matched != WM_ABORT_TO_STARSTAR) 298 + return matched; 299 + } else if (!match_slash && t_ch == '/') 300 + return WM_ABORT_TO_STARSTAR; 301 + t_ch = *++text; 302 + } 303 + return WM_ABORT_ALL; 304 + case '[': 305 + p_ch = *++p; 306 + if (p_ch == '^') 307 + p_ch = '!'; 308 + /* Assign literal 1/0 because of "matched" comparison. */ 309 + negated = p_ch == '!' ? 1 : 0; 310 + if (negated) { 311 + /* Inverted character class. */ 312 + p_ch = *++p; 313 + } 314 + prev_ch = 0; 315 + matched = 0; 316 + do { 317 + if (!p_ch) 318 + return WM_ABORT_ALL; 319 + if (p_ch == '\\') { 320 + p_ch = *++p; 321 + if (!p_ch) 322 + return WM_ABORT_ALL; 323 + if (t_ch == p_ch) 324 + matched = 1; 325 + } else if (p_ch == '-' && prev_ch && p[1] && p[1] != ']') { 326 + p_ch = *++p; 327 + if (p_ch == '\\') { 328 + p_ch = *++p; 329 + if (!p_ch) 330 + return WM_ABORT_ALL; 331 + } 332 + if (t_ch <= p_ch && t_ch >= prev_ch) 333 + matched = 1; 334 + else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) { 335 + uchar t_ch_upper = toupper(t_ch); 336 + if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch) 337 + matched = 1; 338 + } 339 + p_ch = 0; /* This makes "prev_ch" get set to 0. */ 340 + } else if (p_ch == '[' && p[1] == ':') { 341 + const uchar *s; 342 + int i; 343 + for (s = p += 2; (p_ch = *p) && p_ch != ']'; p++) {} /*SHARED ITERATOR*/ 344 + if (!p_ch) 345 + return WM_ABORT_ALL; 346 + i = p - s - 1; 347 + if (i < 0 || p[-1] != ':') { 348 + /* Didn't find ":]", so treat like a normal set. */ 349 + p = s - 2; 350 + p_ch = '['; 351 + if (t_ch == p_ch) 352 + matched = 1; 353 + continue; 354 + } 355 + if (CC_EQ(s,i, "alnum")) { 356 + if (ISALNUM(t_ch)) 357 + matched = 1; 358 + } else if (CC_EQ(s,i, "alpha")) { 359 + if (ISALPHA(t_ch)) 360 + matched = 1; 361 + } else if (CC_EQ(s,i, "blank")) { 362 + if (ISBLANK(t_ch)) 363 + matched = 1; 364 + } else if (CC_EQ(s,i, "cntrl")) { 365 + if (ISCNTRL(t_ch)) 366 + matched = 1; 367 + } else if (CC_EQ(s,i, "digit")) { 368 + if (ISDIGIT(t_ch)) 369 + matched = 1; 370 + } else if (CC_EQ(s,i, "graph")) { 371 + if (ISGRAPH(t_ch)) 372 + matched = 1; 373 + } else if (CC_EQ(s,i, "lower")) { 374 + if (ISLOWER(t_ch)) 375 + matched = 1; 376 + } else if (CC_EQ(s,i, "print")) { 377 + if (ISPRINT(t_ch)) 378 + matched = 1; 379 + } else if (CC_EQ(s,i, "punct")) { 380 + if (ISPUNCT(t_ch)) 381 + matched = 1; 382 + } else if (CC_EQ(s,i, "space")) { 383 + if (ISSPACE(t_ch)) 384 + matched = 1; 385 + } else if (CC_EQ(s,i, "upper")) { 386 + if (ISUPPER(t_ch)) 387 + matched = 1; 388 + else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) 389 + matched = 1; 390 + } else if (CC_EQ(s,i, "xdigit")) { 391 + if (ISXDIGIT(t_ch)) 392 + matched = 1; 393 + } else /* malformed [:class:] string */ 394 + return WM_ABORT_ALL; 395 + p_ch = 0; /* This makes "prev_ch" get set to 0. */ 396 + } else if (t_ch == p_ch) 397 + matched = 1; 398 + } while (prev_ch = p_ch, (p_ch = *++p) != ']'); 399 + if (matched == negated || 400 + ((flags & WM_PATHNAME) && t_ch == '/')) 401 + return WM_NOMATCH; 402 + continue; 403 + } 404 + } 405 + 406 + return *text ? WM_NOMATCH : WM_MATCH; 407 + } 408 + 409 + /* Match the "pattern" against the "text" string. */ 410 + static int wildmatch(const char *pattern, const char *text, unsigned int flags) 411 + { 412 + // local modification: move WM_CASEFOLD here 413 + if (ignore_case) 414 + flags |= WM_CASEFOLD; 415 + 416 + return dowild((const uchar*)pattern, (const uchar*)text, flags); 417 + } 418 + 419 + // Copied from dir.h 420 + 421 + #define PATTERN_FLAG_NODIR 1 422 + #define PATTERN_FLAG_ENDSWITH 4 423 + #define PATTERN_FLAG_MUSTBEDIR 8 424 + #define PATTERN_FLAG_NEGATIVE 16 425 + 426 + // Copied from dir.c 427 + 428 + static int fspathncmp(const char *a, const char *b, size_t count) 429 + { 430 + return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count); 431 + } 432 + 433 + static int simple_length(const char *match) 434 + { 435 + int len = -1; 436 + 437 + for (;;) { 438 + unsigned char c = *match++; 439 + len++; 440 + if (c == '\0' || is_glob_special(c)) 441 + return len; 442 + } 443 + } 444 + 445 + static int no_wildcard(const char *string) 446 + { 447 + return string[simple_length(string)] == '\0'; 448 + } 449 + 450 + static void parse_path_pattern(const char **pattern, 451 + int *patternlen, 452 + unsigned *flags, 453 + int *nowildcardlen) 454 + { 455 + const char *p = *pattern; 456 + size_t i, len; 457 + 458 + *flags = 0; 459 + if (*p == '!') { 460 + *flags |= PATTERN_FLAG_NEGATIVE; 461 + p++; 462 + } 463 + len = strlen(p); 464 + if (len && p[len - 1] == '/') { 465 + len--; 466 + *flags |= PATTERN_FLAG_MUSTBEDIR; 467 + } 468 + for (i = 0; i < len; i++) { 469 + if (p[i] == '/') 470 + break; 471 + } 472 + if (i == len) 473 + *flags |= PATTERN_FLAG_NODIR; 474 + *nowildcardlen = simple_length(p); 475 + /* 476 + * we should have excluded the trailing slash from 'p' too, 477 + * but that's one more allocation. Instead just make sure 478 + * nowildcardlen does not exceed real patternlen 479 + */ 480 + if (*nowildcardlen > len) 481 + *nowildcardlen = len; 482 + if (*p == '*' && no_wildcard(p + 1)) 483 + *flags |= PATTERN_FLAG_ENDSWITH; 484 + *pattern = p; 485 + *patternlen = len; 486 + } 487 + 488 + static void trim_trailing_spaces(char *buf) 489 + { 490 + char *p, *last_space = NULL; 491 + 492 + for (p = buf; *p; p++) 493 + switch (*p) { 494 + case ' ': 495 + if (!last_space) 496 + last_space = p; 497 + break; 498 + case '\\': 499 + p++; 500 + if (!*p) 501 + return; 502 + /* fallthrough */ 503 + default: 504 + last_space = NULL; 505 + } 506 + 507 + if (last_space) 508 + *last_space = '\0'; 509 + } 510 + 511 + static int match_basename(const char *basename, int basenamelen, 512 + const char *pattern, int prefix, int patternlen, 513 + unsigned flags) 514 + { 515 + if (prefix == patternlen) { 516 + if (patternlen == basenamelen && 517 + !fspathncmp(pattern, basename, basenamelen)) 518 + return 1; 519 + } else if (flags & PATTERN_FLAG_ENDSWITH) { 520 + /* "*literal" matching against "fooliteral" */ 521 + if (patternlen - 1 <= basenamelen && 522 + !fspathncmp(pattern + 1, 523 + basename + basenamelen - (patternlen - 1), 524 + patternlen - 1)) 525 + return 1; 526 + } else { 527 + // local modification: call wildmatch() directly 528 + if (!wildmatch(pattern, basename, flags)) 529 + return 1; 530 + } 531 + return 0; 532 + } 533 + 534 + static int match_pathname(const char *pathname, int pathlen, 535 + const char *base, int baselen, 536 + const char *pattern, int prefix, int patternlen) 537 + { 538 + // local modification: remove local variables 539 + 540 + /* 541 + * match with FNM_PATHNAME; the pattern has base implicitly 542 + * in front of it. 543 + */ 544 + if (*pattern == '/') { 545 + pattern++; 546 + patternlen--; 547 + prefix--; 548 + } 549 + 550 + /* 551 + * baselen does not count the trailing slash. base[] may or 552 + * may not end with a trailing slash though. 553 + */ 554 + if (pathlen < baselen + 1 || 555 + (baselen && pathname[baselen] != '/') || 556 + fspathncmp(pathname, base, baselen)) 557 + return 0; 558 + 559 + // local modification: simplified because always baselen > 0 560 + pathname += baselen + 1; 561 + pathlen -= baselen + 1; 562 + 563 + if (prefix) { 564 + /* 565 + * if the non-wildcard part is longer than the 566 + * remaining pathname, surely it cannot match. 567 + */ 568 + if (prefix > pathlen) 569 + return 0; 570 + 571 + if (fspathncmp(pattern, pathname, prefix)) 572 + return 0; 573 + pattern += prefix; 574 + patternlen -= prefix; 575 + pathname += prefix; 576 + pathlen -= prefix; 577 + 578 + /* 579 + * If the whole pattern did not have a wildcard, 580 + * then our prefix match is all we need; we 581 + * do not need to call fnmatch at all. 582 + */ 583 + if (!patternlen && !pathlen) 584 + return 1; 585 + } 586 + 587 + // local modification: call wildmatch() directly 588 + return !wildmatch(pattern, pathname, WM_PATHNAME); 589 + } 590 + 591 + // Copied from git/utf8.c 592 + 593 + static const char utf8_bom[] = "\357\273\277"; 594 + 595 + //----------------------------(IMPORT FROM GIT END)---------------------------- 596 + 597 + struct pattern { 598 + unsigned int flags; 599 + int nowildcardlen; 600 + int patternlen; 601 + int dirlen; 602 + char pattern[]; 603 + }; 604 + 605 + static struct pattern **pattern_list; 606 + static int nr_patterns, alloced_patterns; 607 + 608 + // Remember the number of patterns at each directory level 609 + static int *nr_patterns_at; 610 + // Track the current/max directory level; 611 + static int depth, max_depth; 612 + static bool debug_on; 613 + static FILE *out_fp, *stat_fp; 614 + static char *prefix = ""; 615 + static char *progname; 616 + 617 + static void __attribute__((noreturn)) perror_exit(const char *s) 618 + { 619 + perror(s); 620 + 621 + exit(EXIT_FAILURE); 622 + } 623 + 624 + static void __attribute__((noreturn)) error_exit(const char *fmt, ...) 625 + { 626 + va_list args; 627 + 628 + fprintf(stderr, "%s: error: ", progname); 629 + 630 + va_start(args, fmt); 631 + vfprintf(stderr, fmt, args); 632 + va_end(args); 633 + 634 + exit(EXIT_FAILURE); 635 + } 636 + 637 + static void debug(const char *fmt, ...) 638 + { 639 + va_list args; 640 + int i; 641 + 642 + if (!debug_on) 643 + return; 644 + 645 + fprintf(stderr, "[DEBUG] "); 646 + 647 + for (i = 0; i < depth * 2; i++) 648 + fputc(' ', stderr); 649 + 650 + va_start(args, fmt); 651 + vfprintf(stderr, fmt, args); 652 + va_end(args); 653 + } 654 + 655 + static void *xrealloc(void *ptr, size_t size) 656 + { 657 + ptr = realloc(ptr, size); 658 + if (!ptr) 659 + perror_exit(progname); 660 + 661 + return ptr; 662 + } 663 + 664 + static void *xmalloc(size_t size) 665 + { 666 + return xrealloc(NULL, size); 667 + } 668 + 669 + // similar to last_matching_pattern_from_list() in GIT 670 + static bool is_ignored(const char *path, int pathlen, int dirlen, bool is_dir) 671 + { 672 + int i; 673 + 674 + // Search in the reverse order because the last matching pattern wins. 675 + for (i = nr_patterns - 1; i >= 0; i--) { 676 + struct pattern *p = pattern_list[i]; 677 + unsigned int flags = p->flags; 678 + const char *gitignore_dir = p->pattern + p->patternlen + 1; 679 + bool ignored; 680 + 681 + if ((flags & PATTERN_FLAG_MUSTBEDIR) && !is_dir) 682 + continue; 683 + 684 + if (flags & PATTERN_FLAG_NODIR) { 685 + if (!match_basename(path + dirlen + 1, 686 + pathlen - dirlen - 1, 687 + p->pattern, 688 + p->nowildcardlen, 689 + p->patternlen, 690 + p->flags)) 691 + continue; 692 + } else { 693 + if (!match_pathname(path, pathlen, 694 + gitignore_dir, p->dirlen, 695 + p->pattern, 696 + p->nowildcardlen, 697 + p->patternlen)) 698 + continue; 699 + } 700 + 701 + debug("%s: matches %s%s%s (%s/.gitignore)\n", path, 702 + flags & PATTERN_FLAG_NEGATIVE ? "!" : "", p->pattern, 703 + flags & PATTERN_FLAG_MUSTBEDIR ? "/" : "", 704 + gitignore_dir); 705 + 706 + ignored = (flags & PATTERN_FLAG_NEGATIVE) == 0; 707 + if (ignored) 708 + debug("Ignore: %s\n", path); 709 + 710 + return ignored; 711 + } 712 + 713 + debug("%s: no match\n", path); 714 + 715 + return false; 716 + } 717 + 718 + static void add_pattern(const char *string, const char *dir, int dirlen) 719 + { 720 + struct pattern *p; 721 + int patternlen, nowildcardlen; 722 + unsigned int flags; 723 + 724 + parse_path_pattern(&string, &patternlen, &flags, &nowildcardlen); 725 + 726 + if (patternlen == 0) 727 + return; 728 + 729 + p = xmalloc(sizeof(*p) + patternlen + dirlen + 2); 730 + 731 + memcpy(p->pattern, string, patternlen); 732 + p->pattern[patternlen] = 0; 733 + memcpy(p->pattern + patternlen + 1, dir, dirlen); 734 + p->pattern[patternlen + 1 + dirlen] = 0; 735 + 736 + p->patternlen = patternlen; 737 + p->nowildcardlen = nowildcardlen; 738 + p->dirlen = dirlen; 739 + p->flags = flags; 740 + 741 + debug("Add pattern: %s%s%s\n", 742 + flags & PATTERN_FLAG_NEGATIVE ? "!" : "", p->pattern, 743 + flags & PATTERN_FLAG_MUSTBEDIR ? "/" : ""); 744 + 745 + if (nr_patterns >= alloced_patterns) { 746 + alloced_patterns += 128; 747 + pattern_list = xrealloc(pattern_list, 748 + sizeof(*pattern_list) * alloced_patterns); 749 + } 750 + 751 + pattern_list[nr_patterns++] = p; 752 + } 753 + 754 + // similar to add_patterns_from_buffer() in GIT 755 + static void add_patterns_from_gitignore(const char *dir, int dirlen) 756 + { 757 + struct stat st; 758 + char path[PATH_MAX], *buf, *entry; 759 + size_t size; 760 + int fd, pathlen, i; 761 + 762 + pathlen = snprintf(path, sizeof(path), "%s/.gitignore", dir); 763 + if (pathlen >= sizeof(path)) 764 + error_exit("%s: too long path was truncated\n", path); 765 + 766 + fd = open(path, O_RDONLY | O_NOFOLLOW); 767 + if (fd < 0) { 768 + if (errno != ENOENT) 769 + return perror_exit(path); 770 + return; 771 + } 772 + 773 + if (fstat(fd, &st) < 0) 774 + perror_exit(path); 775 + 776 + size = st.st_size; 777 + 778 + buf = xmalloc(size + 1); 779 + if (read(fd, buf, st.st_size) != st.st_size) 780 + perror_exit(path); 781 + 782 + buf[st.st_size] = '\n'; 783 + if (close(fd)) 784 + perror_exit(path); 785 + 786 + debug("Parse %s\n", path); 787 + 788 + entry = buf; 789 + 790 + // skip utf8 bom 791 + if (!strncmp(entry, utf8_bom, strlen(utf8_bom))) 792 + entry += strlen(utf8_bom); 793 + 794 + for (i = entry - buf; i < size; i++) { 795 + if (buf[i] == '\n') { 796 + if (entry != buf + i && entry[0] != '#') { 797 + buf[i - (i && buf[i-1] == '\r')] = 0; 798 + trim_trailing_spaces(entry); 799 + add_pattern(entry, dir, dirlen); 800 + } 801 + entry = buf + i + 1; 802 + } 803 + } 804 + 805 + free(buf); 806 + } 807 + 808 + // Save the current number of patterns and increment the depth 809 + static void increment_depth(void) 810 + { 811 + if (depth >= max_depth) { 812 + max_depth += 1; 813 + nr_patterns_at = xrealloc(nr_patterns_at, 814 + sizeof(*nr_patterns_at) * max_depth); 815 + } 816 + 817 + nr_patterns_at[depth] = nr_patterns; 818 + depth++; 819 + } 820 + 821 + // Decrement the depth, and free up the patterns of this directory level. 822 + static void decrement_depth(void) 823 + { 824 + depth--; 825 + assert(depth >= 0); 826 + 827 + while (nr_patterns > nr_patterns_at[depth]) 828 + free(pattern_list[--nr_patterns]); 829 + } 830 + 831 + static void print_path(const char *path) 832 + { 833 + // The path always starts with "./" 834 + assert(strlen(path) >= 2); 835 + 836 + // Replace the root directory with a preferred prefix. 837 + // This is useful for the tar command. 838 + fprintf(out_fp, "%s%s\n", prefix, path + 2); 839 + } 840 + 841 + static void print_stat(const char *path, struct stat *st) 842 + { 843 + if (!stat_fp) 844 + return; 845 + 846 + if (!S_ISREG(st->st_mode) && !S_ISLNK(st->st_mode)) 847 + return; 848 + 849 + assert(strlen(path) >= 2); 850 + 851 + fprintf(stat_fp, "%c %9ld %10ld %s\n", 852 + S_ISLNK(st->st_mode) ? 'l' : '-', 853 + st->st_size, st->st_mtim.tv_sec, path + 2); 854 + } 855 + 856 + // Traverse the entire directory tree, parsing .gitignore files. 857 + // Print file paths that are not tracked by git. 858 + // 859 + // Return true if all files under the directory are ignored, false otherwise. 860 + static bool traverse_directory(const char *dir, int dirlen) 861 + { 862 + bool all_ignored = true; 863 + DIR *dirp; 864 + 865 + debug("Enter[%d]: %s\n", depth, dir); 866 + increment_depth(); 867 + 868 + add_patterns_from_gitignore(dir, dirlen); 869 + 870 + dirp = opendir(dir); 871 + if (!dirp) 872 + perror_exit(dir); 873 + 874 + while (1) { 875 + struct dirent *d; 876 + struct stat st; 877 + char path[PATH_MAX]; 878 + int pathlen; 879 + bool ignored; 880 + 881 + errno = 0; 882 + d = readdir(dirp); 883 + if (!d) { 884 + if (errno) 885 + perror_exit(dir); 886 + break; 887 + } 888 + 889 + if (!strcmp(d->d_name, "..") || !strcmp(d->d_name, ".")) 890 + continue; 891 + 892 + pathlen = snprintf(path, sizeof(path), "%s/%s", dir, d->d_name); 893 + if (pathlen >= sizeof(path)) 894 + error_exit("%s: too long path was truncated\n", path); 895 + 896 + if (lstat(path, &st) < 0) 897 + perror_exit(path); 898 + 899 + if ((!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode)) || 900 + is_ignored(path, pathlen, dirlen, S_ISDIR(st.st_mode))) { 901 + ignored = true; 902 + } else { 903 + if (S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode)) 904 + // If all the files in a directory are ignored, 905 + // let's ignore that directory as well. This 906 + // will avoid empty directories in the tarball. 907 + ignored = traverse_directory(path, pathlen); 908 + else 909 + ignored = false; 910 + } 911 + 912 + if (ignored) { 913 + print_path(path); 914 + } else { 915 + print_stat(path, &st); 916 + all_ignored = false; 917 + } 918 + } 919 + 920 + if (closedir(dirp)) 921 + perror_exit(dir); 922 + 923 + decrement_depth(); 924 + debug("Leave[%d]: %s\n", depth, dir); 925 + 926 + return all_ignored; 927 + } 928 + 929 + static void usage(void) 930 + { 931 + fprintf(stderr, 932 + "usage: %s [options]\n" 933 + "\n" 934 + "Show files that are ignored by git\n" 935 + "\n" 936 + "options:\n" 937 + " -d, --debug print debug messages to stderr\n" 938 + " -e, --exclude PATTERN add the given exclude pattern\n" 939 + " -h, --help show this help message and exit\n" 940 + " -i, --ignore-case Ignore case differences between the patterns and the files\n" 941 + " -o, --output FILE output the ignored files to a file (default: '-', i.e. stdout)\n" 942 + " -p, --prefix PREFIX prefix added to each path (default: empty string)\n" 943 + " -r, --rootdir DIR root of the source tree (default: current working directory)\n" 944 + " -s, --stat FILE output the file stat of non-ignored files to a file\n", 945 + progname); 946 + } 947 + 948 + static void open_output(const char *pathname, FILE **fp) 949 + { 950 + if (strcmp(pathname, "-")) { 951 + *fp = fopen(pathname, "w"); 952 + if (!*fp) 953 + perror_exit(pathname); 954 + } else { 955 + *fp = stdout; 956 + } 957 + } 958 + 959 + static void close_output(const char *pathname, FILE *fp) 960 + { 961 + fflush(fp); 962 + 963 + if (ferror(fp)) 964 + error_exit("not all data was written to the output\n"); 965 + 966 + if (fclose(fp)) 967 + perror_exit(pathname); 968 + } 969 + 970 + int main(int argc, char *argv[]) 971 + { 972 + const char *output = "-"; 973 + const char *rootdir = "."; 974 + const char *stat = NULL; 975 + 976 + progname = strrchr(argv[0], '/'); 977 + if (progname) 978 + progname++; 979 + else 980 + progname = argv[0]; 981 + 982 + while (1) { 983 + static struct option long_options[] = { 984 + {"debug", no_argument, NULL, 'd'}, 985 + {"help", no_argument, NULL, 'h'}, 986 + {"ignore-case", no_argument, NULL, 'i'}, 987 + {"output", required_argument, NULL, 'o'}, 988 + {"prefix", required_argument, NULL, 'p'}, 989 + {"rootdir", required_argument, NULL, 'r'}, 990 + {"stat", required_argument, NULL, 's'}, 991 + {"exclude", required_argument, NULL, 'x'}, 992 + {}, 993 + }; 994 + 995 + int c = getopt_long(argc, argv, "dhino:p:r:s:x:", long_options, NULL); 996 + 997 + if (c == -1) 998 + break; 999 + 1000 + switch (c) { 1001 + case 'd': 1002 + debug_on = true; 1003 + break; 1004 + case 'h': 1005 + usage(); 1006 + exit(0); 1007 + case 'i': 1008 + ignore_case = true; 1009 + break; 1010 + case 'o': 1011 + output = optarg; 1012 + break; 1013 + case 'p': 1014 + prefix = optarg; 1015 + break; 1016 + case 'r': 1017 + rootdir = optarg; 1018 + break; 1019 + case 's': 1020 + stat = optarg; 1021 + break; 1022 + case 'x': 1023 + add_pattern(optarg, ".", strlen(".")); 1024 + break; 1025 + case '?': 1026 + usage(); 1027 + /* fallthrough */ 1028 + default: 1029 + exit(EXIT_FAILURE); 1030 + } 1031 + } 1032 + 1033 + open_output(output, &out_fp); 1034 + if (stat && stat[0]) 1035 + open_output(stat, &stat_fp); 1036 + 1037 + if (chdir(rootdir)) 1038 + perror_exit(rootdir); 1039 + 1040 + add_pattern(".git/", ".", strlen(".")); 1041 + 1042 + if (traverse_directory(".", strlen("."))) 1043 + print_path("./"); 1044 + 1045 + assert(depth == 0); 1046 + 1047 + while (nr_patterns > 0) 1048 + free(pattern_list[--nr_patterns]); 1049 + free(pattern_list); 1050 + free(nr_patterns_at); 1051 + 1052 + close_output(output, out_fp); 1053 + if (stat_fp) 1054 + close_output(stat, stat_fp); 1055 + 1056 + return 0; 1057 + }
+19
scripts/misc-check
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + set -e 5 + 6 + # Detect files that are tracked but ignored by git. This is checked only when 7 + # ${KBUILD_EXTRA_WARN} contains 1, git is installed, and the source tree is 8 + # tracked by git. 9 + check_tracked_ignored_files () { 10 + case "${KBUILD_EXTRA_WARN}" in 11 + *1*) ;; 12 + *) return;; 13 + esac 14 + 15 + git -C ${srctree:-.} ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | 16 + sed 's/$/: warning: ignored by one of the .gitignore files/' >&2 17 + } 18 + 19 + check_tracked_ignored_files
+3 -5
scripts/package/builddeb
··· 42 42 else 43 43 chown -R root:root "$pdir" 44 44 fi 45 - chmod -R go-w "$pdir" 46 - # in case we are in a restrictive umask environment like 0077 47 - chmod -R a+rX "$pdir" 48 - # in case we build in a setuid/setgid directory 49 - chmod -R ug-s "$pdir" 45 + # a+rX in case we are in a restrictive umask environment like 0077 46 + # ug-s in case we build in a setuid/setgid directory 47 + chmod -R go-w,a+rX,ug-s "$pdir" 50 48 51 49 # Create the package 52 50 dpkg-gencontrol -p$pname -P"$pdir"
+1 -51
scripts/package/buildtar
··· 16 16 # 17 17 # Some variables and settings used throughout the script 18 18 # 19 - tmpdir="${objtree}/tar-install" 20 - tarball="${objtree}/linux-${KERNELRELEASE}-${ARCH}.tar" 21 - 22 - 23 - # 24 - # Figure out how to compress, if requested at all 25 - # 26 - case "${1}" in 27 - dir-pkg|tar-pkg) 28 - opts= 29 - ;; 30 - targz-pkg) 31 - opts="-I ${KGZIP}" 32 - tarball=${tarball}.gz 33 - ;; 34 - tarbz2-pkg) 35 - opts="-I ${KBZIP2}" 36 - tarball=${tarball}.bz2 37 - ;; 38 - tarxz-pkg) 39 - opts="-I ${XZ}" 40 - tarball=${tarball}.xz 41 - ;; 42 - tarzst-pkg) 43 - opts="-I ${ZSTD}" 44 - tarball=${tarball}.zst 45 - ;; 46 - *) 47 - echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2 48 - exit 1 49 - ;; 50 - esac 51 - 19 + tmpdir=$1 52 20 53 21 # 54 22 # Clean-up and re-create the temporary directory ··· 116 148 sleep 5 117 149 ;; 118 150 esac 119 - 120 - if [ "${1}" = dir-pkg ]; then 121 - echo "Kernel tree successfully created in $tmpdir" 122 - exit 0 123 - fi 124 - 125 - # 126 - # Create the tarball 127 - # 128 - if tar --owner=root --group=root --help >/dev/null 2>&1; then 129 - opts="$opts --owner=root --group=root" 130 - fi 131 - 132 - tar cf $tarball -C $tmpdir $opts $dirs 133 - 134 - echo "Tarball successfully created in $tarball" 135 - 136 - exit 0
+16
scripts/package/deb-build-option
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + # Set up CROSS_COMPILE if we are cross-compiling, but not called from the 5 + # kernel toplevel Makefile 6 + if [ -z "${CROSS_COMPILE}${cross_compiling}" -a "${DEB_HOST_ARCH}" != "${DEB_BUILD_ARCH}" ]; then 7 + echo CROSS_COMPILE=${DEB_HOST_GNU_TYPE}- 8 + fi 9 + 10 + version=$(dpkg-parsechangelog -S Version) 11 + version_upstream="${version%-*}" 12 + debian_revision="${version#${version_upstream}}" 13 + debian_revision="${debian_revision#*-}" 14 + 15 + echo KERNELRELEASE=${version_upstream} 16 + echo KBUILD_BUILD_VERSION=${debian_revision}
+28 -12
scripts/package/mkdebian
··· 84 84 fi 85 85 } 86 86 87 + rm -rf debian 88 + 87 89 # Some variables and settings used throughout the script 88 90 version=$KERNELRELEASE 89 91 if [ -n "$KDEB_PKGVERSION" ]; then 90 92 packageversion=$KDEB_PKGVERSION 91 - revision=${packageversion##*-} 92 93 else 93 - revision=$($srctree/init/build-version) 94 - packageversion=$version-$revision 94 + packageversion=$version-$($srctree/init/build-version) 95 95 fi 96 - sourcename=$KDEB_SOURCENAME 96 + sourcename=${KDEB_SOURCENAME:-linux-upstream} 97 97 98 98 if [ "$ARCH" = "um" ] ; then 99 99 packagename=user-mode-linux ··· 133 133 fi 134 134 135 135 mkdir -p debian/source/ 136 - echo "1.0" > debian/source/format 136 + echo "3.0 (quilt)" > debian/source/format 137 + 138 + { 139 + echo "diff-ignore" 140 + echo "extend-diff-ignore = .*" 141 + } > debian/source/local-options 142 + 143 + # Add .config as a patch 144 + mkdir -p debian/patches 145 + { 146 + echo "Subject: Add .config" 147 + echo "Author: ${maintainer}" 148 + echo 149 + echo "--- /dev/null" 150 + echo "+++ linux/.config" 151 + diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3 152 + } > debian/patches/config 153 + echo config > debian/patches/series 137 154 138 155 echo $debarch > debian/arch 139 156 extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)" ··· 242 225 243 226 build-indep: 244 227 build-arch: 245 - \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ 246 - KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile 228 + \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ 229 + \$(shell \$(srctree)/scripts/package/deb-build-option) \ 230 + olddefconfig all 247 231 248 232 build: build-arch 249 233 250 234 binary-indep: 251 235 binary-arch: build-arch 252 - \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ 253 - KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg 254 - 236 + \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} intdeb-pkg 255 237 clean: 256 - rm -rf debian/*tmp debian/files 257 - \$(MAKE) clean 238 + rm -rf debian/files debian/linux-* 239 + \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} clean 258 240 259 241 binary: binary-arch 260 242 EOF
+5 -7
scripts/package/mkspec
··· 33 33 --exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \ 34 34 --exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s" 35 35 36 - test -n "$LOCALVERSION" && MAKE="$MAKE LOCALVERSION=$LOCALVERSION" 37 - 38 36 # We can label the here-doc lines for conditional output to the spec file 39 37 # 40 38 # Labels: ··· 47 49 Group: System Environment/Kernel 48 50 Vendor: The Linux Community 49 51 URL: https://www.kernel.org 50 - $S Source: kernel-$__KERNELRELEASE.tar.gz 52 + $S Source0: linux.tar.gz 53 + $S Source1: .config 51 54 Provides: $PROVIDES 52 55 $S BuildRequires: bc binutils bison dwarves 53 56 $S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex ··· 84 85 $S$M against the $__KERNELRELEASE kernel package. 85 86 $S$M 86 87 $S %prep 87 - $S %setup -q 88 - $S rm -f scripts/basic/fixdep scripts/kconfig/conf 89 - $S rm -f tools/objtool/{fixdep,objtool} 88 + $S %setup -q -n linux 89 + $S cp %{SOURCE1} . 90 90 $S 91 91 $S %build 92 - $S $MAKE %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release} 92 + $S $MAKE %{?_smp_mflags} KERNELRELEASE=$KERNELRELEASE KBUILD_BUILD_VERSION=%{release} 93 93 $S 94 94 %install 95 95 mkdir -p %{buildroot}/boot
+7 -23
scripts/remove-stale-files
··· 21 21 # then will be really dead and removed from the code base entirely. 22 22 23 23 rm -f arch/powerpc/purgatory/kexec-purgatory.c 24 - 25 - # These were previously generated source files. When you are building the kernel 26 - # with O=, make sure to remove the stale files in the output tree. Otherwise, 27 - # the build system wrongly compiles the stale ones. 28 - if [ -n "${building_out_of_srctree}" ]; then 29 - for f in fdt_rw.c fdt_ro.c fdt_wip.c fdt.c ashldi3.S bswapsdi2.S font.c lib1funcs.S hyp-stub.S 30 - do 31 - rm -f arch/arm/boot/compressed/${f} 32 - done 33 - 34 - for f in uart-ath79.c ashldi3.c bswapdi.c bswapsi.c 35 - do 36 - rm -f arch/mips/boot/compressed/${f} 37 - done 38 - 39 - for f in firmware.c real2.S 40 - do 41 - rm -f arch/parisc/boot/compressed/${f} 42 - done 43 - fi 44 - 45 24 rm -f arch/riscv/purgatory/kexec-purgatory.c 25 + rm -f arch/x86/purgatory/kexec-purgatory.c 46 26 47 27 rm -f scripts/extract-cert 48 28 49 - rm -f arch/x86/purgatory/kexec-purgatory.c 50 - 51 29 rm -f scripts/kconfig/[gmnq]conf-cfg 30 + 31 + rm -f rust/target.json 32 + 33 + rm -f scripts/bin2c 34 + 35 + rm -f .scmversion
+67 -65
scripts/setlocalversion
··· 11 11 # 12 12 13 13 usage() { 14 - echo "Usage: $0 [--save-scmversion] [srctree]" >&2 14 + echo "Usage: $0 [srctree]" >&2 15 15 exit 1 16 16 } 17 17 18 - scm_only=false 19 18 srctree=. 20 - if test "$1" = "--save-scmversion"; then 21 - scm_only=true 22 - shift 23 - fi 24 19 if test $# -gt 0; then 25 20 srctree=$1 26 21 shift ··· 27 32 scm_version() 28 33 { 29 34 local short 35 + local tag 30 36 short=false 31 37 32 38 cd "$srctree" 33 - if test -e .scmversion; then 34 - cat .scmversion 35 - return 36 - fi 37 39 if test "$1" = "--short"; then 38 40 short=true 39 41 fi 40 42 41 - # Check for git and a git repo. 42 - if test -z "$(git rev-parse --show-cdup 2>/dev/null)" && 43 - head=$(git rev-parse --verify HEAD 2>/dev/null); then 43 + if test -n "$(git rev-parse --show-cdup 2>/dev/null)"; then 44 + return 45 + fi 44 46 45 - # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore 46 - # it, because this version is defined in the top level Makefile. 47 - if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then 47 + if ! head=$(git rev-parse --verify HEAD 2>/dev/null); then 48 + return 49 + fi 48 50 49 - # If only the short version is requested, don't bother 50 - # running further git commands 51 - if $short; then 52 - echo "+" 53 - return 54 - fi 55 - # If we are past a tagged commit (like 56 - # "v2.6.30-rc5-302-g72357d5"), we pretty print it. 57 - if atag="$(git describe 2>/dev/null)"; then 58 - echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' 59 - fi 51 + # If a localversion*' file and the corresponding annotated tag exist, 52 + # use it. This is the case in linux-next. 53 + tag=${file_localversion#-} 54 + tag=$(git describe --exact-match --match=$tag $tag 2>/dev/null) 60 55 61 - # Add -g and exactly 12 hex chars. 62 - printf '%s%s' -g "$(echo $head | cut -c1-12)" 56 + # Otherwise, default to the annotated tag derived from KERNELVERSION. 57 + # mainline kernel: 6.2.0-rc5 -> v6.2-rc5 58 + # stable kernel: 6.1.7 -> v6.1.7 59 + if [ -z "${tag}" ]; then 60 + tag=v$(echo "${KERNELVERSION}" | sed -E 's/^([0-9]+\.[0-9]+)\.0(.*)$/\1\2/') 61 + fi 62 + 63 + # If we are at the tagged commit, we ignore it because the version is 64 + # well-defined. 65 + if [ -z "$(git describe --exact-match --match=$tag 2>/dev/null)" ]; then 66 + 67 + # If only the short version is requested, don't bother 68 + # running further git commands 69 + if $short; then 70 + echo "+" 71 + return 72 + fi 73 + # If we are past the tagged commit, we pretty print it. 74 + # (like 6.1.0-14595-g292a089d78d3) 75 + if atag="$(git describe --match=$tag 2>/dev/null)"; then 76 + echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' 63 77 fi 64 78 65 - # Check for uncommitted changes. 66 - # This script must avoid any write attempt to the source tree, 67 - # which might be read-only. 68 - # You cannot use 'git describe --dirty' because it tries to 69 - # create .git/index.lock . 70 - # First, with git-status, but --no-optional-locks is only 71 - # supported in git >= 2.14, so fall back to git-diff-index if 72 - # it fails. Note that git-diff-index does not refresh the 73 - # index, so it may give misleading results. See 74 - # git-update-index(1), git-diff-index(1), and git-status(1). 75 - if { 76 - git --no-optional-locks status -uno --porcelain 2>/dev/null || 77 - git diff-index --name-only HEAD 78 - } | read dummy; then 79 - printf '%s' -dirty 80 - fi 79 + # Add -g and exactly 12 hex chars. 80 + printf '%s%s' -g "$(echo $head | cut -c1-12)" 81 + fi 82 + 83 + # Check for uncommitted changes. 84 + # This script must avoid any write attempt to the source tree, which 85 + # might be read-only. 86 + # You cannot use 'git describe --dirty' because it tries to create 87 + # .git/index.lock . 88 + # First, with git-status, but --no-optional-locks is only supported in 89 + # git >= 2.14, so fall back to git-diff-index if it fails. Note that 90 + # git-diff-index does not refresh the index, so it may give misleading 91 + # results. 92 + # See git-update-index(1), git-diff-index(1), and git-status(1). 93 + if { 94 + git --no-optional-locks status -uno --porcelain 2>/dev/null || 95 + git diff-index --name-only HEAD 96 + } | read dummy; then 97 + printf '%s' -dirty 81 98 fi 82 99 } 83 100 ··· 110 103 echo "$res" 111 104 } 112 105 113 - if $scm_only; then 114 - if test ! -e .scmversion; then 115 - res=$(scm_version) 116 - echo "$res" >.scmversion 117 - fi 118 - exit 119 - fi 120 - 121 106 if ! test -e include/config/auto.conf; then 122 107 echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2 123 108 exit 1 124 109 fi 125 110 126 - # localversion* files in the build and source directory 127 - res="$(collect_files localversion*)" 128 - if test ! "$srctree" -ef .; then 129 - res="$res$(collect_files "$srctree"/localversion*)" 111 + if [ -z "${KERNELVERSION}" ]; then 112 + echo "KERNELVERSION is not set" >&2 113 + exit 1 130 114 fi 131 115 132 - # CONFIG_LOCALVERSION and LOCALVERSION (if set) 133 - config_localversion=$(sed -n 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/p' include/config/auto.conf) 134 - res="${res}${config_localversion}${LOCALVERSION}" 116 + # localversion* files in the build and source directory 117 + file_localversion="$(collect_files localversion*)" 118 + if test ! "$srctree" -ef .; then 119 + file_localversion="${file_localversion}$(collect_files "$srctree"/localversion*)" 120 + fi 135 121 136 - # scm version string if not at a tagged commit 122 + # version string from CONFIG_LOCALVERSION 123 + config_localversion=$(sed -n 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/p' include/config/auto.conf) 124 + 125 + # scm version string if not at the kernel version tag or at the file_localversion 137 126 if grep -q "^CONFIG_LOCALVERSION_AUTO=y$" include/config/auto.conf; then 138 127 # full scm version string 139 - res="$res$(scm_version)" 128 + scm_version="$(scm_version)" 140 129 elif [ "${LOCALVERSION+set}" != "set" ]; then 141 130 # If the variable LOCALVERSION is not set, append a plus 142 131 # sign if the repository is not in a clean annotated or ··· 141 138 # 142 139 # If the variable LOCALVERSION is set (including being set 143 140 # to an empty string), we don't want to append a plus sign. 144 - scm=$(scm_version --short) 145 - res="$res${scm:++}" 141 + scm_version="$(scm_version --short)" 146 142 fi 147 143 148 - echo "$res" 144 + echo "${KERNELVERSION}${file_localversion}${config_localversion}${LOCALVERSION}${scm_version}"
+1 -1
scripts/tags.sh
··· 8 8 # Uses the following environment variables: 9 9 # SUBARCH, SRCARCH, srctree 10 10 11 - if [ "$KBUILD_VERBOSE" = "1" ]; then 11 + if [[ "$KBUILD_VERBOSE" =~ 1 ]]; then 12 12 set -x 13 13 fi 14 14