@@ -29,31 +29,37 @@ This document describes the Linux kernel Makefiles.
2929 --- 4.4 Controlling compiler options for host programs
3030 --- 4.5 When host programs are actually built
3131
32- === 5 Kbuild clean infrastructure
33-
34- === 6 Architecture Makefiles
35- --- 6.1 Set variables to tweak the build to the architecture
36- --- 6.2 Add prerequisites to archheaders:
37- --- 6.3 Add prerequisites to archprepare:
38- --- 6.4 List directories to visit when descending
39- --- 6.5 Architecture-specific boot images
40- --- 6.6 Building non-kbuild targets
41- --- 6.7 Commands useful for building a boot image
42- --- 6.8 Custom kbuild commands
43- --- 6.9 Preprocessing linker scripts
44- --- 6.10 Generic header files
45- --- 6.11 Post-link pass
46-
47- === 7 Kbuild syntax for exported headers
48- --- 7.1 no-export-headers
49- --- 7.2 generic-y
50- --- 7.3 generated-y
51- --- 7.4 mandatory-y
52-
53- === 8 Kbuild Variables
54- === 9 Makefile language
55- === 10 Credits
56- === 11 TODO
32+ === 5 Userspace Program support
33+ --- 5.1 Simple Userspace Program
34+ --- 5.2 Composite Userspace Programs
35+ --- 5.3 Controlling compiler options for userspace programs
36+ --- 5.4 When userspace programs are actually built
37+
38+ === 6 Kbuild clean infrastructure
39+
40+ === 7 Architecture Makefiles
41+ --- 7.1 Set variables to tweak the build to the architecture
42+ --- 7.2 Add prerequisites to archheaders:
43+ --- 7.3 Add prerequisites to archprepare:
44+ --- 7.4 List directories to visit when descending
45+ --- 7.5 Architecture-specific boot images
46+ --- 7.6 Building non-kbuild targets
47+ --- 7.7 Commands useful for building a boot image
48+ --- 7.8 Custom kbuild commands
49+ --- 7.9 Preprocessing linker scripts
50+ --- 7.10 Generic header files
51+ --- 7.11 Post-link pass
52+
53+ === 8 Kbuild syntax for exported headers
54+ --- 8.1 no-export-headers
55+ --- 8.2 generic-y
56+ --- 8.3 generated-y
57+ --- 8.4 mandatory-y
58+
59+ === 9 Kbuild Variables
60+ === 10 Makefile language
61+ === 11 Credits
62+ === 12 TODO
5763
5864 1 Overview
5965==========
@@ -732,7 +738,88 @@ Both possibilities are described in the following.
732738 This will tell kbuild to build lxdialog even if not referenced in
733739 any rule.
734740
735- 5 Kbuild clean infrastructure
741+ 5 Userspace Program support
742+ ===========================
743+
744+ Just like host programs, Kbuild also supports building userspace executables
745+ for the target architecture (i.e. the same architecture as you are building
746+ the kernel for).
747+
748+ The syntax is quite similar. The difference is to use "userprogs" instead of
749+ "hostprogs".
750+
751+ 5.1 Simple Userspace Program
752+ ----------------------------
753+
754+ The following line tells kbuild that the program bpf-direct shall be
755+ built for the target architecture.
756+
757+ Example::
758+
759+ userprogs := bpf-direct
760+
761+ Kbuild assumes in the above example that bpf-direct is made from a
762+ single C source file named bpf-direct.c located in the same directory
763+ as the Makefile.
764+
765+ 5.2 Composite Userspace Programs
766+ --------------------------------
767+
768+ Userspace programs can be made up based on composite objects.
769+ The syntax used to define composite objects for userspace programs is
770+ similar to the syntax used for kernel objects.
771+ $(<executable>-objs) lists all objects used to link the final
772+ executable.
773+
774+ Example::
775+
776+ #samples/seccomp/Makefile
777+ userprogs := bpf-fancy
778+ bpf-fancy-objs := bpf-fancy.o bpf-helper.o
779+
780+ Objects with extension .o are compiled from the corresponding .c
781+ files. In the above example, bpf-fancy.c is compiled to bpf-fancy.o
782+ and bpf-helper.c is compiled to bpf-helper.o.
783+
784+ Finally, the two .o files are linked to the executable, bpf-fancy.
785+ Note: The syntax <executable>-y is not permitted for userspace programs.
786+
787+ 5.3 Controlling compiler options for userspace programs
788+ -------------------------------------------------------
789+
790+ When compiling userspace programs, it is possible to set specific flags.
791+ The programs will always be compiled utilising $(CC) passed
792+ the options specified in $(KBUILD_USERCFLAGS).
793+ To set flags that will take effect for all userspace programs created
794+ in that Makefile, use the variable userccflags.
795+
796+ Example::
797+
798+ # samples/seccomp/Makefile
799+ userccflags += -I usr/include
800+
801+ To set specific flags for a single file the following construction
802+ is used:
803+
804+ Example::
805+
806+ bpf-helper-userccflags += -I user/include
807+
808+ It is also possible to specify additional options to the linker.
809+
810+ Example::
811+
812+ # net/bpfilter/Makefile
813+ bpfilter_umh-userldflags += -static
814+
815+ When linking bpfilter_umh, it will be passed the extra option -static.
816+
817+ 5.4 When userspace programs are actually built
818+ ----------------------------------------------
819+
820+ Same as "When host programs are actually built".
821+
822+ 6 Kbuild clean infrastructure
736823=============================
737824
738825"make clean" deletes most generated files in the obj tree where the kernel
@@ -790,7 +877,7 @@ is not operational at that point.
790877Note 2: All directories listed in core-y, libs-y, drivers-y and net-y will
791878be visited during "make clean".
792879
793- 6 Architecture Makefiles
880+ 7 Architecture Makefiles
794881========================
795882
796883The top level Makefile sets up the environment and does the preparation,
@@ -820,10 +907,10 @@ When kbuild executes, the following steps are followed (roughly):
820907 - Preparing initrd images and the like
821908
822909
823- 6 .1 Set variables to tweak the build to the architecture
910+ 7 .1 Set variables to tweak the build to the architecture
824911--------------------------------------------------------
825912
826- LDFLAGS
913+ KBUILD_LDFLAGS
827914 Generic $(LD) options
828915
829916 Flags used for all invocations of the linker.
@@ -832,7 +919,7 @@ When kbuild executes, the following steps are followed (roughly):
832919 Example::
833920
834921 #arch/s390/Makefile
835- LDFLAGS := -m elf_s390
922+ KBUILD_LDFLAGS := -m elf_s390
836923
837924 Note: ldflags-y can be used to further customise
838925 the flags used. See chapter 3.7.
@@ -967,7 +1054,7 @@ When kbuild executes, the following steps are followed (roughly):
9671054 KBUILD_VMLINUX_LIBS together specify all the object files used to
9681055 link vmlinux.
9691056
970- 6 .2 Add prerequisites to archheaders
1057+ 7 .2 Add prerequisites to archheaders
9711058------------------------------------
9721059
9731060 The archheaders: rule is used to generate header files that
@@ -977,7 +1064,7 @@ When kbuild executes, the following steps are followed (roughly):
9771064 architecture itself.
9781065
9791066
980- 6 .3 Add prerequisites to archprepare
1067+ 7 .3 Add prerequisites to archprepare
9811068------------------------------------
9821069
9831070 The archprepare: rule is used to list prerequisites that need to be
@@ -995,7 +1082,7 @@ When kbuild executes, the following steps are followed (roughly):
9951082 generating offset header files.
9961083
9971084
998- 6 .4 List directories to visit when descending
1085+ 7 .4 List directories to visit when descending
9991086---------------------------------------------
10001087
10011088 An arch Makefile cooperates with the top Makefile to define variables
@@ -1030,7 +1117,7 @@ When kbuild executes, the following steps are followed (roughly):
10301117 drivers-$(CONFIG_OPROFILE) += arch/sparc64/oprofile/
10311118
10321119
1033- 6 .5 Architecture-specific boot images
1120+ 7 .5 Architecture-specific boot images
10341121-------------------------------------
10351122
10361123 An arch Makefile specifies goals that take the vmlinux file, compress
@@ -1085,7 +1172,7 @@ When kbuild executes, the following steps are followed (roughly):
10851172
10861173 When "make" is executed without arguments, bzImage will be built.
10871174
1088- 6 .6 Building non-kbuild targets
1175+ 7 .6 Building non-kbuild targets
10891176-------------------------------
10901177
10911178 extra-y
@@ -1108,7 +1195,7 @@ When kbuild executes, the following steps are followed (roughly):
11081195 In this example, extra-y is used to list object files that
11091196 shall be built, but shall not be linked as part of built-in.a.
11101197
1111- 6 .7 Commands useful for building a boot image
1198+ 7 .7 Commands useful for building a boot image
11121199---------------------------------------------
11131200
11141201 Kbuild provides a few macros that are useful when building a
@@ -1211,7 +1298,7 @@ When kbuild executes, the following steps are followed (roughly):
12111298 targets += $(dtb-y)
12121299 DTC_FLAGS ?= -p 1024
12131300
1214- 6 .8 Custom kbuild commands
1301+ 7 .8 Custom kbuild commands
12151302--------------------------
12161303
12171304 When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand
@@ -1241,7 +1328,7 @@ When kbuild executes, the following steps are followed (roughly):
12411328 will be displayed with "make KBUILD_VERBOSE=0".
12421329
12431330
1244- 6 .9 Preprocessing linker scripts
1331+ 7 .9 Preprocessing linker scripts
12451332--------------------------------
12461333
12471334 When the vmlinux image is built, the linker script
@@ -1274,7 +1361,7 @@ When kbuild executes, the following steps are followed (roughly):
12741361 The kbuild infrastructure for `*lds ` files is used in several
12751362 architecture-specific files.
12761363
1277- 6 .10 Generic header files
1364+ 7 .10 Generic header files
12781365-------------------------
12791366
12801367 The directory include/asm-generic contains the header files
@@ -1283,7 +1370,7 @@ When kbuild executes, the following steps are followed (roughly):
12831370 to list the file in the Kbuild file.
12841371 See "7.2 generic-y" for further info on syntax etc.
12851372
1286- 6 .11 Post-link pass
1373+ 7 .11 Post-link pass
12871374-------------------
12881375
12891376 If the file arch/xxx/Makefile.postlink exists, this makefile
@@ -1299,7 +1386,7 @@ When kbuild executes, the following steps are followed (roughly):
12991386 For example, powerpc uses this to check relocation sanity of
13001387 the linked vmlinux file.
13011388
1302- 7 Kbuild syntax for exported headers
1389+ 8 Kbuild syntax for exported headers
13031390------------------------------------
13041391
13051392The kernel includes a set of headers that is exported to userspace.
@@ -1319,14 +1406,14 @@ A Kbuild file may be defined under arch/<arch>/include/uapi/asm/ and
13191406arch/<arch>/include/asm/ to list asm files coming from asm-generic.
13201407See subsequent chapter for the syntax of the Kbuild file.
13211408
1322- 7 .1 no-export-headers
1409+ 8 .1 no-export-headers
13231410---------------------
13241411
13251412 no-export-headers is essentially used by include/uapi/linux/Kbuild to
13261413 avoid exporting specific headers (e.g. kvm.h) on architectures that do
13271414 not support it. It should be avoided as much as possible.
13281415
1329- 7 .2 generic-y
1416+ 8 .2 generic-y
13301417-------------
13311418
13321419 If an architecture uses a verbatim copy of a header from
@@ -1356,7 +1443,7 @@ See subsequent chapter for the syntax of the Kbuild file.
13561443
13571444 #include <asm-generic/termios.h>
13581445
1359- 7 .3 generated-y
1446+ 8 .3 generated-y
13601447---------------
13611448
13621449 If an architecture generates other header files alongside generic-y
@@ -1370,7 +1457,7 @@ See subsequent chapter for the syntax of the Kbuild file.
13701457 #arch/x86/include/asm/Kbuild
13711458 generated-y += syscalls_32.h
13721459
1373- 7 .4 mandatory-y
1460+ 8 .4 mandatory-y
13741461---------------
13751462
13761463 mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild
@@ -1380,7 +1467,7 @@ See subsequent chapter for the syntax of the Kbuild file.
13801467 in arch/$(ARCH)/include/(uapi/)/asm, Kbuild will automatically generate
13811468 a wrapper of the asm-generic one.
13821469
1383- 8 Kbuild Variables
1470+ 9 Kbuild Variables
13841471==================
13851472
13861473The top Makefile exports the following variables:
@@ -1438,8 +1525,8 @@ The top Makefile exports the following variables:
14381525 command.
14391526
14401527
1441- 9 Makefile language
1442- ===================
1528+ 10 Makefile language
1529+ ====================
14431530
14441531The kernel Makefiles are designed to be run with GNU Make. The Makefiles
14451532use only the documented features of GNU Make, but they do use many
@@ -1458,15 +1545,15 @@ time the left-hand side is used.
14581545There are some cases where "=" is appropriate. Usually, though, ":="
14591546is the right choice.
14601547
1461- 10 Credits
1548+ 11 Credits
14621549==========
14631550
14641551- Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
14651552- Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
14661553- Updates by Sam Ravnborg <sam@ravnborg.org>
14671554- Language QA by Jan Engelhardt <jengelh@gmx.de>
14681555
1469- 11 TODO
1556+ 12 TODO
14701557=======
14711558
14721559- Describe how kbuild supports shipped files with _shipped.
0 commit comments