1*4882a593Smuzhiyun====================== 2*4882a593SmuzhiyunLinux Kernel Makefiles 3*4882a593Smuzhiyun====================== 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunThis document describes the Linux kernel Makefiles. 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun.. Table of Contents 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun === 1 Overview 10*4882a593Smuzhiyun === 2 Who does what 11*4882a593Smuzhiyun === 3 The kbuild files 12*4882a593Smuzhiyun --- 3.1 Goal definitions 13*4882a593Smuzhiyun --- 3.2 Built-in object goals - obj-y 14*4882a593Smuzhiyun --- 3.3 Loadable module goals - obj-m 15*4882a593Smuzhiyun --- 3.4 Objects which export symbols 16*4882a593Smuzhiyun --- 3.5 Library file goals - lib-y 17*4882a593Smuzhiyun --- 3.6 Descending down in directories 18*4882a593Smuzhiyun --- 3.7 Compilation flags 19*4882a593Smuzhiyun --- 3.8 <deleted> 20*4882a593Smuzhiyun --- 3.9 Dependency tracking 21*4882a593Smuzhiyun --- 3.10 Special Rules 22*4882a593Smuzhiyun --- 3.11 $(CC) support functions 23*4882a593Smuzhiyun --- 3.12 $(LD) support functions 24*4882a593Smuzhiyun --- 3.13 Script Invocation 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun === 4 Host Program support 27*4882a593Smuzhiyun --- 4.1 Simple Host Program 28*4882a593Smuzhiyun --- 4.2 Composite Host Programs 29*4882a593Smuzhiyun --- 4.3 Using C++ for host programs 30*4882a593Smuzhiyun --- 4.4 Controlling compiler options for host programs 31*4882a593Smuzhiyun --- 4.5 When host programs are actually built 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun === 5 Userspace Program support 34*4882a593Smuzhiyun --- 5.1 Simple Userspace Program 35*4882a593Smuzhiyun --- 5.2 Composite Userspace Programs 36*4882a593Smuzhiyun --- 5.3 Controlling compiler options for userspace programs 37*4882a593Smuzhiyun --- 5.4 When userspace programs are actually built 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun === 6 Kbuild clean infrastructure 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun === 7 Architecture Makefiles 42*4882a593Smuzhiyun --- 7.1 Set variables to tweak the build to the architecture 43*4882a593Smuzhiyun --- 7.2 Add prerequisites to archheaders 44*4882a593Smuzhiyun --- 7.3 Add prerequisites to archprepare 45*4882a593Smuzhiyun --- 7.4 List directories to visit when descending 46*4882a593Smuzhiyun --- 7.5 Architecture-specific boot images 47*4882a593Smuzhiyun --- 7.6 Building non-kbuild targets 48*4882a593Smuzhiyun --- 7.7 Commands useful for building a boot image 49*4882a593Smuzhiyun --- 7.8 Custom kbuild commands 50*4882a593Smuzhiyun --- 7.9 Preprocessing linker scripts 51*4882a593Smuzhiyun --- 7.10 Generic header files 52*4882a593Smuzhiyun --- 7.11 Post-link pass 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun === 8 Kbuild syntax for exported headers 55*4882a593Smuzhiyun --- 8.1 no-export-headers 56*4882a593Smuzhiyun --- 8.2 generic-y 57*4882a593Smuzhiyun --- 8.3 generated-y 58*4882a593Smuzhiyun --- 8.4 mandatory-y 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun === 9 Kbuild Variables 61*4882a593Smuzhiyun === 10 Makefile language 62*4882a593Smuzhiyun === 11 Credits 63*4882a593Smuzhiyun === 12 TODO 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun1 Overview 66*4882a593Smuzhiyun========== 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunThe Makefiles have five parts:: 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun Makefile the top Makefile. 71*4882a593Smuzhiyun .config the kernel configuration file. 72*4882a593Smuzhiyun arch/$(ARCH)/Makefile the arch Makefile. 73*4882a593Smuzhiyun scripts/Makefile.* common rules etc. for all kbuild Makefiles. 74*4882a593Smuzhiyun kbuild Makefiles there are about 500 of these. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunThe top Makefile reads the .config file, which comes from the kernel 77*4882a593Smuzhiyunconfiguration process. 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunThe top Makefile is responsible for building two major products: vmlinux 80*4882a593Smuzhiyun(the resident kernel image) and modules (any module files). 81*4882a593SmuzhiyunIt builds these goals by recursively descending into the subdirectories of 82*4882a593Smuzhiyunthe kernel source tree. 83*4882a593SmuzhiyunThe list of subdirectories which are visited depends upon the kernel 84*4882a593Smuzhiyunconfiguration. The top Makefile textually includes an arch Makefile 85*4882a593Smuzhiyunwith the name arch/$(ARCH)/Makefile. The arch Makefile supplies 86*4882a593Smuzhiyunarchitecture-specific information to the top Makefile. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunEach subdirectory has a kbuild Makefile which carries out the commands 89*4882a593Smuzhiyunpassed down from above. The kbuild Makefile uses information from the 90*4882a593Smuzhiyun.config file to construct various file lists used by kbuild to build 91*4882a593Smuzhiyunany built-in or modular targets. 92*4882a593Smuzhiyun 93*4882a593Smuzhiyunscripts/Makefile.* contains all the definitions/rules etc. that 94*4882a593Smuzhiyunare used to build the kernel based on the kbuild makefiles. 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun2 Who does what 98*4882a593Smuzhiyun=============== 99*4882a593Smuzhiyun 100*4882a593SmuzhiyunPeople have four different relationships with the kernel Makefiles. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun*Users* are people who build kernels. These people type commands such as 103*4882a593Smuzhiyun"make menuconfig" or "make". They usually do not read or edit 104*4882a593Smuzhiyunany kernel Makefiles (or any other source files). 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun*Normal developers* are people who work on features such as device 107*4882a593Smuzhiyundrivers, file systems, and network protocols. These people need to 108*4882a593Smuzhiyunmaintain the kbuild Makefiles for the subsystem they are 109*4882a593Smuzhiyunworking on. In order to do this effectively, they need some overall 110*4882a593Smuzhiyunknowledge about the kernel Makefiles, plus detailed knowledge about the 111*4882a593Smuzhiyunpublic interface for kbuild. 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun*Arch developers* are people who work on an entire architecture, such 114*4882a593Smuzhiyunas sparc or ia64. Arch developers need to know about the arch Makefile 115*4882a593Smuzhiyunas well as kbuild Makefiles. 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun*Kbuild developers* are people who work on the kernel build system itself. 118*4882a593SmuzhiyunThese people need to know about all aspects of the kernel Makefiles. 119*4882a593Smuzhiyun 120*4882a593SmuzhiyunThis document is aimed towards normal developers and arch developers. 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun3 The kbuild files 124*4882a593Smuzhiyun================== 125*4882a593Smuzhiyun 126*4882a593SmuzhiyunMost Makefiles within the kernel are kbuild Makefiles that use the 127*4882a593Smuzhiyunkbuild infrastructure. This chapter introduces the syntax used in the 128*4882a593Smuzhiyunkbuild makefiles. 129*4882a593SmuzhiyunThe preferred name for the kbuild files are 'Makefile' but 'Kbuild' can 130*4882a593Smuzhiyunbe used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild' 131*4882a593Smuzhiyunfile will be used. 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunSection 3.1 "Goal definitions" is a quick intro; further chapters provide 134*4882a593Smuzhiyunmore details, with real examples. 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun3.1 Goal definitions 137*4882a593Smuzhiyun-------------------- 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun Goal definitions are the main part (heart) of the kbuild Makefile. 140*4882a593Smuzhiyun These lines define the files to be built, any special compilation 141*4882a593Smuzhiyun options, and any subdirectories to be entered recursively. 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun The most simple kbuild makefile contains one line: 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun Example:: 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun obj-y += foo.o 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun This tells kbuild that there is one object in that directory, named 150*4882a593Smuzhiyun foo.o. foo.o will be built from foo.c or foo.S. 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun If foo.o shall be built as a module, the variable obj-m is used. 153*4882a593Smuzhiyun Therefore the following pattern is often used: 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun Example:: 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun obj-$(CONFIG_FOO) += foo.o 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun $(CONFIG_FOO) evaluates to either y (for built-in) or m (for module). 160*4882a593Smuzhiyun If CONFIG_FOO is neither y nor m, then the file will not be compiled 161*4882a593Smuzhiyun nor linked. 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun3.2 Built-in object goals - obj-y 164*4882a593Smuzhiyun--------------------------------- 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun The kbuild Makefile specifies object files for vmlinux 167*4882a593Smuzhiyun in the $(obj-y) lists. These lists depend on the kernel 168*4882a593Smuzhiyun configuration. 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun Kbuild compiles all the $(obj-y) files. It then calls 171*4882a593Smuzhiyun "$(AR) rcSTP" to merge these files into one built-in.a file. 172*4882a593Smuzhiyun This is a thin archive without a symbol table. It will be later 173*4882a593Smuzhiyun linked into vmlinux by scripts/link-vmlinux.sh 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun The order of files in $(obj-y) is significant. Duplicates in 176*4882a593Smuzhiyun the lists are allowed: the first instance will be linked into 177*4882a593Smuzhiyun built-in.a and succeeding instances will be ignored. 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun Link order is significant, because certain functions 180*4882a593Smuzhiyun (module_init() / __initcall) will be called during boot in the 181*4882a593Smuzhiyun order they appear. So keep in mind that changing the link 182*4882a593Smuzhiyun order may e.g. change the order in which your SCSI 183*4882a593Smuzhiyun controllers are detected, and thus your disks are renumbered. 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun Example:: 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun #drivers/isdn/i4l/Makefile 188*4882a593Smuzhiyun # Makefile for the kernel ISDN subsystem and device drivers. 189*4882a593Smuzhiyun # Each configuration option enables a list of files. 190*4882a593Smuzhiyun obj-$(CONFIG_ISDN_I4L) += isdn.o 191*4882a593Smuzhiyun obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun3.3 Loadable module goals - obj-m 194*4882a593Smuzhiyun--------------------------------- 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun $(obj-m) specifies object files which are built as loadable 197*4882a593Smuzhiyun kernel modules. 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun A module may be built from one source file or several source 200*4882a593Smuzhiyun files. In the case of one source file, the kbuild makefile 201*4882a593Smuzhiyun simply adds the file to $(obj-m). 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun Example:: 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun #drivers/isdn/i4l/Makefile 206*4882a593Smuzhiyun obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm' 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun If a kernel module is built from several source files, you specify 211*4882a593Smuzhiyun that you want to build a module in the same way as above; however, 212*4882a593Smuzhiyun kbuild needs to know which object files you want to build your 213*4882a593Smuzhiyun module from, so you have to tell it by setting a $(<module_name>-y) 214*4882a593Smuzhiyun variable. 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun Example:: 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun #drivers/isdn/i4l/Makefile 219*4882a593Smuzhiyun obj-$(CONFIG_ISDN_I4L) += isdn.o 220*4882a593Smuzhiyun isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun In this example, the module name will be isdn.o. Kbuild will 223*4882a593Smuzhiyun compile the objects listed in $(isdn-y) and then run 224*4882a593Smuzhiyun "$(LD) -r" on the list of these files to generate isdn.o. 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun Due to kbuild recognizing $(<module_name>-y) for composite objects, 227*4882a593Smuzhiyun you can use the value of a `CONFIG_` symbol to optionally include an 228*4882a593Smuzhiyun object file as part of a composite object. 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun Example:: 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun #fs/ext2/Makefile 233*4882a593Smuzhiyun obj-$(CONFIG_EXT2_FS) += ext2.o 234*4882a593Smuzhiyun ext2-y := balloc.o dir.o file.o ialloc.o inode.o ioctl.o \ 235*4882a593Smuzhiyun namei.o super.o symlink.o 236*4882a593Smuzhiyun ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o \ 237*4882a593Smuzhiyun xattr_trusted.o 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun In this example, xattr.o, xattr_user.o and xattr_trusted.o are only 240*4882a593Smuzhiyun part of the composite object ext2.o if $(CONFIG_EXT2_FS_XATTR) 241*4882a593Smuzhiyun evaluates to 'y'. 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun Note: Of course, when you are building objects into the kernel, 244*4882a593Smuzhiyun the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, 245*4882a593Smuzhiyun kbuild will build an ext2.o file for you out of the individual 246*4882a593Smuzhiyun parts and then link this into built-in.a, as you would expect. 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun3.4 Objects which export symbols 249*4882a593Smuzhiyun-------------------------------- 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun No special notation is required in the makefiles for 252*4882a593Smuzhiyun modules exporting symbols. 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun3.5 Library file goals - lib-y 255*4882a593Smuzhiyun------------------------------ 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun Objects listed with obj-* are used for modules, or 258*4882a593Smuzhiyun combined in a built-in.a for that specific directory. 259*4882a593Smuzhiyun There is also the possibility to list objects that will 260*4882a593Smuzhiyun be included in a library, lib.a. 261*4882a593Smuzhiyun All objects listed with lib-y are combined in a single 262*4882a593Smuzhiyun library for that directory. 263*4882a593Smuzhiyun Objects that are listed in obj-y and additionally listed in 264*4882a593Smuzhiyun lib-y will not be included in the library, since they will 265*4882a593Smuzhiyun be accessible anyway. 266*4882a593Smuzhiyun For consistency, objects listed in lib-m will be included in lib.a. 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun Note that the same kbuild makefile may list files to be built-in 269*4882a593Smuzhiyun and to be part of a library. Therefore the same directory 270*4882a593Smuzhiyun may contain both a built-in.a and a lib.a file. 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun Example:: 273*4882a593Smuzhiyun 274*4882a593Smuzhiyun #arch/x86/lib/Makefile 275*4882a593Smuzhiyun lib-y := delay.o 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun This will create a library lib.a based on delay.o. For kbuild to 278*4882a593Smuzhiyun actually recognize that there is a lib.a being built, the directory 279*4882a593Smuzhiyun shall be listed in libs-y. 280*4882a593Smuzhiyun 281*4882a593Smuzhiyun See also "6.4 List directories to visit when descending". 282*4882a593Smuzhiyun 283*4882a593Smuzhiyun Use of lib-y is normally restricted to `lib/` and `arch/*/lib`. 284*4882a593Smuzhiyun 285*4882a593Smuzhiyun3.6 Descending down in directories 286*4882a593Smuzhiyun---------------------------------- 287*4882a593Smuzhiyun 288*4882a593Smuzhiyun A Makefile is only responsible for building objects in its own 289*4882a593Smuzhiyun directory. Files in subdirectories should be taken care of by 290*4882a593Smuzhiyun Makefiles in these subdirs. The build system will automatically 291*4882a593Smuzhiyun invoke make recursively in subdirectories, provided you let it know of 292*4882a593Smuzhiyun them. 293*4882a593Smuzhiyun 294*4882a593Smuzhiyun To do so, obj-y and obj-m are used. 295*4882a593Smuzhiyun ext2 lives in a separate directory, and the Makefile present in fs/ 296*4882a593Smuzhiyun tells kbuild to descend down using the following assignment. 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun Example:: 299*4882a593Smuzhiyun 300*4882a593Smuzhiyun #fs/Makefile 301*4882a593Smuzhiyun obj-$(CONFIG_EXT2_FS) += ext2/ 302*4882a593Smuzhiyun 303*4882a593Smuzhiyun If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular) 304*4882a593Smuzhiyun the corresponding obj- variable will be set, and kbuild will descend 305*4882a593Smuzhiyun down in the ext2 directory. 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun Kbuild uses this information not only to decide that it needs to visit 308*4882a593Smuzhiyun the directory, but also to decide whether or not to link objects from 309*4882a593Smuzhiyun the directory into vmlinux. 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun When Kbuild descends into the directory with 'y', all built-in objects 312*4882a593Smuzhiyun from that directory are combined into the built-in.a, which will be 313*4882a593Smuzhiyun eventually linked into vmlinux. 314*4882a593Smuzhiyun 315*4882a593Smuzhiyun When Kbuild descends into the directory with 'm', in contrast, nothing 316*4882a593Smuzhiyun from that directory will be linked into vmlinux. If the Makefile in 317*4882a593Smuzhiyun that directory specifies obj-y, those objects will be left orphan. 318*4882a593Smuzhiyun It is very likely a bug of the Makefile or of dependencies in Kconfig. 319*4882a593Smuzhiyun 320*4882a593Smuzhiyun It is good practice to use a `CONFIG_` variable when assigning directory 321*4882a593Smuzhiyun names. This allows kbuild to totally skip the directory if the 322*4882a593Smuzhiyun corresponding `CONFIG_` option is neither 'y' nor 'm'. 323*4882a593Smuzhiyun 324*4882a593Smuzhiyun3.7 Compilation flags 325*4882a593Smuzhiyun--------------------- 326*4882a593Smuzhiyun 327*4882a593Smuzhiyun ccflags-y, asflags-y and ldflags-y 328*4882a593Smuzhiyun These three flags apply only to the kbuild makefile in which they 329*4882a593Smuzhiyun are assigned. They are used for all the normal cc, as and ld 330*4882a593Smuzhiyun invocations happening during a recursive build. 331*4882a593Smuzhiyun Note: Flags with the same behaviour were previously named: 332*4882a593Smuzhiyun EXTRA_CFLAGS, EXTRA_AFLAGS and EXTRA_LDFLAGS. 333*4882a593Smuzhiyun They are still supported but their usage is deprecated. 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun ccflags-y specifies options for compiling with $(CC). 336*4882a593Smuzhiyun 337*4882a593Smuzhiyun Example:: 338*4882a593Smuzhiyun 339*4882a593Smuzhiyun # drivers/acpi/acpica/Makefile 340*4882a593Smuzhiyun ccflags-y := -Os -D_LINUX -DBUILDING_ACPICA 341*4882a593Smuzhiyun ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT 342*4882a593Smuzhiyun 343*4882a593Smuzhiyun This variable is necessary because the top Makefile owns the 344*4882a593Smuzhiyun variable $(KBUILD_CFLAGS) and uses it for compilation flags for the 345*4882a593Smuzhiyun entire tree. 346*4882a593Smuzhiyun 347*4882a593Smuzhiyun asflags-y specifies assembler options. 348*4882a593Smuzhiyun 349*4882a593Smuzhiyun Example:: 350*4882a593Smuzhiyun 351*4882a593Smuzhiyun #arch/sparc/kernel/Makefile 352*4882a593Smuzhiyun asflags-y := -ansi 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun ldflags-y specifies options for linking with $(LD). 355*4882a593Smuzhiyun 356*4882a593Smuzhiyun Example:: 357*4882a593Smuzhiyun 358*4882a593Smuzhiyun #arch/cris/boot/compressed/Makefile 359*4882a593Smuzhiyun ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds 360*4882a593Smuzhiyun 361*4882a593Smuzhiyun subdir-ccflags-y, subdir-asflags-y 362*4882a593Smuzhiyun The two flags listed above are similar to ccflags-y and asflags-y. 363*4882a593Smuzhiyun The difference is that the subdir- variants have effect for the kbuild 364*4882a593Smuzhiyun file where they are present and all subdirectories. 365*4882a593Smuzhiyun Options specified using subdir-* are added to the commandline before 366*4882a593Smuzhiyun the options specified using the non-subdir variants. 367*4882a593Smuzhiyun 368*4882a593Smuzhiyun Example:: 369*4882a593Smuzhiyun 370*4882a593Smuzhiyun subdir-ccflags-y := -Werror 371*4882a593Smuzhiyun 372*4882a593Smuzhiyun ccflags-remove-y, asflags-remove-y 373*4882a593Smuzhiyun These flags are used to remove particular flags for the compiler, 374*4882a593Smuzhiyun assembler invocations. 375*4882a593Smuzhiyun 376*4882a593Smuzhiyun Example:: 377*4882a593Smuzhiyun 378*4882a593Smuzhiyun ccflags-remove-$(CONFIG_MCOUNT) += -pg 379*4882a593Smuzhiyun 380*4882a593Smuzhiyun CFLAGS_$@, AFLAGS_$@ 381*4882a593Smuzhiyun CFLAGS_$@ and AFLAGS_$@ only apply to commands in current 382*4882a593Smuzhiyun kbuild makefile. 383*4882a593Smuzhiyun 384*4882a593Smuzhiyun $(CFLAGS_$@) specifies per-file options for $(CC). The $@ 385*4882a593Smuzhiyun part has a literal value which specifies the file that it is for. 386*4882a593Smuzhiyun 387*4882a593Smuzhiyun CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@ 388*4882a593Smuzhiyun can re-add compiler flags that were removed by ccflags-remove-y. 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun Example:: 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun # drivers/scsi/Makefile 393*4882a593Smuzhiyun CFLAGS_aha152x.o = -DAHA152X_STAT -DAUTOCONF 394*4882a593Smuzhiyun CFLAGS_gdth.o = # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ \ 395*4882a593Smuzhiyun -DGDTH_STATISTICS 396*4882a593Smuzhiyun 397*4882a593Smuzhiyun These two lines specify compilation flags for aha152x.o and gdth.o. 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun $(AFLAGS_$@) is a similar feature for source files in assembly 400*4882a593Smuzhiyun languages. 401*4882a593Smuzhiyun 402*4882a593Smuzhiyun AFLAGS_$@ has the higher priority than asflags-remove-y; AFLAGS_$@ 403*4882a593Smuzhiyun can re-add assembler flags that were removed by asflags-remove-y. 404*4882a593Smuzhiyun 405*4882a593Smuzhiyun Example:: 406*4882a593Smuzhiyun 407*4882a593Smuzhiyun # arch/arm/kernel/Makefile 408*4882a593Smuzhiyun AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 409*4882a593Smuzhiyun AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312 410*4882a593Smuzhiyun AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun 413*4882a593Smuzhiyun3.9 Dependency tracking 414*4882a593Smuzhiyun----------------------- 415*4882a593Smuzhiyun 416*4882a593Smuzhiyun Kbuild tracks dependencies on the following: 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun 1) All prerequisite files (both `*.c` and `*.h`) 419*4882a593Smuzhiyun 2) `CONFIG_` options used in all prerequisite files 420*4882a593Smuzhiyun 3) Command-line used to compile target 421*4882a593Smuzhiyun 422*4882a593Smuzhiyun Thus, if you change an option to $(CC) all affected files will 423*4882a593Smuzhiyun be re-compiled. 424*4882a593Smuzhiyun 425*4882a593Smuzhiyun3.10 Special Rules 426*4882a593Smuzhiyun------------------ 427*4882a593Smuzhiyun 428*4882a593Smuzhiyun Special rules are used when the kbuild infrastructure does 429*4882a593Smuzhiyun not provide the required support. A typical example is 430*4882a593Smuzhiyun header files generated during the build process. 431*4882a593Smuzhiyun Another example are the architecture-specific Makefiles which 432*4882a593Smuzhiyun need special rules to prepare boot images etc. 433*4882a593Smuzhiyun 434*4882a593Smuzhiyun Special rules are written as normal Make rules. 435*4882a593Smuzhiyun Kbuild is not executing in the directory where the Makefile is 436*4882a593Smuzhiyun located, so all special rules shall provide a relative 437*4882a593Smuzhiyun path to prerequisite files and target files. 438*4882a593Smuzhiyun 439*4882a593Smuzhiyun Two variables are used when defining special rules: 440*4882a593Smuzhiyun 441*4882a593Smuzhiyun $(src) 442*4882a593Smuzhiyun $(src) is a relative path which points to the directory 443*4882a593Smuzhiyun where the Makefile is located. Always use $(src) when 444*4882a593Smuzhiyun referring to files located in the src tree. 445*4882a593Smuzhiyun 446*4882a593Smuzhiyun $(obj) 447*4882a593Smuzhiyun $(obj) is a relative path which points to the directory 448*4882a593Smuzhiyun where the target is saved. Always use $(obj) when 449*4882a593Smuzhiyun referring to generated files. 450*4882a593Smuzhiyun 451*4882a593Smuzhiyun Example:: 452*4882a593Smuzhiyun 453*4882a593Smuzhiyun #drivers/scsi/Makefile 454*4882a593Smuzhiyun $(obj)/53c8xx_d.h: $(src)/53c7,8xx.scr $(src)/script_asm.pl 455*4882a593Smuzhiyun $(CPP) -DCHIP=810 - < $< | ... $(src)/script_asm.pl 456*4882a593Smuzhiyun 457*4882a593Smuzhiyun This is a special rule, following the normal syntax 458*4882a593Smuzhiyun required by make. 459*4882a593Smuzhiyun 460*4882a593Smuzhiyun The target file depends on two prerequisite files. References 461*4882a593Smuzhiyun to the target file are prefixed with $(obj), references 462*4882a593Smuzhiyun to prerequisites are referenced with $(src) (because they are not 463*4882a593Smuzhiyun generated files). 464*4882a593Smuzhiyun 465*4882a593Smuzhiyun $(kecho) 466*4882a593Smuzhiyun echoing information to user in a rule is often a good practice 467*4882a593Smuzhiyun but when execution "make -s" one does not expect to see any output 468*4882a593Smuzhiyun except for warnings/errors. 469*4882a593Smuzhiyun To support this kbuild defines $(kecho) which will echo out the 470*4882a593Smuzhiyun text following $(kecho) to stdout except if "make -s" is used. 471*4882a593Smuzhiyun 472*4882a593Smuzhiyun Example:: 473*4882a593Smuzhiyun 474*4882a593Smuzhiyun #arch/blackfin/boot/Makefile 475*4882a593Smuzhiyun $(obj)/vmImage: $(obj)/vmlinux.gz 476*4882a593Smuzhiyun $(call if_changed,uimage) 477*4882a593Smuzhiyun @$(kecho) 'Kernel: $@ is ready' 478*4882a593Smuzhiyun 479*4882a593Smuzhiyun 480*4882a593Smuzhiyun3.11 $(CC) support functions 481*4882a593Smuzhiyun---------------------------- 482*4882a593Smuzhiyun 483*4882a593Smuzhiyun The kernel may be built with several different versions of 484*4882a593Smuzhiyun $(CC), each supporting a unique set of features and options. 485*4882a593Smuzhiyun kbuild provides basic support to check for valid options for $(CC). 486*4882a593Smuzhiyun $(CC) is usually the gcc compiler, but other alternatives are 487*4882a593Smuzhiyun available. 488*4882a593Smuzhiyun 489*4882a593Smuzhiyun as-option 490*4882a593Smuzhiyun as-option is used to check if $(CC) -- when used to compile 491*4882a593Smuzhiyun assembler (`*.S`) files -- supports the given option. An optional 492*4882a593Smuzhiyun second option may be specified if the first option is not supported. 493*4882a593Smuzhiyun 494*4882a593Smuzhiyun Example:: 495*4882a593Smuzhiyun 496*4882a593Smuzhiyun #arch/sh/Makefile 497*4882a593Smuzhiyun cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) 498*4882a593Smuzhiyun 499*4882a593Smuzhiyun In the above example, cflags-y will be assigned the option 500*4882a593Smuzhiyun -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). 501*4882a593Smuzhiyun The second argument is optional, and if supplied will be used 502*4882a593Smuzhiyun if first argument is not supported. 503*4882a593Smuzhiyun 504*4882a593Smuzhiyun as-instr 505*4882a593Smuzhiyun as-instr checks if the assembler reports a specific instruction 506*4882a593Smuzhiyun and then outputs either option1 or option2 507*4882a593Smuzhiyun C escapes are supported in the test instruction 508*4882a593Smuzhiyun Note: as-instr-option uses KBUILD_AFLAGS for assembler options 509*4882a593Smuzhiyun 510*4882a593Smuzhiyun cc-option 511*4882a593Smuzhiyun cc-option is used to check if $(CC) supports a given option, and if 512*4882a593Smuzhiyun not supported to use an optional second option. 513*4882a593Smuzhiyun 514*4882a593Smuzhiyun Example:: 515*4882a593Smuzhiyun 516*4882a593Smuzhiyun #arch/x86/Makefile 517*4882a593Smuzhiyun cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) 518*4882a593Smuzhiyun 519*4882a593Smuzhiyun In the above example, cflags-y will be assigned the option 520*4882a593Smuzhiyun -march=pentium-mmx if supported by $(CC), otherwise -march=i586. 521*4882a593Smuzhiyun The second argument to cc-option is optional, and if omitted, 522*4882a593Smuzhiyun cflags-y will be assigned no value if first option is not supported. 523*4882a593Smuzhiyun Note: cc-option uses KBUILD_CFLAGS for $(CC) options 524*4882a593Smuzhiyun 525*4882a593Smuzhiyun cc-option-yn 526*4882a593Smuzhiyun cc-option-yn is used to check if gcc supports a given option 527*4882a593Smuzhiyun and return 'y' if supported, otherwise 'n'. 528*4882a593Smuzhiyun 529*4882a593Smuzhiyun Example:: 530*4882a593Smuzhiyun 531*4882a593Smuzhiyun #arch/ppc/Makefile 532*4882a593Smuzhiyun biarch := $(call cc-option-yn, -m32) 533*4882a593Smuzhiyun aflags-$(biarch) += -a32 534*4882a593Smuzhiyun cflags-$(biarch) += -m32 535*4882a593Smuzhiyun 536*4882a593Smuzhiyun In the above example, $(biarch) is set to y if $(CC) supports the -m32 537*4882a593Smuzhiyun option. When $(biarch) equals 'y', the expanded variables $(aflags-y) 538*4882a593Smuzhiyun and $(cflags-y) will be assigned the values -a32 and -m32, 539*4882a593Smuzhiyun respectively. 540*4882a593Smuzhiyun Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options 541*4882a593Smuzhiyun 542*4882a593Smuzhiyun cc-disable-warning 543*4882a593Smuzhiyun cc-disable-warning checks if gcc supports a given warning and returns 544*4882a593Smuzhiyun the commandline switch to disable it. This special function is needed, 545*4882a593Smuzhiyun because gcc 4.4 and later accept any unknown -Wno-* option and only 546*4882a593Smuzhiyun warn about it if there is another warning in the source file. 547*4882a593Smuzhiyun 548*4882a593Smuzhiyun Example:: 549*4882a593Smuzhiyun 550*4882a593Smuzhiyun KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 551*4882a593Smuzhiyun 552*4882a593Smuzhiyun In the above example, -Wno-unused-but-set-variable will be added to 553*4882a593Smuzhiyun KBUILD_CFLAGS only if gcc really accepts it. 554*4882a593Smuzhiyun 555*4882a593Smuzhiyun cc-ifversion 556*4882a593Smuzhiyun cc-ifversion tests the version of $(CC) and equals the fourth parameter 557*4882a593Smuzhiyun if version expression is true, or the fifth (if given) if the version 558*4882a593Smuzhiyun expression is false. 559*4882a593Smuzhiyun 560*4882a593Smuzhiyun Example:: 561*4882a593Smuzhiyun 562*4882a593Smuzhiyun #fs/reiserfs/Makefile 563*4882a593Smuzhiyun ccflags-y := $(call cc-ifversion, -lt, 0402, -O1) 564*4882a593Smuzhiyun 565*4882a593Smuzhiyun In this example, ccflags-y will be assigned the value -O1 if the 566*4882a593Smuzhiyun $(CC) version is less than 4.2. 567*4882a593Smuzhiyun cc-ifversion takes all the shell operators: 568*4882a593Smuzhiyun -eq, -ne, -lt, -le, -gt, and -ge 569*4882a593Smuzhiyun The third parameter may be a text as in this example, but it may also 570*4882a593Smuzhiyun be an expanded variable or a macro. 571*4882a593Smuzhiyun 572*4882a593Smuzhiyun cc-cross-prefix 573*4882a593Smuzhiyun cc-cross-prefix is used to check if there exists a $(CC) in path with 574*4882a593Smuzhiyun one of the listed prefixes. The first prefix where there exist a 575*4882a593Smuzhiyun prefix$(CC) in the PATH is returned - and if no prefix$(CC) is found 576*4882a593Smuzhiyun then nothing is returned. 577*4882a593Smuzhiyun Additional prefixes are separated by a single space in the 578*4882a593Smuzhiyun call of cc-cross-prefix. 579*4882a593Smuzhiyun This functionality is useful for architecture Makefiles that try 580*4882a593Smuzhiyun to set CROSS_COMPILE to well-known values but may have several 581*4882a593Smuzhiyun values to select between. 582*4882a593Smuzhiyun It is recommended only to try to set CROSS_COMPILE if it is a cross 583*4882a593Smuzhiyun build (host arch is different from target arch). And if CROSS_COMPILE 584*4882a593Smuzhiyun is already set then leave it with the old value. 585*4882a593Smuzhiyun 586*4882a593Smuzhiyun Example:: 587*4882a593Smuzhiyun 588*4882a593Smuzhiyun #arch/m68k/Makefile 589*4882a593Smuzhiyun ifneq ($(SUBARCH),$(ARCH)) 590*4882a593Smuzhiyun ifeq ($(CROSS_COMPILE),) 591*4882a593Smuzhiyun CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu-) 592*4882a593Smuzhiyun endif 593*4882a593Smuzhiyun endif 594*4882a593Smuzhiyun 595*4882a593Smuzhiyun3.12 $(LD) support functions 596*4882a593Smuzhiyun---------------------------- 597*4882a593Smuzhiyun 598*4882a593Smuzhiyun ld-option 599*4882a593Smuzhiyun ld-option is used to check if $(LD) supports the supplied option. 600*4882a593Smuzhiyun ld-option takes two options as arguments. 601*4882a593Smuzhiyun The second argument is an optional option that can be used if the 602*4882a593Smuzhiyun first option is not supported by $(LD). 603*4882a593Smuzhiyun 604*4882a593Smuzhiyun Example:: 605*4882a593Smuzhiyun 606*4882a593Smuzhiyun #Makefile 607*4882a593Smuzhiyun LDFLAGS_vmlinux += $(call ld-option, -X) 608*4882a593Smuzhiyun 609*4882a593Smuzhiyun3.13 Script invocation 610*4882a593Smuzhiyun---------------------- 611*4882a593Smuzhiyun 612*4882a593Smuzhiyun Make rules may invoke scripts to build the kernel. The rules shall 613*4882a593Smuzhiyun always provide the appropriate interpreter to execute the script. They 614*4882a593Smuzhiyun shall not rely on the execute bits being set, and shall not invoke the 615*4882a593Smuzhiyun script directly. For the convenience of manual script invocation, such 616*4882a593Smuzhiyun as invoking ./scripts/checkpatch.pl, it is recommended to set execute 617*4882a593Smuzhiyun bits on the scripts nonetheless. 618*4882a593Smuzhiyun 619*4882a593Smuzhiyun Kbuild provides variables $(CONFIG_SHELL), $(AWK), $(PERL), 620*4882a593Smuzhiyun $(PYTHON) and $(PYTHON3) to refer to interpreters for the respective 621*4882a593Smuzhiyun scripts. 622*4882a593Smuzhiyun 623*4882a593Smuzhiyun Example:: 624*4882a593Smuzhiyun 625*4882a593Smuzhiyun #Makefile 626*4882a593Smuzhiyun cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 627*4882a593Smuzhiyun $(KERNELRELEASE) 628*4882a593Smuzhiyun 629*4882a593Smuzhiyun4 Host Program support 630*4882a593Smuzhiyun====================== 631*4882a593Smuzhiyun 632*4882a593SmuzhiyunKbuild supports building executables on the host for use during the 633*4882a593Smuzhiyuncompilation stage. 634*4882a593SmuzhiyunTwo steps are required in order to use a host executable. 635*4882a593Smuzhiyun 636*4882a593SmuzhiyunThe first step is to tell kbuild that a host program exists. This is 637*4882a593Smuzhiyundone utilising the variable "hostprogs". 638*4882a593Smuzhiyun 639*4882a593SmuzhiyunThe second step is to add an explicit dependency to the executable. 640*4882a593SmuzhiyunThis can be done in two ways. Either add the dependency in a rule, 641*4882a593Smuzhiyunor utilise the variable "always-y". 642*4882a593SmuzhiyunBoth possibilities are described in the following. 643*4882a593Smuzhiyun 644*4882a593Smuzhiyun4.1 Simple Host Program 645*4882a593Smuzhiyun----------------------- 646*4882a593Smuzhiyun 647*4882a593Smuzhiyun In some cases there is a need to compile and run a program on the 648*4882a593Smuzhiyun computer where the build is running. 649*4882a593Smuzhiyun The following line tells kbuild that the program bin2hex shall be 650*4882a593Smuzhiyun built on the build host. 651*4882a593Smuzhiyun 652*4882a593Smuzhiyun Example:: 653*4882a593Smuzhiyun 654*4882a593Smuzhiyun hostprogs := bin2hex 655*4882a593Smuzhiyun 656*4882a593Smuzhiyun Kbuild assumes in the above example that bin2hex is made from a single 657*4882a593Smuzhiyun c-source file named bin2hex.c located in the same directory as 658*4882a593Smuzhiyun the Makefile. 659*4882a593Smuzhiyun 660*4882a593Smuzhiyun4.2 Composite Host Programs 661*4882a593Smuzhiyun--------------------------- 662*4882a593Smuzhiyun 663*4882a593Smuzhiyun Host programs can be made up based on composite objects. 664*4882a593Smuzhiyun The syntax used to define composite objects for host programs is 665*4882a593Smuzhiyun similar to the syntax used for kernel objects. 666*4882a593Smuzhiyun $(<executable>-objs) lists all objects used to link the final 667*4882a593Smuzhiyun executable. 668*4882a593Smuzhiyun 669*4882a593Smuzhiyun Example:: 670*4882a593Smuzhiyun 671*4882a593Smuzhiyun #scripts/lxdialog/Makefile 672*4882a593Smuzhiyun hostprogs := lxdialog 673*4882a593Smuzhiyun lxdialog-objs := checklist.o lxdialog.o 674*4882a593Smuzhiyun 675*4882a593Smuzhiyun Objects with extension .o are compiled from the corresponding .c 676*4882a593Smuzhiyun files. In the above example, checklist.c is compiled to checklist.o 677*4882a593Smuzhiyun and lxdialog.c is compiled to lxdialog.o. 678*4882a593Smuzhiyun 679*4882a593Smuzhiyun Finally, the two .o files are linked to the executable, lxdialog. 680*4882a593Smuzhiyun Note: The syntax <executable>-y is not permitted for host-programs. 681*4882a593Smuzhiyun 682*4882a593Smuzhiyun4.3 Using C++ for host programs 683*4882a593Smuzhiyun------------------------------- 684*4882a593Smuzhiyun 685*4882a593Smuzhiyun kbuild offers support for host programs written in C++. This was 686*4882a593Smuzhiyun introduced solely to support kconfig, and is not recommended 687*4882a593Smuzhiyun for general use. 688*4882a593Smuzhiyun 689*4882a593Smuzhiyun Example:: 690*4882a593Smuzhiyun 691*4882a593Smuzhiyun #scripts/kconfig/Makefile 692*4882a593Smuzhiyun hostprogs := qconf 693*4882a593Smuzhiyun qconf-cxxobjs := qconf.o 694*4882a593Smuzhiyun 695*4882a593Smuzhiyun In the example above the executable is composed of the C++ file 696*4882a593Smuzhiyun qconf.cc - identified by $(qconf-cxxobjs). 697*4882a593Smuzhiyun 698*4882a593Smuzhiyun If qconf is composed of a mixture of .c and .cc files, then an 699*4882a593Smuzhiyun additional line can be used to identify this. 700*4882a593Smuzhiyun 701*4882a593Smuzhiyun Example:: 702*4882a593Smuzhiyun 703*4882a593Smuzhiyun #scripts/kconfig/Makefile 704*4882a593Smuzhiyun hostprogs := qconf 705*4882a593Smuzhiyun qconf-cxxobjs := qconf.o 706*4882a593Smuzhiyun qconf-objs := check.o 707*4882a593Smuzhiyun 708*4882a593Smuzhiyun4.4 Controlling compiler options for host programs 709*4882a593Smuzhiyun-------------------------------------------------- 710*4882a593Smuzhiyun 711*4882a593Smuzhiyun When compiling host programs, it is possible to set specific flags. 712*4882a593Smuzhiyun The programs will always be compiled utilising $(HOSTCC) passed 713*4882a593Smuzhiyun the options specified in $(KBUILD_HOSTCFLAGS). 714*4882a593Smuzhiyun To set flags that will take effect for all host programs created 715*4882a593Smuzhiyun in that Makefile, use the variable HOST_EXTRACFLAGS. 716*4882a593Smuzhiyun 717*4882a593Smuzhiyun Example:: 718*4882a593Smuzhiyun 719*4882a593Smuzhiyun #scripts/lxdialog/Makefile 720*4882a593Smuzhiyun HOST_EXTRACFLAGS += -I/usr/include/ncurses 721*4882a593Smuzhiyun 722*4882a593Smuzhiyun To set specific flags for a single file the following construction 723*4882a593Smuzhiyun is used: 724*4882a593Smuzhiyun 725*4882a593Smuzhiyun Example:: 726*4882a593Smuzhiyun 727*4882a593Smuzhiyun #arch/ppc64/boot/Makefile 728*4882a593Smuzhiyun HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) 729*4882a593Smuzhiyun 730*4882a593Smuzhiyun It is also possible to specify additional options to the linker. 731*4882a593Smuzhiyun 732*4882a593Smuzhiyun Example:: 733*4882a593Smuzhiyun 734*4882a593Smuzhiyun #scripts/kconfig/Makefile 735*4882a593Smuzhiyun HOSTLDLIBS_qconf := -L$(QTDIR)/lib 736*4882a593Smuzhiyun 737*4882a593Smuzhiyun When linking qconf, it will be passed the extra option 738*4882a593Smuzhiyun "-L$(QTDIR)/lib". 739*4882a593Smuzhiyun 740*4882a593Smuzhiyun4.5 When host programs are actually built 741*4882a593Smuzhiyun----------------------------------------- 742*4882a593Smuzhiyun 743*4882a593Smuzhiyun Kbuild will only build host-programs when they are referenced 744*4882a593Smuzhiyun as a prerequisite. 745*4882a593Smuzhiyun This is possible in two ways: 746*4882a593Smuzhiyun 747*4882a593Smuzhiyun (1) List the prerequisite explicitly in a special rule. 748*4882a593Smuzhiyun 749*4882a593Smuzhiyun Example:: 750*4882a593Smuzhiyun 751*4882a593Smuzhiyun #drivers/pci/Makefile 752*4882a593Smuzhiyun hostprogs := gen-devlist 753*4882a593Smuzhiyun $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist 754*4882a593Smuzhiyun ( cd $(obj); ./gen-devlist ) < $< 755*4882a593Smuzhiyun 756*4882a593Smuzhiyun The target $(obj)/devlist.h will not be built before 757*4882a593Smuzhiyun $(obj)/gen-devlist is updated. Note that references to 758*4882a593Smuzhiyun the host programs in special rules must be prefixed with $(obj). 759*4882a593Smuzhiyun 760*4882a593Smuzhiyun (2) Use always-y 761*4882a593Smuzhiyun 762*4882a593Smuzhiyun When there is no suitable special rule, and the host program 763*4882a593Smuzhiyun shall be built when a makefile is entered, the always-y 764*4882a593Smuzhiyun variable shall be used. 765*4882a593Smuzhiyun 766*4882a593Smuzhiyun Example:: 767*4882a593Smuzhiyun 768*4882a593Smuzhiyun #scripts/lxdialog/Makefile 769*4882a593Smuzhiyun hostprogs := lxdialog 770*4882a593Smuzhiyun always-y := $(hostprogs) 771*4882a593Smuzhiyun 772*4882a593Smuzhiyun Kbuild provides the following shorthand for this: 773*4882a593Smuzhiyun 774*4882a593Smuzhiyun hostprogs-always-y := lxdialog 775*4882a593Smuzhiyun 776*4882a593Smuzhiyun This will tell kbuild to build lxdialog even if not referenced in 777*4882a593Smuzhiyun any rule. 778*4882a593Smuzhiyun 779*4882a593Smuzhiyun5 Userspace Program support 780*4882a593Smuzhiyun=========================== 781*4882a593Smuzhiyun 782*4882a593SmuzhiyunJust like host programs, Kbuild also supports building userspace executables 783*4882a593Smuzhiyunfor the target architecture (i.e. the same architecture as you are building 784*4882a593Smuzhiyunthe kernel for). 785*4882a593Smuzhiyun 786*4882a593SmuzhiyunThe syntax is quite similar. The difference is to use "userprogs" instead of 787*4882a593Smuzhiyun"hostprogs". 788*4882a593Smuzhiyun 789*4882a593Smuzhiyun5.1 Simple Userspace Program 790*4882a593Smuzhiyun---------------------------- 791*4882a593Smuzhiyun 792*4882a593Smuzhiyun The following line tells kbuild that the program bpf-direct shall be 793*4882a593Smuzhiyun built for the target architecture. 794*4882a593Smuzhiyun 795*4882a593Smuzhiyun Example:: 796*4882a593Smuzhiyun 797*4882a593Smuzhiyun userprogs := bpf-direct 798*4882a593Smuzhiyun 799*4882a593Smuzhiyun Kbuild assumes in the above example that bpf-direct is made from a 800*4882a593Smuzhiyun single C source file named bpf-direct.c located in the same directory 801*4882a593Smuzhiyun as the Makefile. 802*4882a593Smuzhiyun 803*4882a593Smuzhiyun5.2 Composite Userspace Programs 804*4882a593Smuzhiyun-------------------------------- 805*4882a593Smuzhiyun 806*4882a593Smuzhiyun Userspace programs can be made up based on composite objects. 807*4882a593Smuzhiyun The syntax used to define composite objects for userspace programs is 808*4882a593Smuzhiyun similar to the syntax used for kernel objects. 809*4882a593Smuzhiyun $(<executable>-objs) lists all objects used to link the final 810*4882a593Smuzhiyun executable. 811*4882a593Smuzhiyun 812*4882a593Smuzhiyun Example:: 813*4882a593Smuzhiyun 814*4882a593Smuzhiyun #samples/seccomp/Makefile 815*4882a593Smuzhiyun userprogs := bpf-fancy 816*4882a593Smuzhiyun bpf-fancy-objs := bpf-fancy.o bpf-helper.o 817*4882a593Smuzhiyun 818*4882a593Smuzhiyun Objects with extension .o are compiled from the corresponding .c 819*4882a593Smuzhiyun files. In the above example, bpf-fancy.c is compiled to bpf-fancy.o 820*4882a593Smuzhiyun and bpf-helper.c is compiled to bpf-helper.o. 821*4882a593Smuzhiyun 822*4882a593Smuzhiyun Finally, the two .o files are linked to the executable, bpf-fancy. 823*4882a593Smuzhiyun Note: The syntax <executable>-y is not permitted for userspace programs. 824*4882a593Smuzhiyun 825*4882a593Smuzhiyun5.3 Controlling compiler options for userspace programs 826*4882a593Smuzhiyun------------------------------------------------------- 827*4882a593Smuzhiyun 828*4882a593Smuzhiyun When compiling userspace programs, it is possible to set specific flags. 829*4882a593Smuzhiyun The programs will always be compiled utilising $(CC) passed 830*4882a593Smuzhiyun the options specified in $(KBUILD_USERCFLAGS). 831*4882a593Smuzhiyun To set flags that will take effect for all userspace programs created 832*4882a593Smuzhiyun in that Makefile, use the variable userccflags. 833*4882a593Smuzhiyun 834*4882a593Smuzhiyun Example:: 835*4882a593Smuzhiyun 836*4882a593Smuzhiyun # samples/seccomp/Makefile 837*4882a593Smuzhiyun userccflags += -I usr/include 838*4882a593Smuzhiyun 839*4882a593Smuzhiyun To set specific flags for a single file the following construction 840*4882a593Smuzhiyun is used: 841*4882a593Smuzhiyun 842*4882a593Smuzhiyun Example:: 843*4882a593Smuzhiyun 844*4882a593Smuzhiyun bpf-helper-userccflags += -I user/include 845*4882a593Smuzhiyun 846*4882a593Smuzhiyun It is also possible to specify additional options to the linker. 847*4882a593Smuzhiyun 848*4882a593Smuzhiyun Example:: 849*4882a593Smuzhiyun 850*4882a593Smuzhiyun # net/bpfilter/Makefile 851*4882a593Smuzhiyun bpfilter_umh-userldflags += -static 852*4882a593Smuzhiyun 853*4882a593Smuzhiyun When linking bpfilter_umh, it will be passed the extra option -static. 854*4882a593Smuzhiyun 855*4882a593Smuzhiyun From command line, :ref:`USERCFLAGS and USERLDFLAGS <userkbuildflags>` will also be used. 856*4882a593Smuzhiyun 857*4882a593Smuzhiyun5.4 When userspace programs are actually built 858*4882a593Smuzhiyun---------------------------------------------- 859*4882a593Smuzhiyun 860*4882a593Smuzhiyun Kbuild builds userspace programs only when told to do so. 861*4882a593Smuzhiyun There are two ways to do this. 862*4882a593Smuzhiyun 863*4882a593Smuzhiyun (1) Add it as the prerequisite of another file 864*4882a593Smuzhiyun 865*4882a593Smuzhiyun Example:: 866*4882a593Smuzhiyun 867*4882a593Smuzhiyun #net/bpfilter/Makefile 868*4882a593Smuzhiyun userprogs := bpfilter_umh 869*4882a593Smuzhiyun $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 870*4882a593Smuzhiyun 871*4882a593Smuzhiyun $(obj)/bpfilter_umh is built before $(obj)/bpfilter_umh_blob.o 872*4882a593Smuzhiyun 873*4882a593Smuzhiyun (2) Use always-y 874*4882a593Smuzhiyun 875*4882a593Smuzhiyun Example:: 876*4882a593Smuzhiyun 877*4882a593Smuzhiyun userprogs := binderfs_example 878*4882a593Smuzhiyun always-y := $(userprogs) 879*4882a593Smuzhiyun 880*4882a593Smuzhiyun Kbuild provides the following shorthand for this: 881*4882a593Smuzhiyun 882*4882a593Smuzhiyun userprogs-always-y := binderfs_example 883*4882a593Smuzhiyun 884*4882a593Smuzhiyun This will tell Kbuild to build binderfs_example when it visits this 885*4882a593Smuzhiyun Makefile. 886*4882a593Smuzhiyun 887*4882a593Smuzhiyun6 Kbuild clean infrastructure 888*4882a593Smuzhiyun============================= 889*4882a593Smuzhiyun 890*4882a593Smuzhiyun"make clean" deletes most generated files in the obj tree where the kernel 891*4882a593Smuzhiyunis compiled. This includes generated files such as host programs. 892*4882a593SmuzhiyunKbuild knows targets listed in $(hostprogs), $(always-y), $(always-m), 893*4882a593Smuzhiyun$(always-), $(extra-y), $(extra-) and $(targets). They are all deleted 894*4882a593Smuzhiyunduring "make clean". Files matching the patterns "*.[oas]", "*.ko", plus 895*4882a593Smuzhiyunsome additional files generated by kbuild are deleted all over the kernel 896*4882a593Smuzhiyunsource tree when "make clean" is executed. 897*4882a593Smuzhiyun 898*4882a593SmuzhiyunAdditional files or directories can be specified in kbuild makefiles by use of 899*4882a593Smuzhiyun$(clean-files). 900*4882a593Smuzhiyun 901*4882a593Smuzhiyun Example:: 902*4882a593Smuzhiyun 903*4882a593Smuzhiyun #lib/Makefile 904*4882a593Smuzhiyun clean-files := crc32table.h 905*4882a593Smuzhiyun 906*4882a593SmuzhiyunWhen executing "make clean", the file "crc32table.h" will be deleted. 907*4882a593SmuzhiyunKbuild will assume files to be in the same relative directory as the 908*4882a593SmuzhiyunMakefile, except if prefixed with $(objtree). 909*4882a593Smuzhiyun 910*4882a593SmuzhiyunTo exclude certain files or directories from make clean, use the 911*4882a593Smuzhiyun$(no-clean-files) variable. 912*4882a593Smuzhiyun 913*4882a593SmuzhiyunUsually kbuild descends down in subdirectories due to "obj-* := dir/", 914*4882a593Smuzhiyunbut in the architecture makefiles where the kbuild infrastructure 915*4882a593Smuzhiyunis not sufficient this sometimes needs to be explicit. 916*4882a593Smuzhiyun 917*4882a593Smuzhiyun Example:: 918*4882a593Smuzhiyun 919*4882a593Smuzhiyun #arch/x86/boot/Makefile 920*4882a593Smuzhiyun subdir- := compressed 921*4882a593Smuzhiyun 922*4882a593SmuzhiyunThe above assignment instructs kbuild to descend down in the 923*4882a593Smuzhiyundirectory compressed/ when "make clean" is executed. 924*4882a593Smuzhiyun 925*4882a593SmuzhiyunTo support the clean infrastructure in the Makefiles that build the 926*4882a593Smuzhiyunfinal bootimage there is an optional target named archclean: 927*4882a593Smuzhiyun 928*4882a593Smuzhiyun Example:: 929*4882a593Smuzhiyun 930*4882a593Smuzhiyun #arch/x86/Makefile 931*4882a593Smuzhiyun archclean: 932*4882a593Smuzhiyun $(Q)$(MAKE) $(clean)=arch/x86/boot 933*4882a593Smuzhiyun 934*4882a593SmuzhiyunWhen "make clean" is executed, make will descend down in arch/x86/boot, 935*4882a593Smuzhiyunand clean as usual. The Makefile located in arch/x86/boot/ may use 936*4882a593Smuzhiyunthe subdir- trick to descend further down. 937*4882a593Smuzhiyun 938*4882a593SmuzhiyunNote 1: arch/$(ARCH)/Makefile cannot use "subdir-", because that file is 939*4882a593Smuzhiyunincluded in the top level makefile, and the kbuild infrastructure 940*4882a593Smuzhiyunis not operational at that point. 941*4882a593Smuzhiyun 942*4882a593SmuzhiyunNote 2: All directories listed in core-y, libs-y, drivers-y and net-y will 943*4882a593Smuzhiyunbe visited during "make clean". 944*4882a593Smuzhiyun 945*4882a593Smuzhiyun7 Architecture Makefiles 946*4882a593Smuzhiyun======================== 947*4882a593Smuzhiyun 948*4882a593SmuzhiyunThe top level Makefile sets up the environment and does the preparation, 949*4882a593Smuzhiyunbefore starting to descend down in the individual directories. 950*4882a593SmuzhiyunThe top level makefile contains the generic part, whereas 951*4882a593Smuzhiyunarch/$(ARCH)/Makefile contains what is required to set up kbuild 952*4882a593Smuzhiyunfor said architecture. 953*4882a593SmuzhiyunTo do so, arch/$(ARCH)/Makefile sets up a number of variables and defines 954*4882a593Smuzhiyuna few targets. 955*4882a593Smuzhiyun 956*4882a593SmuzhiyunWhen kbuild executes, the following steps are followed (roughly): 957*4882a593Smuzhiyun 958*4882a593Smuzhiyun1) Configuration of the kernel => produce .config 959*4882a593Smuzhiyun2) Store kernel version in include/linux/version.h 960*4882a593Smuzhiyun3) Updating all other prerequisites to the target prepare: 961*4882a593Smuzhiyun - Additional prerequisites are specified in arch/$(ARCH)/Makefile 962*4882a593Smuzhiyun4) Recursively descend down in all directories listed in 963*4882a593Smuzhiyun init-* core* drivers-* net-* libs-* and build all targets. 964*4882a593Smuzhiyun - The values of the above variables are expanded in arch/$(ARCH)/Makefile. 965*4882a593Smuzhiyun5) All object files are then linked and the resulting file vmlinux is 966*4882a593Smuzhiyun located at the root of the obj tree. 967*4882a593Smuzhiyun The very first objects linked are listed in head-y, assigned by 968*4882a593Smuzhiyun arch/$(ARCH)/Makefile. 969*4882a593Smuzhiyun6) Finally, the architecture-specific part does any required post processing 970*4882a593Smuzhiyun and builds the final bootimage. 971*4882a593Smuzhiyun - This includes building boot records 972*4882a593Smuzhiyun - Preparing initrd images and the like 973*4882a593Smuzhiyun 974*4882a593Smuzhiyun 975*4882a593Smuzhiyun7.1 Set variables to tweak the build to the architecture 976*4882a593Smuzhiyun-------------------------------------------------------- 977*4882a593Smuzhiyun 978*4882a593Smuzhiyun KBUILD_LDFLAGS 979*4882a593Smuzhiyun Generic $(LD) options 980*4882a593Smuzhiyun 981*4882a593Smuzhiyun Flags used for all invocations of the linker. 982*4882a593Smuzhiyun Often specifying the emulation is sufficient. 983*4882a593Smuzhiyun 984*4882a593Smuzhiyun Example:: 985*4882a593Smuzhiyun 986*4882a593Smuzhiyun #arch/s390/Makefile 987*4882a593Smuzhiyun KBUILD_LDFLAGS := -m elf_s390 988*4882a593Smuzhiyun 989*4882a593Smuzhiyun Note: ldflags-y can be used to further customise 990*4882a593Smuzhiyun the flags used. See section 3.7. 991*4882a593Smuzhiyun 992*4882a593Smuzhiyun LDFLAGS_vmlinux 993*4882a593Smuzhiyun Options for $(LD) when linking vmlinux 994*4882a593Smuzhiyun 995*4882a593Smuzhiyun LDFLAGS_vmlinux is used to specify additional flags to pass to 996*4882a593Smuzhiyun the linker when linking the final vmlinux image. 997*4882a593Smuzhiyun LDFLAGS_vmlinux uses the LDFLAGS_$@ support. 998*4882a593Smuzhiyun 999*4882a593Smuzhiyun Example:: 1000*4882a593Smuzhiyun 1001*4882a593Smuzhiyun #arch/x86/Makefile 1002*4882a593Smuzhiyun LDFLAGS_vmlinux := -e stext 1003*4882a593Smuzhiyun 1004*4882a593Smuzhiyun OBJCOPYFLAGS 1005*4882a593Smuzhiyun objcopy flags 1006*4882a593Smuzhiyun 1007*4882a593Smuzhiyun When $(call if_changed,objcopy) is used to translate a .o file, 1008*4882a593Smuzhiyun the flags specified in OBJCOPYFLAGS will be used. 1009*4882a593Smuzhiyun $(call if_changed,objcopy) is often used to generate raw binaries on 1010*4882a593Smuzhiyun vmlinux. 1011*4882a593Smuzhiyun 1012*4882a593Smuzhiyun Example:: 1013*4882a593Smuzhiyun 1014*4882a593Smuzhiyun #arch/s390/Makefile 1015*4882a593Smuzhiyun OBJCOPYFLAGS := -O binary 1016*4882a593Smuzhiyun 1017*4882a593Smuzhiyun #arch/s390/boot/Makefile 1018*4882a593Smuzhiyun $(obj)/image: vmlinux FORCE 1019*4882a593Smuzhiyun $(call if_changed,objcopy) 1020*4882a593Smuzhiyun 1021*4882a593Smuzhiyun In this example, the binary $(obj)/image is a binary version of 1022*4882a593Smuzhiyun vmlinux. The usage of $(call if_changed,xxx) will be described later. 1023*4882a593Smuzhiyun 1024*4882a593Smuzhiyun KBUILD_AFLAGS 1025*4882a593Smuzhiyun Assembler flags 1026*4882a593Smuzhiyun 1027*4882a593Smuzhiyun Default value - see top level Makefile 1028*4882a593Smuzhiyun Append or modify as required per architecture. 1029*4882a593Smuzhiyun 1030*4882a593Smuzhiyun Example:: 1031*4882a593Smuzhiyun 1032*4882a593Smuzhiyun #arch/sparc64/Makefile 1033*4882a593Smuzhiyun KBUILD_AFLAGS += -m64 -mcpu=ultrasparc 1034*4882a593Smuzhiyun 1035*4882a593Smuzhiyun KBUILD_CFLAGS 1036*4882a593Smuzhiyun $(CC) compiler flags 1037*4882a593Smuzhiyun 1038*4882a593Smuzhiyun Default value - see top level Makefile 1039*4882a593Smuzhiyun Append or modify as required per architecture. 1040*4882a593Smuzhiyun 1041*4882a593Smuzhiyun Often, the KBUILD_CFLAGS variable depends on the configuration. 1042*4882a593Smuzhiyun 1043*4882a593Smuzhiyun Example:: 1044*4882a593Smuzhiyun 1045*4882a593Smuzhiyun #arch/x86/boot/compressed/Makefile 1046*4882a593Smuzhiyun cflags-$(CONFIG_X86_32) := -march=i386 1047*4882a593Smuzhiyun cflags-$(CONFIG_X86_64) := -mcmodel=small 1048*4882a593Smuzhiyun KBUILD_CFLAGS += $(cflags-y) 1049*4882a593Smuzhiyun 1050*4882a593Smuzhiyun Many arch Makefiles dynamically run the target C compiler to 1051*4882a593Smuzhiyun probe supported options:: 1052*4882a593Smuzhiyun 1053*4882a593Smuzhiyun #arch/x86/Makefile 1054*4882a593Smuzhiyun 1055*4882a593Smuzhiyun ... 1056*4882a593Smuzhiyun cflags-$(CONFIG_MPENTIUMII) += $(call cc-option,\ 1057*4882a593Smuzhiyun -march=pentium2,-march=i686) 1058*4882a593Smuzhiyun ... 1059*4882a593Smuzhiyun # Disable unit-at-a-time mode ... 1060*4882a593Smuzhiyun KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time) 1061*4882a593Smuzhiyun ... 1062*4882a593Smuzhiyun 1063*4882a593Smuzhiyun 1064*4882a593Smuzhiyun The first example utilises the trick that a config option expands 1065*4882a593Smuzhiyun to 'y' when selected. 1066*4882a593Smuzhiyun 1067*4882a593Smuzhiyun KBUILD_AFLAGS_KERNEL 1068*4882a593Smuzhiyun Assembler options specific for built-in 1069*4882a593Smuzhiyun 1070*4882a593Smuzhiyun $(KBUILD_AFLAGS_KERNEL) contains extra C compiler flags used to compile 1071*4882a593Smuzhiyun resident kernel code. 1072*4882a593Smuzhiyun 1073*4882a593Smuzhiyun KBUILD_AFLAGS_MODULE 1074*4882a593Smuzhiyun Assembler options specific for modules 1075*4882a593Smuzhiyun 1076*4882a593Smuzhiyun $(KBUILD_AFLAGS_MODULE) is used to add arch-specific options that 1077*4882a593Smuzhiyun are used for assembler. 1078*4882a593Smuzhiyun 1079*4882a593Smuzhiyun From commandline AFLAGS_MODULE shall be used (see kbuild.rst). 1080*4882a593Smuzhiyun 1081*4882a593Smuzhiyun KBUILD_CFLAGS_KERNEL 1082*4882a593Smuzhiyun $(CC) options specific for built-in 1083*4882a593Smuzhiyun 1084*4882a593Smuzhiyun $(KBUILD_CFLAGS_KERNEL) contains extra C compiler flags used to compile 1085*4882a593Smuzhiyun resident kernel code. 1086*4882a593Smuzhiyun 1087*4882a593Smuzhiyun KBUILD_CFLAGS_MODULE 1088*4882a593Smuzhiyun Options for $(CC) when building modules 1089*4882a593Smuzhiyun 1090*4882a593Smuzhiyun $(KBUILD_CFLAGS_MODULE) is used to add arch-specific options that 1091*4882a593Smuzhiyun are used for $(CC). 1092*4882a593Smuzhiyun From commandline CFLAGS_MODULE shall be used (see kbuild.rst). 1093*4882a593Smuzhiyun 1094*4882a593Smuzhiyun KBUILD_LDFLAGS_MODULE 1095*4882a593Smuzhiyun Options for $(LD) when linking modules 1096*4882a593Smuzhiyun 1097*4882a593Smuzhiyun $(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options 1098*4882a593Smuzhiyun used when linking modules. This is often a linker script. 1099*4882a593Smuzhiyun 1100*4882a593Smuzhiyun From commandline LDFLAGS_MODULE shall be used (see kbuild.rst). 1101*4882a593Smuzhiyun 1102*4882a593Smuzhiyun KBUILD_LDS 1103*4882a593Smuzhiyun 1104*4882a593Smuzhiyun The linker script with full path. Assigned by the top-level Makefile. 1105*4882a593Smuzhiyun 1106*4882a593Smuzhiyun KBUILD_LDS_MODULE 1107*4882a593Smuzhiyun 1108*4882a593Smuzhiyun The module linker script with full path. Assigned by the top-level 1109*4882a593Smuzhiyun Makefile and additionally by the arch Makefile. 1110*4882a593Smuzhiyun 1111*4882a593Smuzhiyun KBUILD_VMLINUX_OBJS 1112*4882a593Smuzhiyun 1113*4882a593Smuzhiyun All object files for vmlinux. They are linked to vmlinux in the same 1114*4882a593Smuzhiyun order as listed in KBUILD_VMLINUX_OBJS. 1115*4882a593Smuzhiyun 1116*4882a593Smuzhiyun KBUILD_VMLINUX_LIBS 1117*4882a593Smuzhiyun 1118*4882a593Smuzhiyun All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and 1119*4882a593Smuzhiyun KBUILD_VMLINUX_LIBS together specify all the object files used to 1120*4882a593Smuzhiyun link vmlinux. 1121*4882a593Smuzhiyun 1122*4882a593Smuzhiyun7.2 Add prerequisites to archheaders 1123*4882a593Smuzhiyun------------------------------------ 1124*4882a593Smuzhiyun 1125*4882a593Smuzhiyun The archheaders: rule is used to generate header files that 1126*4882a593Smuzhiyun may be installed into user space by "make header_install". 1127*4882a593Smuzhiyun 1128*4882a593Smuzhiyun It is run before "make archprepare" when run on the 1129*4882a593Smuzhiyun architecture itself. 1130*4882a593Smuzhiyun 1131*4882a593Smuzhiyun 1132*4882a593Smuzhiyun7.3 Add prerequisites to archprepare 1133*4882a593Smuzhiyun------------------------------------ 1134*4882a593Smuzhiyun 1135*4882a593Smuzhiyun The archprepare: rule is used to list prerequisites that need to be 1136*4882a593Smuzhiyun built before starting to descend down in the subdirectories. 1137*4882a593Smuzhiyun This is usually used for header files containing assembler constants. 1138*4882a593Smuzhiyun 1139*4882a593Smuzhiyun Example:: 1140*4882a593Smuzhiyun 1141*4882a593Smuzhiyun #arch/arm/Makefile 1142*4882a593Smuzhiyun archprepare: maketools 1143*4882a593Smuzhiyun 1144*4882a593Smuzhiyun In this example, the file target maketools will be processed 1145*4882a593Smuzhiyun before descending down in the subdirectories. 1146*4882a593Smuzhiyun See also chapter XXX-TODO that describes how kbuild supports 1147*4882a593Smuzhiyun generating offset header files. 1148*4882a593Smuzhiyun 1149*4882a593Smuzhiyun 1150*4882a593Smuzhiyun7.4 List directories to visit when descending 1151*4882a593Smuzhiyun--------------------------------------------- 1152*4882a593Smuzhiyun 1153*4882a593Smuzhiyun An arch Makefile cooperates with the top Makefile to define variables 1154*4882a593Smuzhiyun which specify how to build the vmlinux file. Note that there is no 1155*4882a593Smuzhiyun corresponding arch-specific section for modules; the module-building 1156*4882a593Smuzhiyun machinery is all architecture-independent. 1157*4882a593Smuzhiyun 1158*4882a593Smuzhiyun 1159*4882a593Smuzhiyun head-y, init-y, core-y, libs-y, drivers-y, net-y 1160*4882a593Smuzhiyun $(head-y) lists objects to be linked first in vmlinux. 1161*4882a593Smuzhiyun 1162*4882a593Smuzhiyun $(libs-y) lists directories where a lib.a archive can be located. 1163*4882a593Smuzhiyun 1164*4882a593Smuzhiyun The rest list directories where a built-in.a object file can be 1165*4882a593Smuzhiyun located. 1166*4882a593Smuzhiyun 1167*4882a593Smuzhiyun $(init-y) objects will be located after $(head-y). 1168*4882a593Smuzhiyun 1169*4882a593Smuzhiyun Then the rest follows in this order: 1170*4882a593Smuzhiyun 1171*4882a593Smuzhiyun $(core-y), $(libs-y), $(drivers-y) and $(net-y). 1172*4882a593Smuzhiyun 1173*4882a593Smuzhiyun The top level Makefile defines values for all generic directories, 1174*4882a593Smuzhiyun and arch/$(ARCH)/Makefile only adds architecture-specific 1175*4882a593Smuzhiyun directories. 1176*4882a593Smuzhiyun 1177*4882a593Smuzhiyun Example:: 1178*4882a593Smuzhiyun 1179*4882a593Smuzhiyun #arch/sparc64/Makefile 1180*4882a593Smuzhiyun core-y += arch/sparc64/kernel/ 1181*4882a593Smuzhiyun libs-y += arch/sparc64/prom/ arch/sparc64/lib/ 1182*4882a593Smuzhiyun drivers-$(CONFIG_OPROFILE) += arch/sparc64/oprofile/ 1183*4882a593Smuzhiyun 1184*4882a593Smuzhiyun 1185*4882a593Smuzhiyun7.5 Architecture-specific boot images 1186*4882a593Smuzhiyun------------------------------------- 1187*4882a593Smuzhiyun 1188*4882a593Smuzhiyun An arch Makefile specifies goals that take the vmlinux file, compress 1189*4882a593Smuzhiyun it, wrap it in bootstrapping code, and copy the resulting files 1190*4882a593Smuzhiyun somewhere. This includes various kinds of installation commands. 1191*4882a593Smuzhiyun The actual goals are not standardized across architectures. 1192*4882a593Smuzhiyun 1193*4882a593Smuzhiyun It is common to locate any additional processing in a boot/ 1194*4882a593Smuzhiyun directory below arch/$(ARCH)/. 1195*4882a593Smuzhiyun 1196*4882a593Smuzhiyun Kbuild does not provide any smart way to support building a 1197*4882a593Smuzhiyun target specified in boot/. Therefore arch/$(ARCH)/Makefile shall 1198*4882a593Smuzhiyun call make manually to build a target in boot/. 1199*4882a593Smuzhiyun 1200*4882a593Smuzhiyun The recommended approach is to include shortcuts in 1201*4882a593Smuzhiyun arch/$(ARCH)/Makefile, and use the full path when calling down 1202*4882a593Smuzhiyun into the arch/$(ARCH)/boot/Makefile. 1203*4882a593Smuzhiyun 1204*4882a593Smuzhiyun Example:: 1205*4882a593Smuzhiyun 1206*4882a593Smuzhiyun #arch/x86/Makefile 1207*4882a593Smuzhiyun boot := arch/x86/boot 1208*4882a593Smuzhiyun bzImage: vmlinux 1209*4882a593Smuzhiyun $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 1210*4882a593Smuzhiyun 1211*4882a593Smuzhiyun "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke 1212*4882a593Smuzhiyun make in a subdirectory. 1213*4882a593Smuzhiyun 1214*4882a593Smuzhiyun There are no rules for naming architecture-specific targets, 1215*4882a593Smuzhiyun but executing "make help" will list all relevant targets. 1216*4882a593Smuzhiyun To support this, $(archhelp) must be defined. 1217*4882a593Smuzhiyun 1218*4882a593Smuzhiyun Example:: 1219*4882a593Smuzhiyun 1220*4882a593Smuzhiyun #arch/x86/Makefile 1221*4882a593Smuzhiyun define archhelp 1222*4882a593Smuzhiyun echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' 1223*4882a593Smuzhiyun endif 1224*4882a593Smuzhiyun 1225*4882a593Smuzhiyun When make is executed without arguments, the first goal encountered 1226*4882a593Smuzhiyun will be built. In the top level Makefile the first goal present 1227*4882a593Smuzhiyun is all:. 1228*4882a593Smuzhiyun An architecture shall always, per default, build a bootable image. 1229*4882a593Smuzhiyun In "make help", the default goal is highlighted with a '*'. 1230*4882a593Smuzhiyun Add a new prerequisite to all: to select a default goal different 1231*4882a593Smuzhiyun from vmlinux. 1232*4882a593Smuzhiyun 1233*4882a593Smuzhiyun Example:: 1234*4882a593Smuzhiyun 1235*4882a593Smuzhiyun #arch/x86/Makefile 1236*4882a593Smuzhiyun all: bzImage 1237*4882a593Smuzhiyun 1238*4882a593Smuzhiyun When "make" is executed without arguments, bzImage will be built. 1239*4882a593Smuzhiyun 1240*4882a593Smuzhiyun7.6 Building non-kbuild targets 1241*4882a593Smuzhiyun------------------------------- 1242*4882a593Smuzhiyun 1243*4882a593Smuzhiyun extra-y 1244*4882a593Smuzhiyun extra-y specifies additional targets created in the current 1245*4882a593Smuzhiyun directory, in addition to any targets specified by `obj-*`. 1246*4882a593Smuzhiyun 1247*4882a593Smuzhiyun Listing all targets in extra-y is required for two purposes: 1248*4882a593Smuzhiyun 1249*4882a593Smuzhiyun 1) Enable kbuild to check changes in command lines 1250*4882a593Smuzhiyun 1251*4882a593Smuzhiyun - When $(call if_changed,xxx) is used 1252*4882a593Smuzhiyun 1253*4882a593Smuzhiyun 2) kbuild knows what files to delete during "make clean" 1254*4882a593Smuzhiyun 1255*4882a593Smuzhiyun Example:: 1256*4882a593Smuzhiyun 1257*4882a593Smuzhiyun #arch/x86/kernel/Makefile 1258*4882a593Smuzhiyun extra-y := head.o init_task.o 1259*4882a593Smuzhiyun 1260*4882a593Smuzhiyun In this example, extra-y is used to list object files that 1261*4882a593Smuzhiyun shall be built, but shall not be linked as part of built-in.a. 1262*4882a593Smuzhiyun 1263*4882a593Smuzhiyun7.7 Commands useful for building a boot image 1264*4882a593Smuzhiyun--------------------------------------------- 1265*4882a593Smuzhiyun 1266*4882a593Smuzhiyun Kbuild provides a few macros that are useful when building a 1267*4882a593Smuzhiyun boot image. 1268*4882a593Smuzhiyun 1269*4882a593Smuzhiyun if_changed 1270*4882a593Smuzhiyun if_changed is the infrastructure used for the following commands. 1271*4882a593Smuzhiyun 1272*4882a593Smuzhiyun Usage:: 1273*4882a593Smuzhiyun 1274*4882a593Smuzhiyun target: source(s) FORCE 1275*4882a593Smuzhiyun $(call if_changed,ld/objcopy/gzip/...) 1276*4882a593Smuzhiyun 1277*4882a593Smuzhiyun When the rule is evaluated, it is checked to see if any files 1278*4882a593Smuzhiyun need an update, or the command line has changed since the last 1279*4882a593Smuzhiyun invocation. The latter will force a rebuild if any options 1280*4882a593Smuzhiyun to the executable have changed. 1281*4882a593Smuzhiyun Any target that utilises if_changed must be listed in $(targets), 1282*4882a593Smuzhiyun otherwise the command line check will fail, and the target will 1283*4882a593Smuzhiyun always be built. 1284*4882a593Smuzhiyun Assignments to $(targets) are without $(obj)/ prefix. 1285*4882a593Smuzhiyun if_changed may be used in conjunction with custom commands as 1286*4882a593Smuzhiyun defined in 7.8 "Custom kbuild commands". 1287*4882a593Smuzhiyun 1288*4882a593Smuzhiyun Note: It is a typical mistake to forget the FORCE prerequisite. 1289*4882a593Smuzhiyun Another common pitfall is that whitespace is sometimes 1290*4882a593Smuzhiyun significant; for instance, the below will fail (note the extra space 1291*4882a593Smuzhiyun after the comma):: 1292*4882a593Smuzhiyun 1293*4882a593Smuzhiyun target: source(s) FORCE 1294*4882a593Smuzhiyun 1295*4882a593Smuzhiyun **WRONG!** $(call if_changed, ld/objcopy/gzip/...) 1296*4882a593Smuzhiyun 1297*4882a593Smuzhiyun Note: 1298*4882a593Smuzhiyun if_changed should not be used more than once per target. 1299*4882a593Smuzhiyun It stores the executed command in a corresponding .cmd 1300*4882a593Smuzhiyun 1301*4882a593Smuzhiyun file and multiple calls would result in overwrites and 1302*4882a593Smuzhiyun unwanted results when the target is up to date and only the 1303*4882a593Smuzhiyun tests on changed commands trigger execution of commands. 1304*4882a593Smuzhiyun 1305*4882a593Smuzhiyun ld 1306*4882a593Smuzhiyun Link target. Often, LDFLAGS_$@ is used to set specific options to ld. 1307*4882a593Smuzhiyun 1308*4882a593Smuzhiyun Example:: 1309*4882a593Smuzhiyun 1310*4882a593Smuzhiyun #arch/x86/boot/Makefile 1311*4882a593Smuzhiyun LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary 1312*4882a593Smuzhiyun LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext 1313*4882a593Smuzhiyun 1314*4882a593Smuzhiyun targets += setup setup.o bootsect bootsect.o 1315*4882a593Smuzhiyun $(obj)/setup $(obj)/bootsect: %: %.o FORCE 1316*4882a593Smuzhiyun $(call if_changed,ld) 1317*4882a593Smuzhiyun 1318*4882a593Smuzhiyun In this example, there are two possible targets, requiring different 1319*4882a593Smuzhiyun options to the linker. The linker options are specified using the 1320*4882a593Smuzhiyun LDFLAGS_$@ syntax - one for each potential target. 1321*4882a593Smuzhiyun $(targets) are assigned all potential targets, by which kbuild knows 1322*4882a593Smuzhiyun the targets and will: 1323*4882a593Smuzhiyun 1324*4882a593Smuzhiyun 1) check for commandline changes 1325*4882a593Smuzhiyun 2) delete target during make clean 1326*4882a593Smuzhiyun 1327*4882a593Smuzhiyun The ": %: %.o" part of the prerequisite is a shorthand that 1328*4882a593Smuzhiyun frees us from listing the setup.o and bootsect.o files. 1329*4882a593Smuzhiyun 1330*4882a593Smuzhiyun Note: 1331*4882a593Smuzhiyun It is a common mistake to forget the "targets :=" assignment, 1332*4882a593Smuzhiyun resulting in the target file being recompiled for no 1333*4882a593Smuzhiyun obvious reason. 1334*4882a593Smuzhiyun 1335*4882a593Smuzhiyun objcopy 1336*4882a593Smuzhiyun Copy binary. Uses OBJCOPYFLAGS usually specified in 1337*4882a593Smuzhiyun arch/$(ARCH)/Makefile. 1338*4882a593Smuzhiyun OBJCOPYFLAGS_$@ may be used to set additional options. 1339*4882a593Smuzhiyun 1340*4882a593Smuzhiyun gzip 1341*4882a593Smuzhiyun Compress target. Use maximum compression to compress target. 1342*4882a593Smuzhiyun 1343*4882a593Smuzhiyun Example:: 1344*4882a593Smuzhiyun 1345*4882a593Smuzhiyun #arch/x86/boot/compressed/Makefile 1346*4882a593Smuzhiyun $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE 1347*4882a593Smuzhiyun $(call if_changed,gzip) 1348*4882a593Smuzhiyun 1349*4882a593Smuzhiyun dtc 1350*4882a593Smuzhiyun Create flattened device tree blob object suitable for linking 1351*4882a593Smuzhiyun into vmlinux. Device tree blobs linked into vmlinux are placed 1352*4882a593Smuzhiyun in an init section in the image. Platform code *must* copy the 1353*4882a593Smuzhiyun blob to non-init memory prior to calling unflatten_device_tree(). 1354*4882a593Smuzhiyun 1355*4882a593Smuzhiyun To use this command, simply add `*.dtb` into obj-y or targets, or make 1356*4882a593Smuzhiyun some other target depend on `%.dtb` 1357*4882a593Smuzhiyun 1358*4882a593Smuzhiyun A central rule exists to create `$(obj)/%.dtb` from `$(src)/%.dts`; 1359*4882a593Smuzhiyun architecture Makefiles do no need to explicitly write out that rule. 1360*4882a593Smuzhiyun 1361*4882a593Smuzhiyun Example:: 1362*4882a593Smuzhiyun 1363*4882a593Smuzhiyun targets += $(dtb-y) 1364*4882a593Smuzhiyun DTC_FLAGS ?= -p 1024 1365*4882a593Smuzhiyun 1366*4882a593Smuzhiyun7.8 Custom kbuild commands 1367*4882a593Smuzhiyun-------------------------- 1368*4882a593Smuzhiyun 1369*4882a593Smuzhiyun When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand 1370*4882a593Smuzhiyun of a command is normally displayed. 1371*4882a593Smuzhiyun To enable this behaviour for custom commands kbuild requires 1372*4882a593Smuzhiyun two variables to be set:: 1373*4882a593Smuzhiyun 1374*4882a593Smuzhiyun quiet_cmd_<command> - what shall be echoed 1375*4882a593Smuzhiyun cmd_<command> - the command to execute 1376*4882a593Smuzhiyun 1377*4882a593Smuzhiyun Example:: 1378*4882a593Smuzhiyun 1379*4882a593Smuzhiyun # 1380*4882a593Smuzhiyun quiet_cmd_image = BUILD $@ 1381*4882a593Smuzhiyun cmd_image = $(obj)/tools/build $(BUILDFLAGS) \ 1382*4882a593Smuzhiyun $(obj)/vmlinux.bin > $@ 1383*4882a593Smuzhiyun 1384*4882a593Smuzhiyun targets += bzImage 1385*4882a593Smuzhiyun $(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE 1386*4882a593Smuzhiyun $(call if_changed,image) 1387*4882a593Smuzhiyun @echo 'Kernel: $@ is ready' 1388*4882a593Smuzhiyun 1389*4882a593Smuzhiyun When updating the $(obj)/bzImage target, the line: 1390*4882a593Smuzhiyun 1391*4882a593Smuzhiyun BUILD arch/x86/boot/bzImage 1392*4882a593Smuzhiyun 1393*4882a593Smuzhiyun will be displayed with "make KBUILD_VERBOSE=0". 1394*4882a593Smuzhiyun 1395*4882a593Smuzhiyun 1396*4882a593Smuzhiyun7.9 Preprocessing linker scripts 1397*4882a593Smuzhiyun-------------------------------- 1398*4882a593Smuzhiyun 1399*4882a593Smuzhiyun When the vmlinux image is built, the linker script 1400*4882a593Smuzhiyun arch/$(ARCH)/kernel/vmlinux.lds is used. 1401*4882a593Smuzhiyun The script is a preprocessed variant of the file vmlinux.lds.S 1402*4882a593Smuzhiyun located in the same directory. 1403*4882a593Smuzhiyun kbuild knows .lds files and includes a rule `*lds.S` -> `*lds`. 1404*4882a593Smuzhiyun 1405*4882a593Smuzhiyun Example:: 1406*4882a593Smuzhiyun 1407*4882a593Smuzhiyun #arch/x86/kernel/Makefile 1408*4882a593Smuzhiyun extra-y := vmlinux.lds 1409*4882a593Smuzhiyun 1410*4882a593Smuzhiyun #Makefile 1411*4882a593Smuzhiyun export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) 1412*4882a593Smuzhiyun 1413*4882a593Smuzhiyun The assignment to extra-y is used to tell kbuild to build the 1414*4882a593Smuzhiyun target vmlinux.lds. 1415*4882a593Smuzhiyun The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the 1416*4882a593Smuzhiyun specified options when building the target vmlinux.lds. 1417*4882a593Smuzhiyun 1418*4882a593Smuzhiyun When building the `*.lds` target, kbuild uses the variables:: 1419*4882a593Smuzhiyun 1420*4882a593Smuzhiyun KBUILD_CPPFLAGS : Set in top-level Makefile 1421*4882a593Smuzhiyun cppflags-y : May be set in the kbuild makefile 1422*4882a593Smuzhiyun CPPFLAGS_$(@F) : Target-specific flags. 1423*4882a593Smuzhiyun Note that the full filename is used in this 1424*4882a593Smuzhiyun assignment. 1425*4882a593Smuzhiyun 1426*4882a593Smuzhiyun The kbuild infrastructure for `*lds` files is used in several 1427*4882a593Smuzhiyun architecture-specific files. 1428*4882a593Smuzhiyun 1429*4882a593Smuzhiyun7.10 Generic header files 1430*4882a593Smuzhiyun------------------------- 1431*4882a593Smuzhiyun 1432*4882a593Smuzhiyun The directory include/asm-generic contains the header files 1433*4882a593Smuzhiyun that may be shared between individual architectures. 1434*4882a593Smuzhiyun The recommended approach how to use a generic header file is 1435*4882a593Smuzhiyun to list the file in the Kbuild file. 1436*4882a593Smuzhiyun See "8.2 generic-y" for further info on syntax etc. 1437*4882a593Smuzhiyun 1438*4882a593Smuzhiyun7.11 Post-link pass 1439*4882a593Smuzhiyun------------------- 1440*4882a593Smuzhiyun 1441*4882a593Smuzhiyun If the file arch/xxx/Makefile.postlink exists, this makefile 1442*4882a593Smuzhiyun will be invoked for post-link objects (vmlinux and modules.ko) 1443*4882a593Smuzhiyun for architectures to run post-link passes on. Must also handle 1444*4882a593Smuzhiyun the clean target. 1445*4882a593Smuzhiyun 1446*4882a593Smuzhiyun This pass runs after kallsyms generation. If the architecture 1447*4882a593Smuzhiyun needs to modify symbol locations, rather than manipulate the 1448*4882a593Smuzhiyun kallsyms, it may be easier to add another postlink target for 1449*4882a593Smuzhiyun .tmp_vmlinux? targets to be called from link-vmlinux.sh. 1450*4882a593Smuzhiyun 1451*4882a593Smuzhiyun For example, powerpc uses this to check relocation sanity of 1452*4882a593Smuzhiyun the linked vmlinux file. 1453*4882a593Smuzhiyun 1454*4882a593Smuzhiyun8 Kbuild syntax for exported headers 1455*4882a593Smuzhiyun------------------------------------ 1456*4882a593Smuzhiyun 1457*4882a593SmuzhiyunThe kernel includes a set of headers that is exported to userspace. 1458*4882a593SmuzhiyunMany headers can be exported as-is but other headers require a 1459*4882a593Smuzhiyunminimal pre-processing before they are ready for user-space. 1460*4882a593SmuzhiyunThe pre-processing does: 1461*4882a593Smuzhiyun 1462*4882a593Smuzhiyun- drop kernel-specific annotations 1463*4882a593Smuzhiyun- drop include of compiler.h 1464*4882a593Smuzhiyun- drop all sections that are kernel internal (guarded by `ifdef __KERNEL__`) 1465*4882a593Smuzhiyun 1466*4882a593SmuzhiyunAll headers under include/uapi/, include/generated/uapi/, 1467*4882a593Smuzhiyunarch/<arch>/include/uapi/ and arch/<arch>/include/generated/uapi/ 1468*4882a593Smuzhiyunare exported. 1469*4882a593Smuzhiyun 1470*4882a593SmuzhiyunA Kbuild file may be defined under arch/<arch>/include/uapi/asm/ and 1471*4882a593Smuzhiyunarch/<arch>/include/asm/ to list asm files coming from asm-generic. 1472*4882a593SmuzhiyunSee subsequent chapter for the syntax of the Kbuild file. 1473*4882a593Smuzhiyun 1474*4882a593Smuzhiyun8.1 no-export-headers 1475*4882a593Smuzhiyun--------------------- 1476*4882a593Smuzhiyun 1477*4882a593Smuzhiyun no-export-headers is essentially used by include/uapi/linux/Kbuild to 1478*4882a593Smuzhiyun avoid exporting specific headers (e.g. kvm.h) on architectures that do 1479*4882a593Smuzhiyun not support it. It should be avoided as much as possible. 1480*4882a593Smuzhiyun 1481*4882a593Smuzhiyun8.2 generic-y 1482*4882a593Smuzhiyun------------- 1483*4882a593Smuzhiyun 1484*4882a593Smuzhiyun If an architecture uses a verbatim copy of a header from 1485*4882a593Smuzhiyun include/asm-generic then this is listed in the file 1486*4882a593Smuzhiyun arch/$(ARCH)/include/asm/Kbuild like this: 1487*4882a593Smuzhiyun 1488*4882a593Smuzhiyun Example:: 1489*4882a593Smuzhiyun 1490*4882a593Smuzhiyun #arch/x86/include/asm/Kbuild 1491*4882a593Smuzhiyun generic-y += termios.h 1492*4882a593Smuzhiyun generic-y += rtc.h 1493*4882a593Smuzhiyun 1494*4882a593Smuzhiyun During the prepare phase of the build a wrapper include 1495*4882a593Smuzhiyun file is generated in the directory:: 1496*4882a593Smuzhiyun 1497*4882a593Smuzhiyun arch/$(ARCH)/include/generated/asm 1498*4882a593Smuzhiyun 1499*4882a593Smuzhiyun When a header is exported where the architecture uses 1500*4882a593Smuzhiyun the generic header a similar wrapper is generated as part 1501*4882a593Smuzhiyun of the set of exported headers in the directory:: 1502*4882a593Smuzhiyun 1503*4882a593Smuzhiyun usr/include/asm 1504*4882a593Smuzhiyun 1505*4882a593Smuzhiyun The generated wrapper will in both cases look like the following: 1506*4882a593Smuzhiyun 1507*4882a593Smuzhiyun Example: termios.h:: 1508*4882a593Smuzhiyun 1509*4882a593Smuzhiyun #include <asm-generic/termios.h> 1510*4882a593Smuzhiyun 1511*4882a593Smuzhiyun8.3 generated-y 1512*4882a593Smuzhiyun--------------- 1513*4882a593Smuzhiyun 1514*4882a593Smuzhiyun If an architecture generates other header files alongside generic-y 1515*4882a593Smuzhiyun wrappers, generated-y specifies them. 1516*4882a593Smuzhiyun 1517*4882a593Smuzhiyun This prevents them being treated as stale asm-generic wrappers and 1518*4882a593Smuzhiyun removed. 1519*4882a593Smuzhiyun 1520*4882a593Smuzhiyun Example:: 1521*4882a593Smuzhiyun 1522*4882a593Smuzhiyun #arch/x86/include/asm/Kbuild 1523*4882a593Smuzhiyun generated-y += syscalls_32.h 1524*4882a593Smuzhiyun 1525*4882a593Smuzhiyun8.4 mandatory-y 1526*4882a593Smuzhiyun--------------- 1527*4882a593Smuzhiyun 1528*4882a593Smuzhiyun mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild 1529*4882a593Smuzhiyun to define the minimum set of ASM headers that all architectures must have. 1530*4882a593Smuzhiyun 1531*4882a593Smuzhiyun This works like optional generic-y. If a mandatory header is missing 1532*4882a593Smuzhiyun in arch/$(ARCH)/include/(uapi/)/asm, Kbuild will automatically generate 1533*4882a593Smuzhiyun a wrapper of the asm-generic one. 1534*4882a593Smuzhiyun 1535*4882a593Smuzhiyun9 Kbuild Variables 1536*4882a593Smuzhiyun================== 1537*4882a593Smuzhiyun 1538*4882a593SmuzhiyunThe top Makefile exports the following variables: 1539*4882a593Smuzhiyun 1540*4882a593Smuzhiyun VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION 1541*4882a593Smuzhiyun These variables define the current kernel version. A few arch 1542*4882a593Smuzhiyun Makefiles actually use these values directly; they should use 1543*4882a593Smuzhiyun $(KERNELRELEASE) instead. 1544*4882a593Smuzhiyun 1545*4882a593Smuzhiyun $(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic 1546*4882a593Smuzhiyun three-part version number, such as "2", "4", and "0". These three 1547*4882a593Smuzhiyun values are always numeric. 1548*4882a593Smuzhiyun 1549*4882a593Smuzhiyun $(EXTRAVERSION) defines an even tinier sublevel for pre-patches 1550*4882a593Smuzhiyun or additional patches. It is usually some non-numeric string 1551*4882a593Smuzhiyun such as "-pre4", and is often blank. 1552*4882a593Smuzhiyun 1553*4882a593Smuzhiyun KERNELRELEASE 1554*4882a593Smuzhiyun $(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable 1555*4882a593Smuzhiyun for constructing installation directory names or showing in 1556*4882a593Smuzhiyun version strings. Some arch Makefiles use it for this purpose. 1557*4882a593Smuzhiyun 1558*4882a593Smuzhiyun ARCH 1559*4882a593Smuzhiyun This variable defines the target architecture, such as "i386", 1560*4882a593Smuzhiyun "arm", or "sparc". Some kbuild Makefiles test $(ARCH) to 1561*4882a593Smuzhiyun determine which files to compile. 1562*4882a593Smuzhiyun 1563*4882a593Smuzhiyun By default, the top Makefile sets $(ARCH) to be the same as the 1564*4882a593Smuzhiyun host system architecture. For a cross build, a user may 1565*4882a593Smuzhiyun override the value of $(ARCH) on the command line:: 1566*4882a593Smuzhiyun 1567*4882a593Smuzhiyun make ARCH=m68k ... 1568*4882a593Smuzhiyun 1569*4882a593Smuzhiyun 1570*4882a593Smuzhiyun INSTALL_PATH 1571*4882a593Smuzhiyun This variable defines a place for the arch Makefiles to install 1572*4882a593Smuzhiyun the resident kernel image and System.map file. 1573*4882a593Smuzhiyun Use this for architecture-specific install targets. 1574*4882a593Smuzhiyun 1575*4882a593Smuzhiyun INSTALL_MOD_PATH, MODLIB 1576*4882a593Smuzhiyun $(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module 1577*4882a593Smuzhiyun installation. This variable is not defined in the Makefile but 1578*4882a593Smuzhiyun may be passed in by the user if desired. 1579*4882a593Smuzhiyun 1580*4882a593Smuzhiyun $(MODLIB) specifies the directory for module installation. 1581*4882a593Smuzhiyun The top Makefile defines $(MODLIB) to 1582*4882a593Smuzhiyun $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE). The user may 1583*4882a593Smuzhiyun override this value on the command line if desired. 1584*4882a593Smuzhiyun 1585*4882a593Smuzhiyun INSTALL_MOD_STRIP 1586*4882a593Smuzhiyun If this variable is specified, it will cause modules to be stripped 1587*4882a593Smuzhiyun after they are installed. If INSTALL_MOD_STRIP is '1', then the 1588*4882a593Smuzhiyun default option --strip-debug will be used. Otherwise, the 1589*4882a593Smuzhiyun INSTALL_MOD_STRIP value will be used as the option(s) to the strip 1590*4882a593Smuzhiyun command. 1591*4882a593Smuzhiyun 1592*4882a593Smuzhiyun 1593*4882a593Smuzhiyun10 Makefile language 1594*4882a593Smuzhiyun==================== 1595*4882a593Smuzhiyun 1596*4882a593SmuzhiyunThe kernel Makefiles are designed to be run with GNU Make. The Makefiles 1597*4882a593Smuzhiyunuse only the documented features of GNU Make, but they do use many 1598*4882a593SmuzhiyunGNU extensions. 1599*4882a593Smuzhiyun 1600*4882a593SmuzhiyunGNU Make supports elementary list-processing functions. The kernel 1601*4882a593SmuzhiyunMakefiles use a novel style of list building and manipulation with few 1602*4882a593Smuzhiyun"if" statements. 1603*4882a593Smuzhiyun 1604*4882a593SmuzhiyunGNU Make has two assignment operators, ":=" and "=". ":=" performs 1605*4882a593Smuzhiyunimmediate evaluation of the right-hand side and stores an actual string 1606*4882a593Smuzhiyuninto the left-hand side. "=" is like a formula definition; it stores the 1607*4882a593Smuzhiyunright-hand side in an unevaluated form and then evaluates this form each 1608*4882a593Smuzhiyuntime the left-hand side is used. 1609*4882a593Smuzhiyun 1610*4882a593SmuzhiyunThere are some cases where "=" is appropriate. Usually, though, ":=" 1611*4882a593Smuzhiyunis the right choice. 1612*4882a593Smuzhiyun 1613*4882a593Smuzhiyun11 Credits 1614*4882a593Smuzhiyun========== 1615*4882a593Smuzhiyun 1616*4882a593Smuzhiyun- Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net> 1617*4882a593Smuzhiyun- Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de> 1618*4882a593Smuzhiyun- Updates by Sam Ravnborg <sam@ravnborg.org> 1619*4882a593Smuzhiyun- Language QA by Jan Engelhardt <jengelh@gmx.de> 1620*4882a593Smuzhiyun 1621*4882a593Smuzhiyun12 TODO 1622*4882a593Smuzhiyun======= 1623*4882a593Smuzhiyun 1624*4882a593Smuzhiyun- Describe how kbuild supports shipped files with _shipped. 1625*4882a593Smuzhiyun- Generating offset header files. 1626*4882a593Smuzhiyun- Add more variables to chapters 7 or 9? 1627