diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-24 17:24:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-24 17:24:14 -0400 |
commit | 6e936d3e9a45a4307e7f4a29ee9829e7a0464af1 (patch) | |
tree | 555f9d89779e6a675b38d9703f278ecf0579531c | |
parent | a68aa1cc6f3203b8a332683ebde67a00f39eec43 (diff) | |
parent | 5cc8d246d0ebbdf827d4bb7c3de175377d244d73 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
* git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild: (28 commits)
kbuild: add distclean info to 'make help' and more details for 'clean'
dontdiff: add utsrelease.h
kbuild: fix "mkdir -p" usage in scripts/package/mkspec
kbuild: correct and clarify versioning info in Makefile
kbuild: fixup Documentation/kbuild/modules.txt
kbuild: Extend kbuild/defconfig tags support to exuberant ctags
kbuild: fix for some typos in Documentation/makefiles.txt
kbuild: clarify "make C=" build option
Documentaion: update Documentation/Changes with minimum versions
kbuild: update help in top level Makefile
kbuild: fail kernel compilation in case of unresolved module symbols
kbuild: remove debug left-over from Makefile.host
kbuild: create output directory for hostprogs with O=.. build
kbuild: add missing return statement in modpost.c:secref_whitelist()
kbuild: preperly align SYSMAP output
kbuild: make -rR is now default
kbuild: make V=2 tell why a target is rebuild
kbuild: modpost on vmlinux regardless of CONFIG_MODULES
kbuild: ignore references from ".pci_fixup" to ".init.text"
kbuild: linguistic fixes for Documentation/kbuild/makefiles.txt
...
-rw-r--r-- | Documentation/Changes | 7 | ||||
-rw-r--r-- | Documentation/dontdiff | 1 | ||||
-rw-r--r-- | Documentation/kbuild/kconfig-language.txt | 12 | ||||
-rw-r--r-- | Documentation/kbuild/makefiles.txt | 265 | ||||
-rw-r--r-- | Documentation/kbuild/modules.txt | 161 | ||||
-rw-r--r-- | Documentation/sparse.txt | 8 | ||||
-rw-r--r-- | Kbuild | 2 | ||||
-rw-r--r-- | Makefile | 134 | ||||
-rw-r--r-- | scripts/Kbuild.include | 93 | ||||
-rw-r--r-- | scripts/Makefile | 5 | ||||
-rw-r--r-- | scripts/Makefile.build | 5 | ||||
-rw-r--r-- | scripts/Makefile.headersinst | 2 | ||||
-rw-r--r-- | scripts/Makefile.host | 20 | ||||
-rw-r--r-- | scripts/Makefile.modpost | 13 | ||||
-rw-r--r-- | scripts/kconfig/Makefile | 1 | ||||
-rw-r--r-- | scripts/kconfig/confdata.c | 8 | ||||
-rw-r--r-- | scripts/mod/modpost.c | 42 | ||||
-rwxr-xr-x | scripts/package/mkspec | 4 | ||||
-rw-r--r-- | scripts/unifdef.c | 1005 | ||||
-rw-r--r-- | usr/Makefile | 2 |
20 files changed, 1471 insertions, 319 deletions
diff --git a/Documentation/Changes b/Documentation/Changes index 488272074c36..abee7f58c1ed 100644 --- a/Documentation/Changes +++ b/Documentation/Changes | |||
@@ -37,15 +37,14 @@ o e2fsprogs 1.29 # tune2fs | |||
37 | o jfsutils 1.1.3 # fsck.jfs -V | 37 | o jfsutils 1.1.3 # fsck.jfs -V |
38 | o reiserfsprogs 3.6.3 # reiserfsck -V 2>&1|grep reiserfsprogs | 38 | o reiserfsprogs 3.6.3 # reiserfsck -V 2>&1|grep reiserfsprogs |
39 | o xfsprogs 2.6.0 # xfs_db -V | 39 | o xfsprogs 2.6.0 # xfs_db -V |
40 | o pcmciautils 004 | 40 | o pcmciautils 004 # pccardctl -V |
41 | o pcmcia-cs 3.1.21 # cardmgr -V | ||
42 | o quota-tools 3.09 # quota -V | 41 | o quota-tools 3.09 # quota -V |
43 | o PPP 2.4.0 # pppd --version | 42 | o PPP 2.4.0 # pppd --version |
44 | o isdn4k-utils 3.1pre1 # isdnctrl 2>&1|grep version | 43 | o isdn4k-utils 3.1pre1 # isdnctrl 2>&1|grep version |
45 | o nfs-utils 1.0.5 # showmount --version | 44 | o nfs-utils 1.0.5 # showmount --version |
46 | o procps 3.2.0 # ps --version | 45 | o procps 3.2.0 # ps --version |
47 | o oprofile 0.9 # oprofiled --version | 46 | o oprofile 0.9 # oprofiled --version |
48 | o udev 071 # udevinfo -V | 47 | o udev 081 # udevinfo -V |
49 | 48 | ||
50 | Kernel compilation | 49 | Kernel compilation |
51 | ================== | 50 | ================== |
@@ -268,7 +267,7 @@ active clients. | |||
268 | 267 | ||
269 | To enable this new functionality, you need to: | 268 | To enable this new functionality, you need to: |
270 | 269 | ||
271 | mount -t nfsd nfsd /proc/fs/nfs | 270 | mount -t nfsd nfsd /proc/fs/nfsd |
272 | 271 | ||
273 | before running exportfs or mountd. It is recommended that all NFS | 272 | before running exportfs or mountd. It is recommended that all NFS |
274 | services be protected from the internet-at-large by a firewall where | 273 | services be protected from the internet-at-large by a firewall where |
diff --git a/Documentation/dontdiff b/Documentation/dontdiff index 24adfe9af3ca..63c2d0c55aa2 100644 --- a/Documentation/dontdiff +++ b/Documentation/dontdiff | |||
@@ -135,6 +135,7 @@ tags | |||
135 | times.h* | 135 | times.h* |
136 | tkparse | 136 | tkparse |
137 | trix_boot.h | 137 | trix_boot.h |
138 | utsrelease.h* | ||
138 | version.h* | 139 | version.h* |
139 | vmlinux | 140 | vmlinux |
140 | vmlinux-* | 141 | vmlinux-* |
diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index ca1967f36423..003fccc14d24 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt | |||
@@ -67,19 +67,19 @@ applicable everywhere (see syntax). | |||
67 | - default value: "default" <expr> ["if" <expr>] | 67 | - default value: "default" <expr> ["if" <expr>] |
68 | A config option can have any number of default values. If multiple | 68 | A config option can have any number of default values. If multiple |
69 | default values are visible, only the first defined one is active. | 69 | default values are visible, only the first defined one is active. |
70 | Default values are not limited to the menu entry, where they are | 70 | Default values are not limited to the menu entry where they are |
71 | defined, this means the default can be defined somewhere else or be | 71 | defined. This means the default can be defined somewhere else or be |
72 | overridden by an earlier definition. | 72 | overridden by an earlier definition. |
73 | The default value is only assigned to the config symbol if no other | 73 | The default value is only assigned to the config symbol if no other |
74 | value was set by the user (via the input prompt above). If an input | 74 | value was set by the user (via the input prompt above). If an input |
75 | prompt is visible the default value is presented to the user and can | 75 | prompt is visible the default value is presented to the user and can |
76 | be overridden by him. | 76 | be overridden by him. |
77 | Optionally dependencies only for this default value can be added with | 77 | Optionally, dependencies only for this default value can be added with |
78 | "if". | 78 | "if". |
79 | 79 | ||
80 | - dependencies: "depends on"/"requires" <expr> | 80 | - dependencies: "depends on"/"requires" <expr> |
81 | This defines a dependency for this menu entry. If multiple | 81 | This defines a dependency for this menu entry. If multiple |
82 | dependencies are defined they are connected with '&&'. Dependencies | 82 | dependencies are defined, they are connected with '&&'. Dependencies |
83 | are applied to all other options within this menu entry (which also | 83 | are applied to all other options within this menu entry (which also |
84 | accept an "if" expression), so these two examples are equivalent: | 84 | accept an "if" expression), so these two examples are equivalent: |
85 | 85 | ||
@@ -153,7 +153,7 @@ Nonconstant symbols are the most common ones and are defined with the | |||
153 | 'config' statement. Nonconstant symbols consist entirely of alphanumeric | 153 | 'config' statement. Nonconstant symbols consist entirely of alphanumeric |
154 | characters or underscores. | 154 | characters or underscores. |
155 | Constant symbols are only part of expressions. Constant symbols are | 155 | Constant symbols are only part of expressions. Constant symbols are |
156 | always surrounded by single or double quotes. Within the quote any | 156 | always surrounded by single or double quotes. Within the quote, any |
157 | other character is allowed and the quotes can be escaped using '\'. | 157 | other character is allowed and the quotes can be escaped using '\'. |
158 | 158 | ||
159 | Menu structure | 159 | Menu structure |
@@ -237,7 +237,7 @@ choices: | |||
237 | <choice block> | 237 | <choice block> |
238 | "endchoice" | 238 | "endchoice" |
239 | 239 | ||
240 | This defines a choice group and accepts any of above attributes as | 240 | This defines a choice group and accepts any of the above attributes as |
241 | options. A choice can only be of type bool or tristate, while a boolean | 241 | options. A choice can only be of type bool or tristate, while a boolean |
242 | choice only allows a single config entry to be selected, a tristate | 242 | choice only allows a single config entry to be selected, a tristate |
243 | choice also allows any number of config entries to be set to 'm'. This | 243 | choice also allows any number of config entries to be set to 'm'. This |
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 0706699c9da9..b7d6abb501a6 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt | |||
@@ -22,7 +22,7 @@ This document describes the Linux kernel Makefiles. | |||
22 | === 4 Host Program support | 22 | === 4 Host Program support |
23 | --- 4.1 Simple Host Program | 23 | --- 4.1 Simple Host Program |
24 | --- 4.2 Composite Host Programs | 24 | --- 4.2 Composite Host Programs |
25 | --- 4.3 Defining shared libraries | 25 | --- 4.3 Defining shared libraries |
26 | --- 4.4 Using C++ for host programs | 26 | --- 4.4 Using C++ for host programs |
27 | --- 4.5 Controlling compiler options for host programs | 27 | --- 4.5 Controlling compiler options for host programs |
28 | --- 4.6 When host programs are actually built | 28 | --- 4.6 When host programs are actually built |
@@ -69,7 +69,7 @@ architecture-specific information to the top Makefile. | |||
69 | 69 | ||
70 | Each subdirectory has a kbuild Makefile which carries out the commands | 70 | Each subdirectory has a kbuild Makefile which carries out the commands |
71 | passed down from above. The kbuild Makefile uses information from the | 71 | passed down from above. The kbuild Makefile uses information from the |
72 | .config file to construct various file lists used by kbuild to build | 72 | .config file to construct various file lists used by kbuild to build |
73 | any built-in or modular targets. | 73 | any built-in or modular targets. |
74 | 74 | ||
75 | scripts/Makefile.* contains all the definitions/rules etc. that | 75 | scripts/Makefile.* contains all the definitions/rules etc. that |
@@ -86,7 +86,7 @@ any kernel Makefiles (or any other source files). | |||
86 | 86 | ||
87 | *Normal developers* are people who work on features such as device | 87 | *Normal developers* are people who work on features such as device |
88 | drivers, file systems, and network protocols. These people need to | 88 | drivers, file systems, and network protocols. These people need to |
89 | maintain the kbuild Makefiles for the subsystem that they are | 89 | maintain the kbuild Makefiles for the subsystem they are |
90 | working on. In order to do this effectively, they need some overall | 90 | working on. In order to do this effectively, they need some overall |
91 | knowledge about the kernel Makefiles, plus detailed knowledge about the | 91 | knowledge about the kernel Makefiles, plus detailed knowledge about the |
92 | public interface for kbuild. | 92 | public interface for kbuild. |
@@ -104,10 +104,10 @@ This document is aimed towards normal developers and arch developers. | |||
104 | === 3 The kbuild files | 104 | === 3 The kbuild files |
105 | 105 | ||
106 | Most Makefiles within the kernel are kbuild Makefiles that use the | 106 | Most Makefiles within the kernel are kbuild Makefiles that use the |
107 | kbuild infrastructure. This chapter introduce the syntax used in the | 107 | kbuild infrastructure. This chapter introduces the syntax used in the |
108 | kbuild makefiles. | 108 | kbuild makefiles. |
109 | The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can | 109 | The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can |
110 | be used and if both a 'Makefile' and a 'Kbuild' file exists then the 'Kbuild' | 110 | be used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild' |
111 | file will be used. | 111 | file will be used. |
112 | 112 | ||
113 | Section 3.1 "Goal definitions" is a quick intro, further chapters provide | 113 | Section 3.1 "Goal definitions" is a quick intro, further chapters provide |
@@ -124,7 +124,7 @@ more details, with real examples. | |||
124 | Example: | 124 | Example: |
125 | obj-y += foo.o | 125 | obj-y += foo.o |
126 | 126 | ||
127 | This tell kbuild that there is one object in that directory named | 127 | This tell kbuild that there is one object in that directory, named |
128 | foo.o. foo.o will be built from foo.c or foo.S. | 128 | foo.o. foo.o will be built from foo.c or foo.S. |
129 | 129 | ||
130 | If foo.o shall be built as a module, the variable obj-m is used. | 130 | If foo.o shall be built as a module, the variable obj-m is used. |
@@ -140,7 +140,7 @@ more details, with real examples. | |||
140 | --- 3.2 Built-in object goals - obj-y | 140 | --- 3.2 Built-in object goals - obj-y |
141 | 141 | ||
142 | The kbuild Makefile specifies object files for vmlinux | 142 | The kbuild Makefile specifies object files for vmlinux |
143 | in the lists $(obj-y). These lists depend on the kernel | 143 | in the $(obj-y) lists. These lists depend on the kernel |
144 | configuration. | 144 | configuration. |
145 | 145 | ||
146 | Kbuild compiles all the $(obj-y) files. It then calls | 146 | Kbuild compiles all the $(obj-y) files. It then calls |
@@ -154,8 +154,8 @@ more details, with real examples. | |||
154 | Link order is significant, because certain functions | 154 | Link order is significant, because certain functions |
155 | (module_init() / __initcall) will be called during boot in the | 155 | (module_init() / __initcall) will be called during boot in the |
156 | order they appear. So keep in mind that changing the link | 156 | order they appear. So keep in mind that changing the link |
157 | order may e.g. change the order in which your SCSI | 157 | order may e.g. change the order in which your SCSI |
158 | controllers are detected, and thus you disks are renumbered. | 158 | controllers are detected, and thus your disks are renumbered. |
159 | 159 | ||
160 | Example: | 160 | Example: |
161 | #drivers/isdn/i4l/Makefile | 161 | #drivers/isdn/i4l/Makefile |
@@ -203,11 +203,11 @@ more details, with real examples. | |||
203 | Example: | 203 | Example: |
204 | #fs/ext2/Makefile | 204 | #fs/ext2/Makefile |
205 | obj-$(CONFIG_EXT2_FS) += ext2.o | 205 | obj-$(CONFIG_EXT2_FS) += ext2.o |
206 | ext2-y := balloc.o bitmap.o | 206 | ext2-y := balloc.o bitmap.o |
207 | ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o | 207 | ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o |
208 | 208 | ||
209 | In this example xattr.o is only part of the composite object | 209 | In this example, xattr.o is only part of the composite object |
210 | ext2.o, if $(CONFIG_EXT2_FS_XATTR) evaluates to 'y'. | 210 | ext2.o if $(CONFIG_EXT2_FS_XATTR) evaluates to 'y'. |
211 | 211 | ||
212 | Note: Of course, when you are building objects into the kernel, | 212 | Note: Of course, when you are building objects into the kernel, |
213 | the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, | 213 | the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, |
@@ -221,16 +221,16 @@ more details, with real examples. | |||
221 | 221 | ||
222 | --- 3.5 Library file goals - lib-y | 222 | --- 3.5 Library file goals - lib-y |
223 | 223 | ||
224 | Objects listed with obj-* are used for modules or | 224 | Objects listed with obj-* are used for modules, or |
225 | combined in a built-in.o for that specific directory. | 225 | combined in a built-in.o for that specific directory. |
226 | There is also the possibility to list objects that will | 226 | There is also the possibility to list objects that will |
227 | be included in a library, lib.a. | 227 | be included in a library, lib.a. |
228 | All objects listed with lib-y are combined in a single | 228 | All objects listed with lib-y are combined in a single |
229 | library for that directory. | 229 | library for that directory. |
230 | Objects that are listed in obj-y and additional listed in | 230 | Objects that are listed in obj-y and additionaly listed in |
231 | lib-y will not be included in the library, since they will anyway | 231 | lib-y will not be included in the library, since they will anyway |
232 | be accessible. | 232 | be accessible. |
233 | For consistency objects listed in lib-m will be included in lib.a. | 233 | For consistency, objects listed in lib-m will be included in lib.a. |
234 | 234 | ||
235 | Note that the same kbuild makefile may list files to be built-in | 235 | Note that the same kbuild makefile may list files to be built-in |
236 | and to be part of a library. Therefore the same directory | 236 | and to be part of a library. Therefore the same directory |
@@ -241,11 +241,11 @@ more details, with real examples. | |||
241 | lib-y := checksum.o delay.o | 241 | lib-y := checksum.o delay.o |
242 | 242 | ||
243 | This will create a library lib.a based on checksum.o and delay.o. | 243 | This will create a library lib.a based on checksum.o and delay.o. |
244 | For kbuild to actually recognize that there is a lib.a being build | 244 | For kbuild to actually recognize that there is a lib.a being built, |
245 | the directory shall be listed in libs-y. | 245 | the directory shall be listed in libs-y. |
246 | See also "6.3 List directories to visit when descending". | 246 | See also "6.3 List directories to visit when descending". |
247 | 247 | ||
248 | Usage of lib-y is normally restricted to lib/ and arch/*/lib. | 248 | Use of lib-y is normally restricted to lib/ and arch/*/lib. |
249 | 249 | ||
250 | --- 3.6 Descending down in directories | 250 | --- 3.6 Descending down in directories |
251 | 251 | ||
@@ -255,7 +255,7 @@ more details, with real examples. | |||
255 | invoke make recursively in subdirectories, provided you let it know of | 255 | invoke make recursively in subdirectories, provided you let it know of |
256 | them. | 256 | them. |
257 | 257 | ||
258 | To do so obj-y and obj-m are used. | 258 | To do so, obj-y and obj-m are used. |
259 | ext2 lives in a separate directory, and the Makefile present in fs/ | 259 | ext2 lives in a separate directory, and the Makefile present in fs/ |
260 | tells kbuild to descend down using the following assignment. | 260 | tells kbuild to descend down using the following assignment. |
261 | 261 | ||
@@ -353,8 +353,8 @@ more details, with real examples. | |||
353 | Special rules are used when the kbuild infrastructure does | 353 | Special rules are used when the kbuild infrastructure does |
354 | not provide the required support. A typical example is | 354 | not provide the required support. A typical example is |
355 | header files generated during the build process. | 355 | header files generated during the build process. |
356 | Another example is the architecture specific Makefiles which | 356 | Another example are the architecture specific Makefiles which |
357 | needs special rules to prepare boot images etc. | 357 | need special rules to prepare boot images etc. |
358 | 358 | ||
359 | Special rules are written as normal Make rules. | 359 | Special rules are written as normal Make rules. |
360 | Kbuild is not executing in the directory where the Makefile is | 360 | Kbuild is not executing in the directory where the Makefile is |
@@ -387,28 +387,28 @@ more details, with real examples. | |||
387 | 387 | ||
388 | --- 3.11 $(CC) support functions | 388 | --- 3.11 $(CC) support functions |
389 | 389 | ||
390 | The kernel may be build with several different versions of | 390 | The kernel may be built with several different versions of |
391 | $(CC), each supporting a unique set of features and options. | 391 | $(CC), each supporting a unique set of features and options. |
392 | kbuild provide basic support to check for valid options for $(CC). | 392 | kbuild provide basic support to check for valid options for $(CC). |
393 | $(CC) is useally the gcc compiler, but other alternatives are | 393 | $(CC) is useally the gcc compiler, but other alternatives are |
394 | available. | 394 | available. |
395 | 395 | ||
396 | as-option | 396 | as-option |
397 | as-option is used to check if $(CC) when used to compile | 397 | as-option is used to check if $(CC) -- when used to compile |
398 | assembler (*.S) files supports the given option. An optional | 398 | assembler (*.S) files -- supports the given option. An optional |
399 | second option may be specified if first option are not supported. | 399 | second option may be specified if the first option is not supported. |
400 | 400 | ||
401 | Example: | 401 | Example: |
402 | #arch/sh/Makefile | 402 | #arch/sh/Makefile |
403 | cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) | 403 | cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),) |
404 | 404 | ||
405 | In the above example cflags-y will be assinged the the option | 405 | In the above example, cflags-y will be assigned the option |
406 | -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). | 406 | -Wa$(comma)-isa=$(isa-y) if it is supported by $(CC). |
407 | The second argument is optional, and if supplied will be used | 407 | The second argument is optional, and if supplied will be used |
408 | if first argument is not supported. | 408 | if first argument is not supported. |
409 | 409 | ||
410 | ld-option | 410 | ld-option |
411 | ld-option is used to check if $(CC) when used to link object files | 411 | ld-option is used to check if $(CC) when used to link object files |
412 | supports the given option. An optional second option may be | 412 | supports the given option. An optional second option may be |
413 | specified if first option are not supported. | 413 | specified if first option are not supported. |
414 | 414 | ||
@@ -422,7 +422,7 @@ more details, with real examples. | |||
422 | if first argument is not supported. | 422 | if first argument is not supported. |
423 | 423 | ||
424 | cc-option | 424 | cc-option |
425 | cc-option is used to check if $(CC) support a given option, and not | 425 | cc-option is used to check if $(CC) supports a given option, and not |
426 | supported to use an optional second option. | 426 | supported to use an optional second option. |
427 | 427 | ||
428 | Example: | 428 | Example: |
@@ -430,12 +430,12 @@ more details, with real examples. | |||
430 | cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) | 430 | cflags-y += $(call cc-option,-march=pentium-mmx,-march=i586) |
431 | 431 | ||
432 | In the above example cflags-y will be assigned the option | 432 | In the above example cflags-y will be assigned the option |
433 | -march=pentium-mmx if supported by $(CC), otherwise -march-i586. | 433 | -march=pentium-mmx if supported by $(CC), otherwise -march=i586. |
434 | The second argument to cc-option is optional, and if omitted | 434 | The second argument to cc-option is optional, and if omitted, |
435 | cflags-y will be assigned no value if first option is not supported. | 435 | cflags-y will be assigned no value if first option is not supported. |
436 | 436 | ||
437 | cc-option-yn | 437 | cc-option-yn |
438 | cc-option-yn is used to check if gcc supports a given option | 438 | cc-option-yn is used to check if gcc supports a given option |
439 | and return 'y' if supported, otherwise 'n'. | 439 | and return 'y' if supported, otherwise 'n'. |
440 | 440 | ||
441 | Example: | 441 | Example: |
@@ -443,32 +443,33 @@ more details, with real examples. | |||
443 | biarch := $(call cc-option-yn, -m32) | 443 | biarch := $(call cc-option-yn, -m32) |
444 | aflags-$(biarch) += -a32 | 444 | aflags-$(biarch) += -a32 |
445 | cflags-$(biarch) += -m32 | 445 | cflags-$(biarch) += -m32 |
446 | 446 | ||
447 | In the above example $(biarch) is set to y if $(CC) supports the -m32 | 447 | In the above example, $(biarch) is set to y if $(CC) supports the -m32 |
448 | option. When $(biarch) equals to y the expanded variables $(aflags-y) | 448 | option. When $(biarch) equals 'y', the expanded variables $(aflags-y) |
449 | and $(cflags-y) will be assigned the values -a32 and -m32. | 449 | and $(cflags-y) will be assigned the values -a32 and -m32, |
450 | respectively. | ||
450 | 451 | ||
451 | cc-option-align | 452 | cc-option-align |
452 | gcc version >= 3.0 shifted type of options used to speify | 453 | gcc versions >= 3.0 changed the type of options used to specify |
453 | alignment of functions, loops etc. $(cc-option-align) whrn used | 454 | alignment of functions, loops etc. $(cc-option-align), when used |
454 | as prefix to the align options will select the right prefix: | 455 | as prefix to the align options, will select the right prefix: |
455 | gcc < 3.00 | 456 | gcc < 3.00 |
456 | cc-option-align = -malign | 457 | cc-option-align = -malign |
457 | gcc >= 3.00 | 458 | gcc >= 3.00 |
458 | cc-option-align = -falign | 459 | cc-option-align = -falign |
459 | 460 | ||
460 | Example: | 461 | Example: |
461 | CFLAGS += $(cc-option-align)-functions=4 | 462 | CFLAGS += $(cc-option-align)-functions=4 |
462 | 463 | ||
463 | In the above example the option -falign-functions=4 is used for | 464 | In the above example, the option -falign-functions=4 is used for |
464 | gcc >= 3.00. For gcc < 3.00 -malign-functions=4 is used. | 465 | gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used. |
465 | 466 | ||
466 | cc-version | 467 | cc-version |
467 | cc-version return a numerical version of the $(CC) compiler version. | 468 | cc-version returns a numerical version of the $(CC) compiler version. |
468 | The format is <major><minor> where both are two digits. So for example | 469 | The format is <major><minor> where both are two digits. So for example |
469 | gcc 3.41 would return 0341. | 470 | gcc 3.41 would return 0341. |
470 | cc-version is useful when a specific $(CC) version is faulty in one | 471 | cc-version is useful when a specific $(CC) version is faulty in one |
471 | area, for example the -mregparm=3 were broken in some gcc version | 472 | area, for example -mregparm=3 was broken in some gcc versions |
472 | even though the option was accepted by gcc. | 473 | even though the option was accepted by gcc. |
473 | 474 | ||
474 | Example: | 475 | Example: |
@@ -477,20 +478,20 @@ more details, with real examples. | |||
477 | if [ $(call cc-version) -ge 0300 ] ; then \ | 478 | if [ $(call cc-version) -ge 0300 ] ; then \ |
478 | echo "-mregparm=3"; fi ;) | 479 | echo "-mregparm=3"; fi ;) |
479 | 480 | ||
480 | In the above example -mregparm=3 is only used for gcc version greater | 481 | In the above example, -mregparm=3 is only used for gcc version greater |
481 | than or equal to gcc 3.0. | 482 | than or equal to gcc 3.0. |
482 | 483 | ||
483 | cc-ifversion | 484 | cc-ifversion |
484 | cc-ifversion test the version of $(CC) and equals last argument if | 485 | cc-ifversion tests the version of $(CC) and equals last argument if |
485 | version expression is true. | 486 | version expression is true. |
486 | 487 | ||
487 | Example: | 488 | Example: |
488 | #fs/reiserfs/Makefile | 489 | #fs/reiserfs/Makefile |
489 | EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1) | 490 | EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1) |
490 | 491 | ||
491 | In this example EXTRA_CFLAGS will be assigned the value -O1 if the | 492 | In this example, EXTRA_CFLAGS will be assigned the value -O1 if the |
492 | $(CC) version is less than 4.2. | 493 | $(CC) version is less than 4.2. |
493 | cc-ifversion takes all the shell operators: | 494 | cc-ifversion takes all the shell operators: |
494 | -eq, -ne, -lt, -le, -gt, and -ge | 495 | -eq, -ne, -lt, -le, -gt, and -ge |
495 | The third parameter may be a text as in this example, but it may also | 496 | The third parameter may be a text as in this example, but it may also |
496 | be an expanded variable or a macro. | 497 | be an expanded variable or a macro. |
@@ -506,7 +507,7 @@ The first step is to tell kbuild that a host program exists. This is | |||
506 | done utilising the variable hostprogs-y. | 507 | done utilising the variable hostprogs-y. |
507 | 508 | ||
508 | The second step is to add an explicit dependency to the executable. | 509 | The second step is to add an explicit dependency to the executable. |
509 | This can be done in two ways. Either add the dependency in a rule, | 510 | This can be done in two ways. Either add the dependency in a rule, |
510 | or utilise the variable $(always). | 511 | or utilise the variable $(always). |
511 | Both possibilities are described in the following. | 512 | Both possibilities are described in the following. |
512 | 513 | ||
@@ -523,28 +524,28 @@ Both possibilities are described in the following. | |||
523 | Kbuild assumes in the above example that bin2hex is made from a single | 524 | Kbuild assumes in the above example that bin2hex is made from a single |
524 | c-source file named bin2hex.c located in the same directory as | 525 | c-source file named bin2hex.c located in the same directory as |
525 | the Makefile. | 526 | the Makefile. |
526 | 527 | ||
527 | --- 4.2 Composite Host Programs | 528 | --- 4.2 Composite Host Programs |
528 | 529 | ||
529 | Host programs can be made up based on composite objects. | 530 | Host programs can be made up based on composite objects. |
530 | The syntax used to define composite objects for host programs is | 531 | The syntax used to define composite objects for host programs is |
531 | similar to the syntax used for kernel objects. | 532 | similar to the syntax used for kernel objects. |
532 | $(<executeable>-objs) list all objects used to link the final | 533 | $(<executeable>-objs) lists all objects used to link the final |
533 | executable. | 534 | executable. |
534 | 535 | ||
535 | Example: | 536 | Example: |
536 | #scripts/lxdialog/Makefile | 537 | #scripts/lxdialog/Makefile |
537 | hostprogs-y := lxdialog | 538 | hostprogs-y := lxdialog |
538 | lxdialog-objs := checklist.o lxdialog.o | 539 | lxdialog-objs := checklist.o lxdialog.o |
539 | 540 | ||
540 | Objects with extension .o are compiled from the corresponding .c | 541 | Objects with extension .o are compiled from the corresponding .c |
541 | files. In the above example checklist.c is compiled to checklist.o | 542 | files. In the above example, checklist.c is compiled to checklist.o |
542 | and lxdialog.c is compiled to lxdialog.o. | 543 | and lxdialog.c is compiled to lxdialog.o. |
543 | Finally the two .o files are linked to the executable, lxdialog. | 544 | Finally, the two .o files are linked to the executable, lxdialog. |
544 | Note: The syntax <executable>-y is not permitted for host-programs. | 545 | Note: The syntax <executable>-y is not permitted for host-programs. |
545 | 546 | ||
546 | --- 4.3 Defining shared libraries | 547 | --- 4.3 Defining shared libraries |
547 | 548 | ||
548 | Objects with extension .so are considered shared libraries, and | 549 | Objects with extension .so are considered shared libraries, and |
549 | will be compiled as position independent objects. | 550 | will be compiled as position independent objects. |
550 | Kbuild provides support for shared libraries, but the usage | 551 | Kbuild provides support for shared libraries, but the usage |
@@ -557,7 +558,7 @@ Both possibilities are described in the following. | |||
557 | hostprogs-y := conf | 558 | hostprogs-y := conf |
558 | conf-objs := conf.o libkconfig.so | 559 | conf-objs := conf.o libkconfig.so |
559 | libkconfig-objs := expr.o type.o | 560 | libkconfig-objs := expr.o type.o |
560 | 561 | ||
561 | Shared libraries always require a corresponding -objs line, and | 562 | Shared libraries always require a corresponding -objs line, and |
562 | in the example above the shared library libkconfig is composed by | 563 | in the example above the shared library libkconfig is composed by |
563 | the two objects expr.o and type.o. | 564 | the two objects expr.o and type.o. |
@@ -578,7 +579,7 @@ Both possibilities are described in the following. | |||
578 | 579 | ||
579 | In the example above the executable is composed of the C++ file | 580 | In the example above the executable is composed of the C++ file |
580 | qconf.cc - identified by $(qconf-cxxobjs). | 581 | qconf.cc - identified by $(qconf-cxxobjs). |
581 | 582 | ||
582 | If qconf is composed by a mixture of .c and .cc files, then an | 583 | If qconf is composed by a mixture of .c and .cc files, then an |
583 | additional line can be used to identify this. | 584 | additional line can be used to identify this. |
584 | 585 | ||
@@ -587,34 +588,35 @@ Both possibilities are described in the following. | |||
587 | hostprogs-y := qconf | 588 | hostprogs-y := qconf |
588 | qconf-cxxobjs := qconf.o | 589 | qconf-cxxobjs := qconf.o |
589 | qconf-objs := check.o | 590 | qconf-objs := check.o |
590 | 591 | ||
591 | --- 4.5 Controlling compiler options for host programs | 592 | --- 4.5 Controlling compiler options for host programs |
592 | 593 | ||
593 | When compiling host programs, it is possible to set specific flags. | 594 | When compiling host programs, it is possible to set specific flags. |
594 | The programs will always be compiled utilising $(HOSTCC) passed | 595 | The programs will always be compiled utilising $(HOSTCC) passed |
595 | the options specified in $(HOSTCFLAGS). | 596 | the options specified in $(HOSTCFLAGS). |
596 | To set flags that will take effect for all host programs created | 597 | To set flags that will take effect for all host programs created |
597 | in that Makefile use the variable HOST_EXTRACFLAGS. | 598 | in that Makefile, use the variable HOST_EXTRACFLAGS. |
598 | 599 | ||
599 | Example: | 600 | Example: |
600 | #scripts/lxdialog/Makefile | 601 | #scripts/lxdialog/Makefile |
601 | HOST_EXTRACFLAGS += -I/usr/include/ncurses | 602 | HOST_EXTRACFLAGS += -I/usr/include/ncurses |
602 | 603 | ||
603 | To set specific flags for a single file the following construction | 604 | To set specific flags for a single file the following construction |
604 | is used: | 605 | is used: |
605 | 606 | ||
606 | Example: | 607 | Example: |
607 | #arch/ppc64/boot/Makefile | 608 | #arch/ppc64/boot/Makefile |
608 | HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) | 609 | HOSTCFLAGS_piggyback.o := -DKERNELBASE=$(KERNELBASE) |
609 | 610 | ||
610 | It is also possible to specify additional options to the linker. | 611 | It is also possible to specify additional options to the linker. |
611 | 612 | ||
612 | Example: | 613 | Example: |
613 | #scripts/kconfig/Makefile | 614 | #scripts/kconfig/Makefile |
614 | HOSTLOADLIBES_qconf := -L$(QTDIR)/lib | 615 | HOSTLOADLIBES_qconf := -L$(QTDIR)/lib |
615 | 616 | ||
616 | When linking qconf it will be passed the extra option "-L$(QTDIR)/lib". | 617 | When linking qconf, it will be passed the extra option |
617 | 618 | "-L$(QTDIR)/lib". | |
619 | |||
618 | --- 4.6 When host programs are actually built | 620 | --- 4.6 When host programs are actually built |
619 | 621 | ||
620 | Kbuild will only build host-programs when they are referenced | 622 | Kbuild will only build host-programs when they are referenced |
@@ -629,7 +631,7 @@ Both possibilities are described in the following. | |||
629 | $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist | 631 | $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist |
630 | ( cd $(obj); ./gen-devlist ) < $< | 632 | ( cd $(obj); ./gen-devlist ) < $< |
631 | 633 | ||
632 | The target $(obj)/devlist.h will not be built before | 634 | The target $(obj)/devlist.h will not be built before |
633 | $(obj)/gen-devlist is updated. Note that references to | 635 | $(obj)/gen-devlist is updated. Note that references to |
634 | the host programs in special rules must be prefixed with $(obj). | 636 | the host programs in special rules must be prefixed with $(obj). |
635 | 637 | ||
@@ -648,7 +650,7 @@ Both possibilities are described in the following. | |||
648 | 650 | ||
649 | --- 4.7 Using hostprogs-$(CONFIG_FOO) | 651 | --- 4.7 Using hostprogs-$(CONFIG_FOO) |
650 | 652 | ||
651 | A typcal pattern in a Kbuild file lok like this: | 653 | A typical pattern in a Kbuild file looks like this: |
652 | 654 | ||
653 | Example: | 655 | Example: |
654 | #scripts/Makefile | 656 | #scripts/Makefile |
@@ -656,13 +658,13 @@ Both possibilities are described in the following. | |||
656 | 658 | ||
657 | Kbuild knows about both 'y' for built-in and 'm' for module. | 659 | Kbuild knows about both 'y' for built-in and 'm' for module. |
658 | So if a config symbol evaluate to 'm', kbuild will still build | 660 | So if a config symbol evaluate to 'm', kbuild will still build |
659 | the binary. In other words Kbuild handle hostprogs-m exactly | 661 | the binary. In other words, Kbuild handles hostprogs-m exactly |
660 | like hostprogs-y. But only hostprogs-y is recommend used | 662 | like hostprogs-y. But only hostprogs-y is recommended to be used |
661 | when no CONFIG symbol are involved. | 663 | when no CONFIG symbols are involved. |
662 | 664 | ||
663 | === 5 Kbuild clean infrastructure | 665 | === 5 Kbuild clean infrastructure |
664 | 666 | ||
665 | "make clean" deletes most generated files in the src tree where the kernel | 667 | "make clean" deletes most generated files in the obj tree where the kernel |
666 | is compiled. This includes generated files such as host programs. | 668 | is compiled. This includes generated files such as host programs. |
667 | Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always), | 669 | Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always), |
668 | $(extra-y) and $(targets). They are all deleted during "make clean". | 670 | $(extra-y) and $(targets). They are all deleted during "make clean". |
@@ -680,7 +682,8 @@ When executing "make clean", the two files "devlist.h classlist.h" will | |||
680 | be deleted. Kbuild will assume files to be in same relative directory as the | 682 | be deleted. Kbuild will assume files to be in same relative directory as the |
681 | Makefile except if an absolute path is specified (path starting with '/'). | 683 | Makefile except if an absolute path is specified (path starting with '/'). |
682 | 684 | ||
683 | To delete a directory hirachy use: | 685 | To delete a directory hierarchy use: |
686 | |||
684 | Example: | 687 | Example: |
685 | #scripts/package/Makefile | 688 | #scripts/package/Makefile |
686 | clean-dirs := $(objtree)/debian/ | 689 | clean-dirs := $(objtree)/debian/ |
@@ -723,29 +726,29 @@ be visited during "make clean". | |||
723 | 726 | ||
724 | The top level Makefile sets up the environment and does the preparation, | 727 | The top level Makefile sets up the environment and does the preparation, |
725 | before starting to descend down in the individual directories. | 728 | before starting to descend down in the individual directories. |
726 | The top level makefile contains the generic part, whereas the | 729 | The top level makefile contains the generic part, whereas |
727 | arch/$(ARCH)/Makefile contains what is required to set-up kbuild | 730 | arch/$(ARCH)/Makefile contains what is required to set up kbuild |
728 | to the said architecture. | 731 | for said architecture. |
729 | To do so arch/$(ARCH)/Makefile sets a number of variables, and defines | 732 | To do so, arch/$(ARCH)/Makefile sets up a number of variables and defines |
730 | a few targets. | 733 | a few targets. |
731 | 734 | ||
732 | When kbuild executes the following steps are followed (roughly): | 735 | When kbuild executes, the following steps are followed (roughly): |
733 | 1) Configuration of the kernel => produced .config | 736 | 1) Configuration of the kernel => produce .config |
734 | 2) Store kernel version in include/linux/version.h | 737 | 2) Store kernel version in include/linux/version.h |
735 | 3) Symlink include/asm to include/asm-$(ARCH) | 738 | 3) Symlink include/asm to include/asm-$(ARCH) |
736 | 4) Updating all other prerequisites to the target prepare: | 739 | 4) Updating all other prerequisites to the target prepare: |
737 | - Additional prerequisites are specified in arch/$(ARCH)/Makefile | 740 | - Additional prerequisites are specified in arch/$(ARCH)/Makefile |
738 | 5) Recursively descend down in all directories listed in | 741 | 5) Recursively descend down in all directories listed in |
739 | init-* core* drivers-* net-* libs-* and build all targets. | 742 | init-* core* drivers-* net-* libs-* and build all targets. |
740 | - The value of the above variables are extended in arch/$(ARCH)/Makefile. | 743 | - The values of the above variables are expanded in arch/$(ARCH)/Makefile. |
741 | 6) All object files are then linked and the resulting file vmlinux is | 744 | 6) All object files are then linked and the resulting file vmlinux is |
742 | located at the root of the src tree. | 745 | located at the root of the obj tree. |
743 | The very first objects linked are listed in head-y, assigned by | 746 | The very first objects linked are listed in head-y, assigned by |
744 | arch/$(ARCH)/Makefile. | 747 | arch/$(ARCH)/Makefile. |
745 | 7) Finally the architecture specific part does any required post processing | 748 | 7) Finally, the architecture specific part does any required post processing |
746 | and builds the final bootimage. | 749 | and builds the final bootimage. |
747 | - This includes building boot records | 750 | - This includes building boot records |
748 | - Preparing initrd images and the like | 751 | - Preparing initrd images and thelike |
749 | 752 | ||
750 | 753 | ||
751 | --- 6.1 Set variables to tweak the build to the architecture | 754 | --- 6.1 Set variables to tweak the build to the architecture |
@@ -760,7 +763,7 @@ When kbuild executes the following steps are followed (roughly): | |||
760 | LDFLAGS := -m elf_s390 | 763 | LDFLAGS := -m elf_s390 |
761 | Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise | 764 | Note: EXTRA_LDFLAGS and LDFLAGS_$@ can be used to further customise |
762 | the flags used. See chapter 7. | 765 | the flags used. See chapter 7. |
763 | 766 | ||
764 | LDFLAGS_MODULE Options for $(LD) when linking modules | 767 | LDFLAGS_MODULE Options for $(LD) when linking modules |
765 | 768 | ||
766 | LDFLAGS_MODULE is used to set specific flags for $(LD) when | 769 | LDFLAGS_MODULE is used to set specific flags for $(LD) when |
@@ -770,7 +773,7 @@ When kbuild executes the following steps are followed (roughly): | |||
770 | LDFLAGS_vmlinux Options for $(LD) when linking vmlinux | 773 | LDFLAGS_vmlinux Options for $(LD) when linking vmlinux |
771 | 774 | ||
772 | LDFLAGS_vmlinux is used to specify additional flags to pass to | 775 | LDFLAGS_vmlinux is used to specify additional flags to pass to |
773 | the linker when linking the final vmlinux. | 776 | the linker when linking the final vmlinux image. |
774 | LDFLAGS_vmlinux uses the LDFLAGS_$@ support. | 777 | LDFLAGS_vmlinux uses the LDFLAGS_$@ support. |
775 | 778 | ||
776 | Example: | 779 | Example: |
@@ -780,7 +783,7 @@ When kbuild executes the following steps are followed (roughly): | |||
780 | OBJCOPYFLAGS objcopy flags | 783 | OBJCOPYFLAGS objcopy flags |
781 | 784 | ||
782 | When $(call if_changed,objcopy) is used to translate a .o file, | 785 | When $(call if_changed,objcopy) is used to translate a .o file, |
783 | then the flags specified in OBJCOPYFLAGS will be used. | 786 | the flags specified in OBJCOPYFLAGS will be used. |
784 | $(call if_changed,objcopy) is often used to generate raw binaries on | 787 | $(call if_changed,objcopy) is often used to generate raw binaries on |
785 | vmlinux. | 788 | vmlinux. |
786 | 789 | ||
@@ -792,7 +795,7 @@ When kbuild executes the following steps are followed (roughly): | |||
792 | $(obj)/image: vmlinux FORCE | 795 | $(obj)/image: vmlinux FORCE |
793 | $(call if_changed,objcopy) | 796 | $(call if_changed,objcopy) |
794 | 797 | ||
795 | In this example the binary $(obj)/image is a binary version of | 798 | In this example, the binary $(obj)/image is a binary version of |
796 | vmlinux. The usage of $(call if_changed,xxx) will be described later. | 799 | vmlinux. The usage of $(call if_changed,xxx) will be described later. |
797 | 800 | ||
798 | AFLAGS $(AS) assembler flags | 801 | AFLAGS $(AS) assembler flags |
@@ -809,7 +812,7 @@ When kbuild executes the following steps are followed (roughly): | |||
809 | Default value - see top level Makefile | 812 | Default value - see top level Makefile |
810 | Append or modify as required per architecture. | 813 | Append or modify as required per architecture. |
811 | 814 | ||
812 | Often the CFLAGS variable depends on the configuration. | 815 | Often, the CFLAGS variable depends on the configuration. |
813 | 816 | ||
814 | Example: | 817 | Example: |
815 | #arch/i386/Makefile | 818 | #arch/i386/Makefile |
@@ -830,7 +833,7 @@ When kbuild executes the following steps are followed (roughly): | |||
830 | ... | 833 | ... |
831 | 834 | ||
832 | 835 | ||
833 | The first examples utilises the trick that a config option expands | 836 | The first example utilises the trick that a config option expands |
834 | to 'y' when selected. | 837 | to 'y' when selected. |
835 | 838 | ||
836 | CFLAGS_KERNEL $(CC) options specific for built-in | 839 | CFLAGS_KERNEL $(CC) options specific for built-in |
@@ -843,18 +846,18 @@ When kbuild executes the following steps are followed (roughly): | |||
843 | $(CFLAGS_MODULE) contains extra C compiler flags used to compile code | 846 | $(CFLAGS_MODULE) contains extra C compiler flags used to compile code |
844 | for loadable kernel modules. | 847 | for loadable kernel modules. |
845 | 848 | ||
846 | 849 | ||
847 | --- 6.2 Add prerequisites to archprepare: | 850 | --- 6.2 Add prerequisites to archprepare: |
848 | 851 | ||
849 | The archprepare: rule is used to list prerequisites that needs to be | 852 | The archprepare: rule is used to list prerequisites that need to be |
850 | built before starting to descend down in the subdirectories. | 853 | built before starting to descend down in the subdirectories. |
851 | This is usual header files containing assembler constants. | 854 | This is usually used for header files containing assembler constants. |
852 | 855 | ||
853 | Example: | 856 | Example: |
854 | #arch/arm/Makefile | 857 | #arch/arm/Makefile |
855 | archprepare: maketools | 858 | archprepare: maketools |
856 | 859 | ||
857 | In this example the file target maketools will be processed | 860 | In this example, the file target maketools will be processed |
858 | before descending down in the subdirectories. | 861 | before descending down in the subdirectories. |
859 | See also chapter XXX-TODO that describe how kbuild supports | 862 | See also chapter XXX-TODO that describe how kbuild supports |
860 | generating offset header files. | 863 | generating offset header files. |
@@ -867,18 +870,19 @@ When kbuild executes the following steps are followed (roughly): | |||
867 | corresponding arch-specific section for modules; the module-building | 870 | corresponding arch-specific section for modules; the module-building |
868 | machinery is all architecture-independent. | 871 | machinery is all architecture-independent. |
869 | 872 | ||
870 | 873 | ||
871 | head-y, init-y, core-y, libs-y, drivers-y, net-y | 874 | head-y, init-y, core-y, libs-y, drivers-y, net-y |
872 | 875 | ||
873 | $(head-y) list objects to be linked first in vmlinux. | 876 | $(head-y) lists objects to be linked first in vmlinux. |
874 | $(libs-y) list directories where a lib.a archive can be located. | 877 | $(libs-y) lists directories where a lib.a archive can be located. |
875 | The rest list directories where a built-in.o object file can be located. | 878 | The rest lists directories where a built-in.o object file can be |
879 | located. | ||
876 | 880 | ||
877 | $(init-y) objects will be located after $(head-y). | 881 | $(init-y) objects will be located after $(head-y). |
878 | Then the rest follows in this order: | 882 | Then the rest follows in this order: |
879 | $(core-y), $(libs-y), $(drivers-y) and $(net-y). | 883 | $(core-y), $(libs-y), $(drivers-y) and $(net-y). |
880 | 884 | ||
881 | The top level Makefile define values for all generic directories, | 885 | The top level Makefile defines values for all generic directories, |
882 | and arch/$(ARCH)/Makefile only adds architecture specific directories. | 886 | and arch/$(ARCH)/Makefile only adds architecture specific directories. |
883 | 887 | ||
884 | Example: | 888 | Example: |
@@ -915,27 +919,27 @@ When kbuild executes the following steps are followed (roughly): | |||
915 | "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke | 919 | "$(Q)$(MAKE) $(build)=<dir>" is the recommended way to invoke |
916 | make in a subdirectory. | 920 | make in a subdirectory. |
917 | 921 | ||
918 | There are no rules for naming of the architecture specific targets, | 922 | There are no rules for naming architecture specific targets, |
919 | but executing "make help" will list all relevant targets. | 923 | but executing "make help" will list all relevant targets. |
920 | To support this $(archhelp) must be defined. | 924 | To support this, $(archhelp) must be defined. |
921 | 925 | ||
922 | Example: | 926 | Example: |
923 | #arch/i386/Makefile | 927 | #arch/i386/Makefile |
924 | define archhelp | 928 | define archhelp |
925 | echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' | 929 | echo '* bzImage - Image (arch/$(ARCH)/boot/bzImage)' |
926 | endef | 930 | endif |
927 | 931 | ||
928 | When make is executed without arguments, the first goal encountered | 932 | When make is executed without arguments, the first goal encountered |
929 | will be built. In the top level Makefile the first goal present | 933 | will be built. In the top level Makefile the first goal present |
930 | is all:. | 934 | is all:. |
931 | An architecture shall always per default build a bootable image. | 935 | An architecture shall always, per default, build a bootable image. |
932 | In "make help" the default goal is highlighted with a '*'. | 936 | In "make help", the default goal is highlighted with a '*'. |
933 | Add a new prerequisite to all: to select a default goal different | 937 | Add a new prerequisite to all: to select a default goal different |
934 | from vmlinux. | 938 | from vmlinux. |
935 | 939 | ||
936 | Example: | 940 | Example: |
937 | #arch/i386/Makefile | 941 | #arch/i386/Makefile |
938 | all: bzImage | 942 | all: bzImage |
939 | 943 | ||
940 | When "make" is executed without arguments, bzImage will be built. | 944 | When "make" is executed without arguments, bzImage will be built. |
941 | 945 | ||
@@ -955,10 +959,10 @@ When kbuild executes the following steps are followed (roughly): | |||
955 | #arch/i386/kernel/Makefile | 959 | #arch/i386/kernel/Makefile |
956 | extra-y := head.o init_task.o | 960 | extra-y := head.o init_task.o |
957 | 961 | ||
958 | In this example extra-y is used to list object files that | 962 | In this example, extra-y is used to list object files that |
959 | shall be built, but shall not be linked as part of built-in.o. | 963 | shall be built, but shall not be linked as part of built-in.o. |
960 | 964 | ||
961 | 965 | ||
962 | --- 6.6 Commands useful for building a boot image | 966 | --- 6.6 Commands useful for building a boot image |
963 | 967 | ||
964 | Kbuild provides a few macros that are useful when building a | 968 | Kbuild provides a few macros that are useful when building a |
@@ -972,8 +976,8 @@ When kbuild executes the following steps are followed (roughly): | |||
972 | target: source(s) FORCE | 976 | target: source(s) FORCE |
973 | $(call if_changed,ld/objcopy/gzip) | 977 | $(call if_changed,ld/objcopy/gzip) |
974 | 978 | ||
975 | When the rule is evaluated it is checked to see if any files | 979 | When the rule is evaluated, it is checked to see if any files |
976 | needs an update, or the commandline has changed since last | 980 | needs an update, or the command line has changed since the last |
977 | invocation. The latter will force a rebuild if any options | 981 | invocation. The latter will force a rebuild if any options |
978 | to the executable have changed. | 982 | to the executable have changed. |
979 | Any target that utilises if_changed must be listed in $(targets), | 983 | Any target that utilises if_changed must be listed in $(targets), |
@@ -991,8 +995,8 @@ When kbuild executes the following steps are followed (roughly): | |||
991 | #WRONG!# $(call if_changed, ld/objcopy/gzip) | 995 | #WRONG!# $(call if_changed, ld/objcopy/gzip) |
992 | 996 | ||
993 | ld | 997 | ld |
994 | Link target. Often LDFLAGS_$@ is used to set specific options to ld. | 998 | Link target. Often, LDFLAGS_$@ is used to set specific options to ld. |
995 | 999 | ||
996 | objcopy | 1000 | objcopy |
997 | Copy binary. Uses OBJCOPYFLAGS usually specified in | 1001 | Copy binary. Uses OBJCOPYFLAGS usually specified in |
998 | arch/$(ARCH)/Makefile. | 1002 | arch/$(ARCH)/Makefile. |
@@ -1010,10 +1014,10 @@ When kbuild executes the following steps are followed (roughly): | |||
1010 | $(obj)/setup $(obj)/bootsect: %: %.o FORCE | 1014 | $(obj)/setup $(obj)/bootsect: %: %.o FORCE |
1011 | $(call if_changed,ld) | 1015 | $(call if_changed,ld) |
1012 | 1016 | ||
1013 | In this example there are two possible targets, requiring different | 1017 | In this example, there are two possible targets, requiring different |
1014 | options to the linker. the linker options are specified using the | 1018 | options to the linker. The linker options are specified using the |
1015 | LDFLAGS_$@ syntax - one for each potential target. | 1019 | LDFLAGS_$@ syntax - one for each potential target. |
1016 | $(targets) are assinged all potential targets, herby kbuild knows | 1020 | $(targets) are assinged all potential targets, by which kbuild knows |
1017 | the targets and will: | 1021 | the targets and will: |
1018 | 1) check for commandline changes | 1022 | 1) check for commandline changes |
1019 | 2) delete target during make clean | 1023 | 2) delete target during make clean |
@@ -1027,7 +1031,7 @@ When kbuild executes the following steps are followed (roughly): | |||
1027 | 1031 | ||
1028 | --- 6.7 Custom kbuild commands | 1032 | --- 6.7 Custom kbuild commands |
1029 | 1033 | ||
1030 | When kbuild is executing with KBUILD_VERBOSE=0 then only a shorthand | 1034 | When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand |
1031 | of a command is normally displayed. | 1035 | of a command is normally displayed. |
1032 | To enable this behaviour for custom commands kbuild requires | 1036 | To enable this behaviour for custom commands kbuild requires |
1033 | two variables to be set: | 1037 | two variables to be set: |
@@ -1045,34 +1049,34 @@ When kbuild executes the following steps are followed (roughly): | |||
1045 | $(call if_changed,image) | 1049 | $(call if_changed,image) |
1046 | @echo 'Kernel: $@ is ready' | 1050 | @echo 'Kernel: $@ is ready' |
1047 | 1051 | ||
1048 | When updating the $(obj)/bzImage target the line: | 1052 | When updating the $(obj)/bzImage target, the line |
1049 | 1053 | ||
1050 | BUILD arch/i386/boot/bzImage | 1054 | BUILD arch/i386/boot/bzImage |
1051 | 1055 | ||
1052 | will be displayed with "make KBUILD_VERBOSE=0". | 1056 | will be displayed with "make KBUILD_VERBOSE=0". |
1053 | 1057 | ||
1054 | 1058 | ||
1055 | --- 6.8 Preprocessing linker scripts | 1059 | --- 6.8 Preprocessing linker scripts |
1056 | 1060 | ||
1057 | When the vmlinux image is build the linker script: | 1061 | When the vmlinux image is built, the linker script |
1058 | arch/$(ARCH)/kernel/vmlinux.lds is used. | 1062 | arch/$(ARCH)/kernel/vmlinux.lds is used. |
1059 | The script is a preprocessed variant of the file vmlinux.lds.S | 1063 | The script is a preprocessed variant of the file vmlinux.lds.S |
1060 | located in the same directory. | 1064 | located in the same directory. |
1061 | kbuild knows .lds file and includes a rule *lds.S -> *lds. | 1065 | kbuild knows .lds files and includes a rule *lds.S -> *lds. |
1062 | 1066 | ||
1063 | Example: | 1067 | Example: |
1064 | #arch/i386/kernel/Makefile | 1068 | #arch/i386/kernel/Makefile |
1065 | always := vmlinux.lds | 1069 | always := vmlinux.lds |
1066 | 1070 | ||
1067 | #Makefile | 1071 | #Makefile |
1068 | export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) | 1072 | export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) |
1069 | 1073 | ||
1070 | The assigment to $(always) is used to tell kbuild to build the | 1074 | The assignment to $(always) is used to tell kbuild to build the |
1071 | target: vmlinux.lds. | 1075 | target vmlinux.lds. |
1072 | The assignment to $(CPPFLAGS_vmlinux.lds) tell kbuild to use the | 1076 | The assignment to $(CPPFLAGS_vmlinux.lds) tells kbuild to use the |
1073 | specified options when building the target vmlinux.lds. | 1077 | specified options when building the target vmlinux.lds. |
1074 | 1078 | ||
1075 | When building the *.lds target kbuild used the variakles: | 1079 | When building the *.lds target, kbuild uses the variables: |
1076 | CPPFLAGS : Set in top-level Makefile | 1080 | CPPFLAGS : Set in top-level Makefile |
1077 | EXTRA_CPPFLAGS : May be set in the kbuild makefile | 1081 | EXTRA_CPPFLAGS : May be set in the kbuild makefile |
1078 | CPPFLAGS_$(@F) : Target specific flags. | 1082 | CPPFLAGS_$(@F) : Target specific flags. |
@@ -1147,7 +1151,7 @@ The top Makefile exports the following variables: | |||
1147 | 1151 | ||
1148 | === 8 Makefile language | 1152 | === 8 Makefile language |
1149 | 1153 | ||
1150 | The kernel Makefiles are designed to run with GNU Make. The Makefiles | 1154 | The kernel Makefiles are designed to be run with GNU Make. The Makefiles |
1151 | use only the documented features of GNU Make, but they do use many | 1155 | use only the documented features of GNU Make, but they do use many |
1152 | GNU extensions. | 1156 | GNU extensions. |
1153 | 1157 | ||
@@ -1169,10 +1173,13 @@ is the right choice. | |||
1169 | Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net> | 1173 | Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net> |
1170 | Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de> | 1174 | Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de> |
1171 | Updates by Sam Ravnborg <sam@ravnborg.org> | 1175 | Updates by Sam Ravnborg <sam@ravnborg.org> |
1176 | Language QA by Jan Engelhardt <jengelh@gmx.de> | ||
1172 | 1177 | ||
1173 | === 10 TODO | 1178 | === 10 TODO |
1174 | 1179 | ||
1175 | - Describe how kbuild support shipped files with _shipped. | 1180 | - Describe how kbuild supports shipped files with _shipped. |
1176 | - Generating offset header files. | 1181 | - Generating offset header files. |
1177 | - Add more variables to section 7? | 1182 | - Add more variables to section 7? |
1178 | 1183 | ||
1184 | |||
1185 | |||
diff --git a/Documentation/kbuild/modules.txt b/Documentation/kbuild/modules.txt index 61fc079eb966..2e7702e94a78 100644 --- a/Documentation/kbuild/modules.txt +++ b/Documentation/kbuild/modules.txt | |||
@@ -1,7 +1,7 @@ | |||
1 | 1 | ||
2 | In this document you will find information about: | 2 | In this document you will find information about: |
3 | - how to build external modules | 3 | - how to build external modules |
4 | - how to make your module use kbuild infrastructure | 4 | - how to make your module use the kbuild infrastructure |
5 | - how kbuild will install a kernel | 5 | - how kbuild will install a kernel |
6 | - how to install modules in a non-standard location | 6 | - how to install modules in a non-standard location |
7 | 7 | ||
@@ -24,7 +24,7 @@ In this document you will find information about: | |||
24 | --- 6.1 INSTALL_MOD_PATH | 24 | --- 6.1 INSTALL_MOD_PATH |
25 | --- 6.2 INSTALL_MOD_DIR | 25 | --- 6.2 INSTALL_MOD_DIR |
26 | === 7. Module versioning & Module.symvers | 26 | === 7. Module versioning & Module.symvers |
27 | --- 7.1 Symbols fron the kernel (vmlinux + modules) | 27 | --- 7.1 Symbols from the kernel (vmlinux + modules) |
28 | --- 7.2 Symbols and external modules | 28 | --- 7.2 Symbols and external modules |
29 | --- 7.3 Symbols from another external module | 29 | --- 7.3 Symbols from another external module |
30 | === 8. Tips & Tricks | 30 | === 8. Tips & Tricks |
@@ -36,13 +36,13 @@ In this document you will find information about: | |||
36 | 36 | ||
37 | kbuild includes functionality for building modules both | 37 | kbuild includes functionality for building modules both |
38 | within the kernel source tree and outside the kernel source tree. | 38 | within the kernel source tree and outside the kernel source tree. |
39 | The latter is usually referred to as external modules and is used | 39 | The latter is usually referred to as external or "out-of-tree" |
40 | both during development and for modules that are not planned to be | 40 | modules and is used both during development and for modules that |
41 | included in the kernel tree. | 41 | are not planned to be included in the kernel tree. |
42 | 42 | ||
43 | What is covered within this file is mainly information to authors | 43 | What is covered within this file is mainly information to authors |
44 | of modules. The author of an external modules should supply | 44 | of modules. The author of an external module should supply |
45 | a makefile that hides most of the complexity so one only has to type | 45 | a makefile that hides most of the complexity, so one only has to type |
46 | 'make' to build the module. A complete example will be present in | 46 | 'make' to build the module. A complete example will be present in |
47 | chapter 4, "Creating a kbuild file for an external module". | 47 | chapter 4, "Creating a kbuild file for an external module". |
48 | 48 | ||
@@ -63,14 +63,15 @@ when building an external module. | |||
63 | For the running kernel use: | 63 | For the running kernel use: |
64 | make -C /lib/modules/`uname -r`/build M=`pwd` | 64 | make -C /lib/modules/`uname -r`/build M=`pwd` |
65 | 65 | ||
66 | For the above command to succeed the kernel must have been built with | 66 | For the above command to succeed, the kernel must have been |
67 | modules enabled. | 67 | built with modules enabled. |
68 | 68 | ||
69 | To install the modules that were just built: | 69 | To install the modules that were just built: |
70 | 70 | ||
71 | make -C <path-to-kernel> M=`pwd` modules_install | 71 | make -C <path-to-kernel> M=`pwd` modules_install |
72 | 72 | ||
73 | More complex examples later, the above should get you going. | 73 | More complex examples will be shown later, the above should |
74 | be enough to get you started. | ||
74 | 75 | ||
75 | --- 2.2 Available targets | 76 | --- 2.2 Available targets |
76 | 77 | ||
@@ -89,13 +90,13 @@ when building an external module. | |||
89 | Same functionality as if no target was specified. | 90 | Same functionality as if no target was specified. |
90 | See description above. | 91 | See description above. |
91 | 92 | ||
92 | make -C $KDIR M=$PWD modules_install | 93 | make -C $KDIR M=`pwd` modules_install |
93 | Install the external module(s). | 94 | Install the external module(s). |
94 | Installation default is in /lib/modules/<kernel-version>/extra, | 95 | Installation default is in /lib/modules/<kernel-version>/extra, |
95 | but may be prefixed with INSTALL_MOD_PATH - see separate | 96 | but may be prefixed with INSTALL_MOD_PATH - see separate |
96 | chapter. | 97 | chapter. |
97 | 98 | ||
98 | make -C $KDIR M=$PWD clean | 99 | make -C $KDIR M=`pwd` clean |
99 | Remove all generated files for the module - the kernel | 100 | Remove all generated files for the module - the kernel |
100 | source directory is not modified. | 101 | source directory is not modified. |
101 | 102 | ||
@@ -129,29 +130,28 @@ when building an external module. | |||
129 | 130 | ||
130 | To make sure the kernel contains the information required to | 131 | To make sure the kernel contains the information required to |
131 | build external modules the target 'modules_prepare' must be used. | 132 | build external modules the target 'modules_prepare' must be used. |
132 | 'module_prepare' solely exists as a simple way to prepare | 133 | 'module_prepare' exists solely as a simple way to prepare |
133 | a kernel for building external modules. | 134 | a kernel source tree for building external modules. |
134 | Note: modules_prepare will not build Module.symvers even if | 135 | Note: modules_prepare will not build Module.symvers even if |
135 | CONFIG_MODULEVERSIONING is set. | 136 | CONFIG_MODULEVERSIONING is set. Therefore a full kernel build |
136 | Therefore a full kernel build needs to be executed to make | 137 | needs to be executed to make module versioning work. |
137 | module versioning work. | ||
138 | 138 | ||
139 | --- 2.5 Building separate files for a module | 139 | --- 2.5 Building separate files for a module |
140 | It is possible to build single files which is part of a module. | 140 | It is possible to build single files which are part of a module. |
141 | This works equal for the kernel, a module and even for external | 141 | This works equally well for the kernel, a module and even for |
142 | modules. | 142 | external modules. |
143 | Examples (module foo.ko, consist of bar.o, baz.o): | 143 | Examples (module foo.ko, consist of bar.o, baz.o): |
144 | make -C $KDIR M=`pwd` bar.lst | 144 | make -C $KDIR M=`pwd` bar.lst |
145 | make -C $KDIR M=`pwd` bar.o | 145 | make -C $KDIR M=`pwd` bar.o |
146 | make -C $KDIR M=`pwd` foo.ko | 146 | make -C $KDIR M=`pwd` foo.ko |
147 | make -C $KDIR M=`pwd` / | 147 | make -C $KDIR M=`pwd` / |
148 | 148 | ||
149 | 149 | ||
150 | === 3. Example commands | 150 | === 3. Example commands |
151 | 151 | ||
152 | This example shows the actual commands to be executed when building | 152 | This example shows the actual commands to be executed when building |
153 | an external module for the currently running kernel. | 153 | an external module for the currently running kernel. |
154 | In the example below the distribution is supposed to use the | 154 | In the example below, the distribution is supposed to use the |
155 | facility to locate output files for a kernel compile in a different | 155 | facility to locate output files for a kernel compile in a different |
156 | directory than the kernel source - but the examples will also work | 156 | directory than the kernel source - but the examples will also work |
157 | when the source and the output files are mixed in the same directory. | 157 | when the source and the output files are mixed in the same directory. |
@@ -170,14 +170,14 @@ the following commands to build the module: | |||
170 | O=/lib/modules/`uname-r`/build \ | 170 | O=/lib/modules/`uname-r`/build \ |
171 | M=`pwd` | 171 | M=`pwd` |
172 | 172 | ||
173 | Then to install the module use the following command: | 173 | Then, to install the module use the following command: |
174 | 174 | ||
175 | make -C /usr/src/`uname -r`/source \ | 175 | make -C /usr/src/`uname -r`/source \ |
176 | O=/lib/modules/`uname-r`/build \ | 176 | O=/lib/modules/`uname-r`/build \ |
177 | M=`pwd` \ | 177 | M=`pwd` \ |
178 | modules_install | 178 | modules_install |
179 | 179 | ||
180 | If one looks closely you will see that this is the same commands as | 180 | If you look closely you will see that this is the same command as |
181 | listed before - with the directories spelled out. | 181 | listed before - with the directories spelled out. |
182 | 182 | ||
183 | The above are rather long commands, and the following chapter | 183 | The above are rather long commands, and the following chapter |
@@ -230,7 +230,7 @@ following files: | |||
230 | 230 | ||
231 | endif | 231 | endif |
232 | 232 | ||
233 | In example 1 the check for KERNELRELEASE is used to separate | 233 | In example 1, the check for KERNELRELEASE is used to separate |
234 | the two parts of the Makefile. kbuild will only see the two | 234 | the two parts of the Makefile. kbuild will only see the two |
235 | assignments whereas make will see everything except the two | 235 | assignments whereas make will see everything except the two |
236 | kbuild assignments. | 236 | kbuild assignments. |
@@ -255,7 +255,7 @@ following files: | |||
255 | echo "X" > 8123_bin_shipped | 255 | echo "X" > 8123_bin_shipped |
256 | 256 | ||
257 | 257 | ||
258 | In example 2 we are down to two fairly simple files and for simple | 258 | In example 2, we are down to two fairly simple files and for simple |
259 | files as used in this example the split is questionable. But some | 259 | files as used in this example the split is questionable. But some |
260 | external modules use Makefiles of several hundred lines and here it | 260 | external modules use Makefiles of several hundred lines and here it |
261 | really pays off to separate the kbuild part from the rest. | 261 | really pays off to separate the kbuild part from the rest. |
@@ -282,9 +282,9 @@ following files: | |||
282 | 282 | ||
283 | endif | 283 | endif |
284 | 284 | ||
285 | The trick here is to include the Kbuild file from Makefile so | 285 | The trick here is to include the Kbuild file from Makefile, so |
286 | if an older version of kbuild picks up the Makefile the Kbuild | 286 | if an older version of kbuild picks up the Makefile, the Kbuild |
287 | file will be included. | 287 | file will be included. |
288 | 288 | ||
289 | --- 4.2 Binary blobs included in a module | 289 | --- 4.2 Binary blobs included in a module |
290 | 290 | ||
@@ -301,18 +301,19 @@ following files: | |||
301 | obj-m := 8123.o | 301 | obj-m := 8123.o |
302 | 8123-y := 8123_if.o 8123_pci.o 8123_bin.o | 302 | 8123-y := 8123_if.o 8123_pci.o 8123_bin.o |
303 | 303 | ||
304 | In example 4 there is no distinction between the ordinary .c/.h files | 304 | In example 4, there is no distinction between the ordinary .c/.h files |
305 | and the binary file. But kbuild will pick up different rules to create | 305 | and the binary file. But kbuild will pick up different rules to create |
306 | the .o file. | 306 | the .o file. |
307 | 307 | ||
308 | 308 | ||
309 | === 5. Include files | 309 | === 5. Include files |
310 | 310 | ||
311 | Include files are a necessity when a .c file uses something from another .c | 311 | Include files are a necessity when a .c file uses something from other .c |
312 | files (not strictly in the sense of .c but if good programming practice is | 312 | files (not strictly in the sense of C, but if good programming practice is |
313 | used). Any module that consist of more than one .c file will have a .h file | 313 | used). Any module that consists of more than one .c file will have a .h file |
314 | for one of the .c files. | 314 | for one of the .c files. |
315 | - If the .h file only describes a module internal interface then the .h file | 315 | |
316 | - If the .h file only describes a module internal interface, then the .h file | ||
316 | shall be placed in the same directory as the .c files. | 317 | shall be placed in the same directory as the .c files. |
317 | - If the .h files describe an interface used by other parts of the kernel | 318 | - If the .h files describe an interface used by other parts of the kernel |
318 | located in different directories, the .h files shall be located in | 319 | located in different directories, the .h files shall be located in |
@@ -323,11 +324,11 @@ under include/ such as include/scsi. Another exception is arch-specific | |||
323 | .h files which are located under include/asm-$(ARCH)/*. | 324 | .h files which are located under include/asm-$(ARCH)/*. |
324 | 325 | ||
325 | External modules have a tendency to locate include files in a separate include/ | 326 | External modules have a tendency to locate include files in a separate include/ |
326 | directory and therefore needs to deal with this in their kbuild file. | 327 | directory and therefore need to deal with this in their kbuild file. |
327 | 328 | ||
328 | --- 5.1 How to include files from the kernel include dir | 329 | --- 5.1 How to include files from the kernel include dir |
329 | 330 | ||
330 | When a module needs to include a file from include/linux/ then one | 331 | When a module needs to include a file from include/linux/, then one |
331 | just uses: | 332 | just uses: |
332 | 333 | ||
333 | #include <linux/modules.h> | 334 | #include <linux/modules.h> |
@@ -348,7 +349,7 @@ directory and therefore needs to deal with this in their kbuild file. | |||
348 | The trick here is to use either EXTRA_CFLAGS (take effect for all .c | 349 | The trick here is to use either EXTRA_CFLAGS (take effect for all .c |
349 | files) or CFLAGS_$F.o (take effect only for a single file). | 350 | files) or CFLAGS_$F.o (take effect only for a single file). |
350 | 351 | ||
351 | In our example if we move 8123_if.h to a subdirectory named include/ | 352 | In our example, if we move 8123_if.h to a subdirectory named include/ |
352 | the resulting Kbuild file would look like: | 353 | the resulting Kbuild file would look like: |
353 | 354 | ||
354 | --> filename: Kbuild | 355 | --> filename: Kbuild |
@@ -362,19 +363,19 @@ directory and therefore needs to deal with this in their kbuild file. | |||
362 | 363 | ||
363 | --- 5.3 External modules using several directories | 364 | --- 5.3 External modules using several directories |
364 | 365 | ||
365 | If an external module does not follow the usual kernel style but | 366 | If an external module does not follow the usual kernel style, but |
366 | decide to spread files over several directories then kbuild can | 367 | decides to spread files over several directories, then kbuild can |
367 | support this too. | 368 | handle this too. |
368 | 369 | ||
369 | Consider the following example: | 370 | Consider the following example: |
370 | 371 | ||
371 | | | 372 | | |
372 | +- src/complex_main.c | 373 | +- src/complex_main.c |
373 | | +- hal/hardwareif.c | 374 | | +- hal/hardwareif.c |
374 | | +- hal/include/hardwareif.h | 375 | | +- hal/include/hardwareif.h |
375 | +- include/complex.h | 376 | +- include/complex.h |
376 | 377 | ||
377 | To build a single module named complex.ko we then need the following | 378 | To build a single module named complex.ko, we then need the following |
378 | kbuild file: | 379 | kbuild file: |
379 | 380 | ||
380 | Kbuild: | 381 | Kbuild: |
@@ -387,12 +388,12 @@ directory and therefore needs to deal with this in their kbuild file. | |||
387 | 388 | ||
388 | 389 | ||
389 | kbuild knows how to handle .o files located in another directory - | 390 | kbuild knows how to handle .o files located in another directory - |
390 | although this is NOT reccommended practice. The syntax is to specify | 391 | although this is NOT recommended practice. The syntax is to specify |
391 | the directory relative to the directory where the Kbuild file is | 392 | the directory relative to the directory where the Kbuild file is |
392 | located. | 393 | located. |
393 | 394 | ||
394 | To find the .h files we have to explicitly tell kbuild where to look | 395 | To find the .h files, we have to explicitly tell kbuild where to look |
395 | for the .h files. When kbuild executes current directory is always | 396 | for the .h files. When kbuild executes, the current directory is always |
396 | the root of the kernel tree (argument to -C) and therefore we have to | 397 | the root of the kernel tree (argument to -C) and therefore we have to |
397 | tell kbuild how to find the .h files using absolute paths. | 398 | tell kbuild how to find the .h files using absolute paths. |
398 | $(src) will specify the absolute path to the directory where the | 399 | $(src) will specify the absolute path to the directory where the |
@@ -412,7 +413,7 @@ External modules are installed in the directory: | |||
412 | 413 | ||
413 | --- 6.1 INSTALL_MOD_PATH | 414 | --- 6.1 INSTALL_MOD_PATH |
414 | 415 | ||
415 | Above are the default directories, but as always some level of | 416 | Above are the default directories, but as always, some level of |
416 | customization is possible. One can prefix the path using the variable | 417 | customization is possible. One can prefix the path using the variable |
417 | INSTALL_MOD_PATH: | 418 | INSTALL_MOD_PATH: |
418 | 419 | ||
@@ -420,17 +421,17 @@ External modules are installed in the directory: | |||
420 | => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel | 421 | => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel |
421 | 422 | ||
422 | INSTALL_MOD_PATH may be set as an ordinary shell variable or as in the | 423 | INSTALL_MOD_PATH may be set as an ordinary shell variable or as in the |
423 | example above be specified on the command line when calling make. | 424 | example above, can be specified on the command line when calling make. |
424 | INSTALL_MOD_PATH has effect both when installing modules included in | 425 | INSTALL_MOD_PATH has effect both when installing modules included in |
425 | the kernel as well as when installing external modules. | 426 | the kernel as well as when installing external modules. |
426 | 427 | ||
427 | --- 6.2 INSTALL_MOD_DIR | 428 | --- 6.2 INSTALL_MOD_DIR |
428 | 429 | ||
429 | When installing external modules they are default installed in a | 430 | When installing external modules they are by default installed to a |
430 | directory under /lib/modules/$(KERNELRELEASE)/extra, but one may wish | 431 | directory under /lib/modules/$(KERNELRELEASE)/extra, but one may wish |
431 | to locate modules for a specific functionality in a separate | 432 | to locate modules for a specific functionality in a separate |
432 | directory. For this purpose one can use INSTALL_MOD_DIR to specify an | 433 | directory. For this purpose, one can use INSTALL_MOD_DIR to specify an |
433 | alternative name than 'extra'. | 434 | alternative name to 'extra'. |
434 | 435 | ||
435 | $ make INSTALL_MOD_DIR=gandalf -C KERNELDIR \ | 436 | $ make INSTALL_MOD_DIR=gandalf -C KERNELDIR \ |
436 | M=`pwd` modules_install | 437 | M=`pwd` modules_install |
@@ -444,16 +445,16 @@ Module versioning is enabled by the CONFIG_MODVERSIONS tag. | |||
444 | Module versioning is used as a simple ABI consistency check. The Module | 445 | Module versioning is used as a simple ABI consistency check. The Module |
445 | versioning creates a CRC value of the full prototype for an exported symbol and | 446 | versioning creates a CRC value of the full prototype for an exported symbol and |
446 | when a module is loaded/used then the CRC values contained in the kernel are | 447 | when a module is loaded/used then the CRC values contained in the kernel are |
447 | compared with similar values in the module. If they are not equal then the | 448 | compared with similar values in the module. If they are not equal, then the |
448 | kernel refuses to load the module. | 449 | kernel refuses to load the module. |
449 | 450 | ||
450 | Module.symvers contains a list of all exported symbols from a kernel build. | 451 | Module.symvers contains a list of all exported symbols from a kernel build. |
451 | 452 | ||
452 | --- 7.1 Symbols fron the kernel (vmlinux + modules) | 453 | --- 7.1 Symbols fron the kernel (vmlinux + modules) |
453 | 454 | ||
454 | During a kernel build a file named Module.symvers will be generated. | 455 | During a kernel build, a file named Module.symvers will be generated. |
455 | Module.symvers contains all exported symbols from the kernel and | 456 | Module.symvers contains all exported symbols from the kernel and |
456 | compiled modules. For each symbols the corresponding CRC value | 457 | compiled modules. For each symbols, the corresponding CRC value |
457 | is stored too. | 458 | is stored too. |
458 | 459 | ||
459 | The syntax of the Module.symvers file is: | 460 | The syntax of the Module.symvers file is: |
@@ -461,27 +462,27 @@ Module.symvers contains a list of all exported symbols from a kernel build. | |||
461 | Sample: | 462 | Sample: |
462 | 0x2d036834 scsi_remove_host drivers/scsi/scsi_mod | 463 | 0x2d036834 scsi_remove_host drivers/scsi/scsi_mod |
463 | 464 | ||
464 | For a kernel build without CONFIG_MODVERSIONING enabled the crc | 465 | For a kernel build without CONFIG_MODVERSIONS enabled, the crc |
465 | would read: 0x00000000 | 466 | would read: 0x00000000 |
466 | 467 | ||
467 | Module.symvers serve two purposes. | 468 | Module.symvers serves two purposes: |
468 | 1) It list all exported symbols both from vmlinux and all modules | 469 | 1) It lists all exported symbols both from vmlinux and all modules |
469 | 2) It list CRC if CONFIG_MODVERSION is enabled | 470 | 2) It lists the CRC if CONFIG_MODVERSIONS is enabled |
470 | 471 | ||
471 | --- 7.2 Symbols and external modules | 472 | --- 7.2 Symbols and external modules |
472 | 473 | ||
473 | When building an external module the build system needs access to | 474 | When building an external module, the build system needs access to |
474 | the symbols from the kernel to check if all external symbols are | 475 | the symbols from the kernel to check if all external symbols are |
475 | defined. This is done in the MODPOST step and to obtain all | 476 | defined. This is done in the MODPOST step and to obtain all |
476 | symbols modpost reads Module.symvers from the kernel. | 477 | symbols, modpost reads Module.symvers from the kernel. |
477 | If a Module.symvers file is present in the directory where | 478 | If a Module.symvers file is present in the directory where |
478 | the external module is being build this file will be read too. | 479 | the external module is being built, this file will be read too. |
479 | During the MODPOST step a new Module.symvers file will be written | 480 | During the MODPOST step, a new Module.symvers file will be written |
480 | containing all exported symbols that was not defined in the kernel. | 481 | containing all exported symbols that were not defined in the kernel. |
481 | 482 | ||
482 | --- 7.3 Symbols from another external module | 483 | --- 7.3 Symbols from another external module |
483 | 484 | ||
484 | Sometimes one external module uses exported symbols from another | 485 | Sometimes, an external module uses exported symbols from another |
485 | external module. Kbuild needs to have full knowledge on all symbols | 486 | external module. Kbuild needs to have full knowledge on all symbols |
486 | to avoid spitting out warnings about undefined symbols. | 487 | to avoid spitting out warnings about undefined symbols. |
487 | Two solutions exist to let kbuild know all symbols of more than | 488 | Two solutions exist to let kbuild know all symbols of more than |
@@ -490,15 +491,15 @@ Module.symvers contains a list of all exported symbols from a kernel build. | |||
490 | impractical in certain situations. | 491 | impractical in certain situations. |
491 | 492 | ||
492 | Use a top-level Kbuild file | 493 | Use a top-level Kbuild file |
493 | If you have two modules: 'foo', 'bar' and 'foo' needs symbols | 494 | If you have two modules: 'foo' and 'bar', and 'foo' needs |
494 | from 'bar' then one can use a common top-level kbuild file so | 495 | symbols from 'bar', then one can use a common top-level kbuild |
495 | both modules are compiled in same build. | 496 | file so both modules are compiled in same build. |
496 | 497 | ||
497 | Consider following directory layout: | 498 | Consider following directory layout: |
498 | ./foo/ <= contains the foo module | 499 | ./foo/ <= contains the foo module |
499 | ./bar/ <= contains the bar module | 500 | ./bar/ <= contains the bar module |
500 | The top-level Kbuild file would then look like: | 501 | The top-level Kbuild file would then look like: |
501 | 502 | ||
502 | #./Kbuild: (this file may also be named Makefile) | 503 | #./Kbuild: (this file may also be named Makefile) |
503 | obj-y := foo/ bar/ | 504 | obj-y := foo/ bar/ |
504 | 505 | ||
@@ -509,23 +510,23 @@ Module.symvers contains a list of all exported symbols from a kernel build. | |||
509 | knowledge on symbols from both modules. | 510 | knowledge on symbols from both modules. |
510 | 511 | ||
511 | Use an extra Module.symvers file | 512 | Use an extra Module.symvers file |
512 | When an external module is build a Module.symvers file is | 513 | When an external module is built, a Module.symvers file is |
513 | generated containing all exported symbols which are not | 514 | generated containing all exported symbols which are not |
514 | defined in the kernel. | 515 | defined in the kernel. |
515 | To get access to symbols from module 'bar' one can copy the | 516 | To get access to symbols from module 'bar', one can copy the |
516 | Module.symvers file from the compilation of the 'bar' module | 517 | Module.symvers file from the compilation of the 'bar' module |
517 | to the directory where the 'foo' module is build. | 518 | to the directory where the 'foo' module is built. |
518 | During the module build kbuild will read the Module.symvers | 519 | During the module build, kbuild will read the Module.symvers |
519 | file in the directory of the external module and when the | 520 | file in the directory of the external module and when the |
520 | build is finished a new Module.symvers file is created | 521 | build is finished, a new Module.symvers file is created |
521 | containing the sum of all symbols defined and not part of the | 522 | containing the sum of all symbols defined and not part of the |
522 | kernel. | 523 | kernel. |
523 | 524 | ||
524 | === 8. Tips & Tricks | 525 | === 8. Tips & Tricks |
525 | 526 | ||
526 | --- 8.1 Testing for CONFIG_FOO_BAR | 527 | --- 8.1 Testing for CONFIG_FOO_BAR |
527 | 528 | ||
528 | Modules often needs to check for certain CONFIG_ options to decide if | 529 | Modules often need to check for certain CONFIG_ options to decide if |
529 | a specific feature shall be included in the module. When kbuild is used | 530 | a specific feature shall be included in the module. When kbuild is used |
530 | this is done by referencing the CONFIG_ variable directly. | 531 | this is done by referencing the CONFIG_ variable directly. |
531 | 532 | ||
@@ -537,7 +538,7 @@ Module.symvers contains a list of all exported symbols from a kernel build. | |||
537 | 538 | ||
538 | External modules have traditionally used grep to check for specific | 539 | External modules have traditionally used grep to check for specific |
539 | CONFIG_ settings directly in .config. This usage is broken. | 540 | CONFIG_ settings directly in .config. This usage is broken. |
540 | As introduced before external modules shall use kbuild when building | 541 | As introduced before, external modules shall use kbuild when building |
541 | and therefore can use the same methods as in-kernel modules when testing | 542 | and therefore can use the same methods as in-kernel modules when |
542 | for CONFIG_ definitions. | 543 | testing for CONFIG_ definitions. |
543 | 544 | ||
diff --git a/Documentation/sparse.txt b/Documentation/sparse.txt index 5a311c38dd1a..f9c99c9a54f9 100644 --- a/Documentation/sparse.txt +++ b/Documentation/sparse.txt | |||
@@ -69,10 +69,10 @@ recompiled, or use "make C=2" to run sparse on the files whether they need to | |||
69 | be recompiled or not. The latter is a fast way to check the whole tree if you | 69 | be recompiled or not. The latter is a fast way to check the whole tree if you |
70 | have already built it. | 70 | have already built it. |
71 | 71 | ||
72 | The optional make variable CF can be used to pass arguments to sparse. The | 72 | The optional make variable CHECKFLAGS can be used to pass arguments to sparse. |
73 | build system passes -Wbitwise to sparse automatically. To perform endianness | 73 | The build system passes -Wbitwise to sparse automatically. To perform |
74 | checks, you may define __CHECK_ENDIAN__: | 74 | endianness checks, you may define __CHECK_ENDIAN__: |
75 | 75 | ||
76 | make C=2 CF="-D__CHECK_ENDIAN__" | 76 | make C=2 CHECKFLAGS="-D__CHECK_ENDIAN__" |
77 | 77 | ||
78 | These checks are disabled by default as they generate a host of warnings. | 78 | These checks are disabled by default as they generate a host of warnings. |
@@ -28,7 +28,7 @@ define cmd_offsets | |||
28 | echo "/*"; \ | 28 | echo "/*"; \ |
29 | echo " * DO NOT MODIFY."; \ | 29 | echo " * DO NOT MODIFY."; \ |
30 | echo " *"; \ | 30 | echo " *"; \ |
31 | echo " * This file was generated by $(srctree)/Kbuild"; \ | 31 | echo " * This file was generated by Kbuild"; \ |
32 | echo " *"; \ | 32 | echo " *"; \ |
33 | echo " */"; \ | 33 | echo " */"; \ |
34 | echo ""; \ | 34 | echo ""; \ |
@@ -41,9 +41,15 @@ ifndef KBUILD_VERBOSE | |||
41 | KBUILD_VERBOSE = 0 | 41 | KBUILD_VERBOSE = 0 |
42 | endif | 42 | endif |
43 | 43 | ||
44 | # Call checker as part of compilation of C files | 44 | # Call a source code checker (by default, "sparse") as part of the |
45 | # Use 'make C=1' to enable checking (sparse, by default) | 45 | # C compilation. |
46 | # Override with 'make C=1 CHECK=checker_executable CHECKFLAGS=....' | 46 | # |
47 | # Use 'make C=1' to enable checking of only re-compiled files. | ||
48 | # Use 'make C=2' to enable checking of *all* source files, regardless | ||
49 | # of whether they are re-compiled or not. | ||
50 | # | ||
51 | # See the file "Documentation/sparse.txt" for more details, including | ||
52 | # where to get the "sparse" utility. | ||
47 | 53 | ||
48 | ifdef C | 54 | ifdef C |
49 | ifeq ("$(origin C)", "command line") | 55 | ifeq ("$(origin C)", "command line") |
@@ -639,12 +645,12 @@ define rule_vmlinux__ | |||
639 | $(call cmd,vmlinux__) | 645 | $(call cmd,vmlinux__) |
640 | $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd | 646 | $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd |
641 | 647 | ||
642 | $(Q)$(if $($(quiet)cmd_sysmap), \ | 648 | $(Q)$(if $($(quiet)cmd_sysmap), \ |
643 | echo ' $($(quiet)cmd_sysmap) System.map' &&) \ | 649 | echo ' $($(quiet)cmd_sysmap) System.map' &&) \ |
644 | $(cmd_sysmap) $@ System.map; \ | 650 | $(cmd_sysmap) $@ System.map; \ |
645 | if [ $$? -ne 0 ]; then \ | 651 | if [ $$? -ne 0 ]; then \ |
646 | rm -f $@; \ | 652 | rm -f $@; \ |
647 | /bin/false; \ | 653 | /bin/false; \ |
648 | fi; | 654 | fi; |
649 | $(verify_kallsyms) | 655 | $(verify_kallsyms) |
650 | endef | 656 | endef |
@@ -677,12 +683,12 @@ endif | |||
677 | kallsyms.o := .tmp_kallsyms$(last_kallsyms).o | 683 | kallsyms.o := .tmp_kallsyms$(last_kallsyms).o |
678 | 684 | ||
679 | define verify_kallsyms | 685 | define verify_kallsyms |
680 | $(Q)$(if $($(quiet)cmd_sysmap), \ | 686 | $(Q)$(if $($(quiet)cmd_sysmap), \ |
681 | echo ' $($(quiet)cmd_sysmap) .tmp_System.map' &&) \ | 687 | echo ' $($(quiet)cmd_sysmap) .tmp_System.map' &&) \ |
682 | $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map | 688 | $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map |
683 | $(Q)cmp -s System.map .tmp_System.map || \ | 689 | $(Q)cmp -s System.map .tmp_System.map || \ |
684 | (echo Inconsistent kallsyms data; \ | 690 | (echo Inconsistent kallsyms data; \ |
685 | echo Try setting CONFIG_KALLSYMS_EXTRA_PASS; \ | 691 | echo Try setting CONFIG_KALLSYMS_EXTRA_PASS; \ |
686 | rm .tmp_kallsyms* ; /bin/false ) | 692 | rm .tmp_kallsyms* ; /bin/false ) |
687 | endef | 693 | endef |
688 | 694 | ||
@@ -736,6 +742,7 @@ endif # ifdef CONFIG_KALLSYMS | |||
736 | # vmlinux image - including updated kernel symbols | 742 | # vmlinux image - including updated kernel symbols |
737 | vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE | 743 | vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE |
738 | $(call if_changed_rule,vmlinux__) | 744 | $(call if_changed_rule,vmlinux__) |
745 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@ | ||
739 | $(Q)rm -f .old_version | 746 | $(Q)rm -f .old_version |
740 | 747 | ||
741 | # The actual objects are generated when descending, | 748 | # The actual objects are generated when descending, |
@@ -753,12 +760,34 @@ $(vmlinux-dirs): prepare scripts | |||
753 | $(Q)$(MAKE) $(build)=$@ | 760 | $(Q)$(MAKE) $(build)=$@ |
754 | 761 | ||
755 | # Build the kernel release string | 762 | # Build the kernel release string |
756 | # The KERNELRELEASE is stored in a file named include/config/kernel.release | ||
757 | # to be used when executing for example make install or make modules_install | ||
758 | # | 763 | # |
759 | # Take the contents of any files called localversion* and the config | 764 | # The KERNELRELEASE value built here is stored in the file |
760 | # variable CONFIG_LOCALVERSION and append them to KERNELRELEASE. | 765 | # include/config/kernel.release, and is used when executing several |
761 | # LOCALVERSION from the command line override all of this | 766 | # make targets, such as "make install" or "make modules_install." |
767 | # | ||
768 | # The eventual kernel release string consists of the following fields, | ||
769 | # shown in a hierarchical format to show how smaller parts are concatenated | ||
770 | # to form the larger and final value, with values coming from places like | ||
771 | # the Makefile, kernel config options, make command line options and/or | ||
772 | # SCM tag information. | ||
773 | # | ||
774 | # $(KERNELVERSION) | ||
775 | # $(VERSION) eg, 2 | ||
776 | # $(PATCHLEVEL) eg, 6 | ||
777 | # $(SUBLEVEL) eg, 18 | ||
778 | # $(EXTRAVERSION) eg, -rc6 | ||
779 | # $(localver-full) | ||
780 | # $(localver) | ||
781 | # localversion* (all localversion* files) | ||
782 | # $(CONFIG_LOCALVERSION) (from kernel config setting) | ||
783 | # $(localver-auto) (only if CONFIG_LOCALVERSION_AUTO is set) | ||
784 | # ./scripts/setlocalversion (SCM tag, if one exists) | ||
785 | # $(LOCALVERSION) (from make command line if provided) | ||
786 | # | ||
787 | # Note how the final $(localver-auto) string is included *only* if the | ||
788 | # kernel config option CONFIG_LOCALVERSION_AUTO is selected. Also, at the | ||
789 | # moment, only git is supported but other SCMs can edit the script | ||
790 | # scripts/setlocalversion and add the appropriate checks as needed. | ||
762 | 791 | ||
763 | nullstring := | 792 | nullstring := |
764 | space := $(nullstring) # end of line | 793 | space := $(nullstring) # end of line |
@@ -893,14 +922,14 @@ INSTALL_HDR_PATH=$(objtree)/usr | |||
893 | export INSTALL_HDR_PATH | 922 | export INSTALL_HDR_PATH |
894 | 923 | ||
895 | PHONY += headers_install | 924 | PHONY += headers_install |
896 | headers_install: include/linux/version.h | 925 | headers_install: include/linux/version.h scripts_basic FORCE |
897 | $(Q)unifdef -Ux /dev/null | 926 | $(Q)$(MAKE) $(build)=scripts scripts/unifdef |
898 | $(Q)rm -rf $(INSTALL_HDR_PATH)/include | 927 | $(Q)rm -rf $(INSTALL_HDR_PATH)/include |
899 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.headersinst obj=include | 928 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include |
900 | 929 | ||
901 | PHONY += headers_check | 930 | PHONY += headers_check |
902 | headers_check: headers_install | 931 | headers_check: headers_install |
903 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.headersinst obj=include HDRCHECK=1 | 932 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include HDRCHECK=1 |
904 | 933 | ||
905 | # --------------------------------------------------------------------------- | 934 | # --------------------------------------------------------------------------- |
906 | # Modules | 935 | # Modules |
@@ -916,7 +945,7 @@ all: modules | |||
916 | PHONY += modules | 945 | PHONY += modules |
917 | modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) | 946 | modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) |
918 | @echo ' Building modules, stage 2.'; | 947 | @echo ' Building modules, stage 2.'; |
919 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost | 948 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
920 | 949 | ||
921 | 950 | ||
922 | # Target to prepare building external modules | 951 | # Target to prepare building external modules |
@@ -942,7 +971,7 @@ _modinst_: | |||
942 | rm -f $(MODLIB)/build ; \ | 971 | rm -f $(MODLIB)/build ; \ |
943 | ln -s $(objtree) $(MODLIB)/build ; \ | 972 | ln -s $(objtree) $(MODLIB)/build ; \ |
944 | fi | 973 | fi |
945 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst | 974 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst |
946 | 975 | ||
947 | # If System.map exists, run depmod. This deliberately does not have a | 976 | # If System.map exists, run depmod. This deliberately does not have a |
948 | # dependency on System.map since that would run the dependency tree on | 977 | # dependency on System.map since that would run the dependency tree on |
@@ -1057,8 +1086,10 @@ boards := $(notdir $(boards)) | |||
1057 | 1086 | ||
1058 | help: | 1087 | help: |
1059 | @echo 'Cleaning targets:' | 1088 | @echo 'Cleaning targets:' |
1060 | @echo ' clean - remove most generated files but keep the config' | 1089 | @echo ' clean - remove most generated files but keep the config and' |
1090 | @echo ' enough build support to build external modules' | ||
1061 | @echo ' mrproper - remove all generated files + config + various backup files' | 1091 | @echo ' mrproper - remove all generated files + config + various backup files' |
1092 | @echo ' distclean - mrproper + remove editor backup and patch files' | ||
1062 | @echo '' | 1093 | @echo '' |
1063 | @echo 'Configuration targets:' | 1094 | @echo 'Configuration targets:' |
1064 | @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help | 1095 | @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help |
@@ -1100,6 +1131,7 @@ help: | |||
1100 | echo '') | 1131 | echo '') |
1101 | 1132 | ||
1102 | @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' | 1133 | @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' |
1134 | @echo ' make V=2 [targets] 2 => give reason for rebuild of target' | ||
1103 | @echo ' make O=dir [targets] Locate all output files in "dir", including .config' | 1135 | @echo ' make O=dir [targets] Locate all output files in "dir", including .config' |
1104 | @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)' | 1136 | @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)' |
1105 | @echo ' make C=2 [targets] Force check of all c source with $$CHECK' | 1137 | @echo ' make C=2 [targets] Force check of all c source with $$CHECK' |
@@ -1154,7 +1186,7 @@ $(module-dirs): crmodverdir $(objtree)/Module.symvers | |||
1154 | 1186 | ||
1155 | modules: $(module-dirs) | 1187 | modules: $(module-dirs) |
1156 | @echo ' Building modules, stage 2.'; | 1188 | @echo ' Building modules, stage 2.'; |
1157 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost | 1189 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
1158 | 1190 | ||
1159 | PHONY += modules_install | 1191 | PHONY += modules_install |
1160 | modules_install: _emodinst_ _emodinst_post | 1192 | modules_install: _emodinst_ _emodinst_post |
@@ -1163,7 +1195,7 @@ install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) | |||
1163 | PHONY += _emodinst_ | 1195 | PHONY += _emodinst_ |
1164 | _emodinst_: | 1196 | _emodinst_: |
1165 | $(Q)mkdir -p $(MODLIB)/$(install-dir) | 1197 | $(Q)mkdir -p $(MODLIB)/$(install-dir) |
1166 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst | 1198 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst |
1167 | 1199 | ||
1168 | # Run depmod only is we have System.map and depmod is executable | 1200 | # Run depmod only is we have System.map and depmod is executable |
1169 | quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) | 1201 | quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) |
@@ -1264,6 +1296,31 @@ define all-defconfigs | |||
1264 | $(call find-sources,'defconfig') | 1296 | $(call find-sources,'defconfig') |
1265 | endef | 1297 | endef |
1266 | 1298 | ||
1299 | define xtags | ||
1300 | if $1 --version 2>&1 | grep -iq exuberant; then \ | ||
1301 | $(all-sources) | xargs $1 -a \ | ||
1302 | -I __initdata,__exitdata,__acquires,__releases \ | ||
1303 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | ||
1304 | --extra=+f --c-kinds=+px; \ | ||
1305 | $(all-kconfigs) | xargs $1 -a \ | ||
1306 | --langdef=kconfig \ | ||
1307 | --language-force=kconfig \ | ||
1308 | --regex-kconfig='/^[[:blank:]]*config[[:blank:]]+([[:alnum:]_]+)/\1/'; \ | ||
1309 | $(all-defconfigs) | xargs $1 -a \ | ||
1310 | --langdef=dotconfig \ | ||
1311 | --language-force=dotconfig \ | ||
1312 | --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'; \ | ||
1313 | elif $1 --version 2>&1 | grep -iq emacs; then \ | ||
1314 | $(all-sources) | xargs $1 -a; \ | ||
1315 | $(all-kconfigs) | xargs $1 -a \ | ||
1316 | --regex='/^[ \t]*config[ \t]+\([a-zA-Z0-9_]+\)/\1/'; \ | ||
1317 | $(all-defconfigs) | xargs $1 -a \ | ||
1318 | --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; \ | ||
1319 | else \ | ||
1320 | $(all-sources) | xargs $1 -a; \ | ||
1321 | fi | ||
1322 | endef | ||
1323 | |||
1267 | quiet_cmd_cscope-file = FILELST cscope.files | 1324 | quiet_cmd_cscope-file = FILELST cscope.files |
1268 | cmd_cscope-file = (echo \-k; echo \-q; $(all-sources)) > cscope.files | 1325 | cmd_cscope-file = (echo \-k; echo \-q; $(all-sources)) > cscope.files |
1269 | 1326 | ||
@@ -1277,31 +1334,16 @@ cscope: FORCE | |||
1277 | quiet_cmd_TAGS = MAKE $@ | 1334 | quiet_cmd_TAGS = MAKE $@ |
1278 | define cmd_TAGS | 1335 | define cmd_TAGS |
1279 | rm -f $@; \ | 1336 | rm -f $@; \ |
1280 | ETAGSF=`etags --version | grep -i exuberant >/dev/null && \ | 1337 | $(call xtags,etags) |
1281 | echo "-I __initdata,__exitdata,__acquires,__releases \ | ||
1282 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | ||
1283 | --extra=+f --c-kinds=+px"`; \ | ||
1284 | $(all-sources) | xargs etags $$ETAGSF -a; \ | ||
1285 | if test "x$$ETAGSF" = x; then \ | ||
1286 | $(all-kconfigs) | xargs etags -a \ | ||
1287 | --regex='/^config[ \t]+\([a-zA-Z0-9_]+\)/\1/'; \ | ||
1288 | $(all-defconfigs) | xargs etags -a \ | ||
1289 | --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; \ | ||
1290 | fi | ||
1291 | endef | 1338 | endef |
1292 | 1339 | ||
1293 | TAGS: FORCE | 1340 | TAGS: FORCE |
1294 | $(call cmd,TAGS) | 1341 | $(call cmd,TAGS) |
1295 | 1342 | ||
1296 | |||
1297 | quiet_cmd_tags = MAKE $@ | 1343 | quiet_cmd_tags = MAKE $@ |
1298 | define cmd_tags | 1344 | define cmd_tags |
1299 | rm -f $@; \ | 1345 | rm -f $@; \ |
1300 | CTAGSF=`ctags --version | grep -i exuberant >/dev/null && \ | 1346 | $(call xtags,ctags) |
1301 | echo "-I __initdata,__exitdata,__acquires,__releases \ | ||
1302 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | ||
1303 | --extra=+f --c-kinds=+px"`; \ | ||
1304 | $(all-sources) | xargs ctags $$CTAGSF -a | ||
1305 | endef | 1347 | endef |
1306 | 1348 | ||
1307 | tags: FORCE | 1349 | tags: FORCE |
@@ -1379,7 +1421,7 @@ endif | |||
1379 | %.ko: prepare scripts FORCE | 1421 | %.ko: prepare scripts FORCE |
1380 | $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ | 1422 | $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ |
1381 | $(build)=$(build-dir) $(@:.ko=.o) | 1423 | $(build)=$(build-dir) $(@:.ko=.o) |
1382 | $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost | 1424 | $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost |
1383 | 1425 | ||
1384 | # FIXME Should go into a make.lib or something | 1426 | # FIXME Should go into a make.lib or something |
1385 | # =========================================================================== | 1427 | # =========================================================================== |
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index bb19c1561f1e..3d523899fdc0 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
@@ -8,9 +8,13 @@ empty := | |||
8 | space := $(empty) $(empty) | 8 | space := $(empty) $(empty) |
9 | 9 | ||
10 | ### | 10 | ### |
11 | # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o | ||
12 | dot-target = $(dir $@).$(notdir $@) | ||
13 | |||
14 | ### | ||
11 | # The temporary file to save gcc -MD generated dependencies must not | 15 | # The temporary file to save gcc -MD generated dependencies must not |
12 | # contain a comma | 16 | # contain a comma |
13 | depfile = $(subst $(comma),_,$(@D)/.$(@F).d) | 17 | depfile = $(subst $(comma),_,$(dot-target).d) |
14 | 18 | ||
15 | ### | 19 | ### |
16 | # filename of target with directory and extension stripped | 20 | # filename of target with directory and extension stripped |
@@ -119,40 +123,83 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) | |||
119 | ifneq ($(KBUILD_NOCMDDEP),1) | 123 | ifneq ($(KBUILD_NOCMDDEP),1) |
120 | # Check if both arguments has same arguments. Result in empty string if equal | 124 | # Check if both arguments has same arguments. Result in empty string if equal |
121 | # User may override this check using make KBUILD_NOCMDDEP=1 | 125 | # User may override this check using make KBUILD_NOCMDDEP=1 |
122 | arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) | 126 | arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ |
127 | $(filter-out $(cmd_$@), $(cmd_$(1))) ) | ||
123 | endif | 128 | endif |
124 | 129 | ||
125 | # echo command. Short version is $(quiet) equals quiet, otherwise full command | 130 | # echo command. Short version is $(quiet) equals quiet, otherwise full command |
126 | echo-cmd = $(if $($(quiet)cmd_$(1)), \ | 131 | echo-cmd = $(if $($(quiet)cmd_$(1)), \ |
127 | echo ' $(call escsq,$($(quiet)cmd_$(1)))';) | 132 | echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) |
128 | 133 | ||
134 | # >'< substitution is for echo to work, | ||
135 | # >$< substitution to preserve $ when reloading .cmd file | ||
136 | # note: when using inline perl scripts [perl -e '...$$t=1;...'] | ||
137 | # in $(cmd_xxx) double $$ your perl vars | ||
129 | make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))) | 138 | make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))) |
130 | 139 | ||
131 | # function to only execute the passed command if necessary | 140 | # Find any prerequisites that is newer than target or that does not exist. |
132 | # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file | 141 | # PHONY targets skipped in both cases. |
133 | # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars | 142 | any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) |
143 | |||
144 | # Execute command if command has changed or prerequisitei(s) are updated | ||
134 | # | 145 | # |
135 | if_changed = $(if $(strip $(filter-out $(PHONY),$?) \ | 146 | if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ |
136 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ | 147 | @set -e; \ |
137 | @set -e; \ | 148 | $(echo-cmd) $(cmd_$(1)); \ |
138 | $(echo-cmd) $(cmd_$(1)); \ | 149 | echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) |
139 | echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd) | ||
140 | 150 | ||
141 | # execute the command and also postprocess generated .d dependencies | 151 | # execute the command and also postprocess generated .d dependencies |
142 | # file | 152 | # file |
143 | if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \ | 153 | if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ |
144 | $(filter-out FORCE $(wildcard $^),$^) \ | 154 | @set -e; \ |
145 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ | 155 | $(echo-cmd) $(cmd_$(1)); \ |
146 | @set -e; \ | 156 | scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ |
147 | $(echo-cmd) $(cmd_$(1)); \ | 157 | rm -f $(depfile); \ |
148 | scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \ | 158 | mv -f $(dot-target).tmp $(dot-target).cmd) |
149 | rm -f $(depfile); \ | ||
150 | mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) | ||
151 | 159 | ||
152 | # Usage: $(call if_changed_rule,foo) | 160 | # Usage: $(call if_changed_rule,foo) |
153 | # will check if $(cmd_foo) changed, or any of the prequisites changed, | 161 | # will check if $(cmd_foo) changed, or any of the prequisites changed, |
154 | # and if so will execute $(rule_foo) | 162 | # and if so will execute $(rule_foo) |
155 | if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \ | 163 | if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ |
156 | $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ | 164 | @set -e; \ |
157 | @set -e; \ | 165 | $(rule_$(1))) |
158 | $(rule_$(1))) | 166 | |
167 | ### | ||
168 | # why - tell why a a target got build | ||
169 | # enabled by make V=2 | ||
170 | # Output (listed in the order they are checked): | ||
171 | # (1) - due to target is PHONY | ||
172 | # (2) - due to target missing | ||
173 | # (3) - due to: file1.h file2.h | ||
174 | # (4) - due to command line change | ||
175 | # (5) - due to missing .cmd file | ||
176 | # (6) - due to target not in $(targets) | ||
177 | # (1) PHONY targets are always build | ||
178 | # (2) No target, so we better build it | ||
179 | # (3) Prerequisite is newer than target | ||
180 | # (4) The command line stored in the file named dir/.target.cmd | ||
181 | # differed from actual command line. This happens when compiler | ||
182 | # options changes | ||
183 | # (5) No dir/.target.cmd file (used to store command line) | ||
184 | # (6) No dir/.target.cmd file and target not listed in $(targets) | ||
185 | # This is a good hint that there is a bug in the kbuild file | ||
186 | ifeq ($(KBUILD_VERBOSE),2) | ||
187 | why = \ | ||
188 | $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ | ||
189 | $(if $(wildcard $@), \ | ||
190 | $(if $(strip $(any-prereq)),- due to: $(any-prereq), \ | ||
191 | $(if $(arg-check), \ | ||
192 | $(if $(cmd_$@),- due to command line change, \ | ||
193 | $(if $(filter $@, $(targets)), \ | ||
194 | - due to missing .cmd file, \ | ||
195 | - due to $(notdir $@) not in $$(targets) \ | ||
196 | ) \ | ||
197 | ) \ | ||
198 | ) \ | ||
199 | ), \ | ||
200 | - due to target missing \ | ||
201 | ) \ | ||
202 | ) | ||
203 | |||
204 | echo-why = $(call escsq, $(strip $(why))) | ||
205 | endif | ||
diff --git a/scripts/Makefile b/scripts/Makefile index 6f6b48f39f0a..ea41de8fb7f5 100644 --- a/scripts/Makefile +++ b/scripts/Makefile | |||
@@ -15,8 +15,11 @@ hostprogs-$(CONFIG_IKCONFIG) += bin2c | |||
15 | 15 | ||
16 | always := $(hostprogs-y) | 16 | always := $(hostprogs-y) |
17 | 17 | ||
18 | # The following hostprogs-y programs are only build on demand | ||
19 | hostprogs-y += unifdef | ||
20 | |||
18 | subdir-$(CONFIG_MODVERSIONS) += genksyms | 21 | subdir-$(CONFIG_MODVERSIONS) += genksyms |
19 | subdir-$(CONFIG_MODULES) += mod | 22 | subdir-y += mod |
20 | 23 | ||
21 | # Let clean descend into subdirs | 24 | # Let clean descend into subdirs |
22 | subdir- += basic kconfig package | 25 | subdir- += basic kconfig package |
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3cb445cc7432..e2ad2dccccdb 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build | |||
@@ -191,9 +191,10 @@ define rule_cc_o_c | |||
191 | $(call echo-cmd,checksrc) $(cmd_checksrc) \ | 191 | $(call echo-cmd,checksrc) $(cmd_checksrc) \ |
192 | $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ | 192 | $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ |
193 | $(cmd_modversions) \ | 193 | $(cmd_modversions) \ |
194 | scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > $(@D)/.$(@F).tmp; \ | 194 | scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ |
195 | $(dot-target).tmp; \ | ||
195 | rm -f $(depfile); \ | 196 | rm -f $(depfile); \ |
196 | mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd | 197 | mv -f $(dot-target).tmp $(dot-target).cmd |
197 | endef | 198 | endef |
198 | 199 | ||
199 | # Built-in and composite module parts | 200 | # Built-in and composite module parts |
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst index 12e1daf875c8..8c02d2df4278 100644 --- a/scripts/Makefile.headersinst +++ b/scripts/Makefile.headersinst | |||
@@ -7,7 +7,7 @@ | |||
7 | # | 7 | # |
8 | # ========================================================================== | 8 | # ========================================================================== |
9 | 9 | ||
10 | UNIFDEF := unifdef -U__KERNEL__ | 10 | UNIFDEF := scripts/unifdef -U__KERNEL__ |
11 | 11 | ||
12 | # Eliminate the contents of (and inclusions of) compiler.h | 12 | # Eliminate the contents of (and inclusions of) compiler.h |
13 | HDRSED := sed -e "s/ inline / __inline__ /g" \ | 13 | HDRSED := sed -e "s/ inline / __inline__ /g" \ |
diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 060f4c563a5c..575afbe5e370 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host | |||
@@ -32,11 +32,6 @@ | |||
32 | 32 | ||
33 | __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) | 33 | __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) |
34 | 34 | ||
35 | # hostprogs-y := tools/build may have been specified. Retreive directory | ||
36 | host-objdirs := $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f)))) | ||
37 | host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | ||
38 | |||
39 | |||
40 | # C code | 35 | # C code |
41 | # Executables compiled from a single .c file | 36 | # Executables compiled from a single .c file |
42 | host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m))) | 37 | host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m))) |
@@ -65,6 +60,21 @@ host-cobjs := $(filter-out %.so,$(host-cobjs)) | |||
65 | #Object (.o) files used by the shared libaries | 60 | #Object (.o) files used by the shared libaries |
66 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) | 61 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) |
67 | 62 | ||
63 | # output directory for programs/.o files | ||
64 | # hostprogs-y := tools/build may have been specified. Retreive directory | ||
65 | host-objdirs := $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f)))) | ||
66 | # directory of .o files from prog-objs notation | ||
67 | host-objdirs += $(foreach f,$(host-cmulti), \ | ||
68 | $(foreach m,$($(f)-objs), \ | ||
69 | $(if $(dir $(m)),$(dir $(m))))) | ||
70 | # directory of .o files from prog-cxxobjs notation | ||
71 | host-objdirs += $(foreach f,$(host-cxxmulti), \ | ||
72 | $(foreach m,$($(f)-cxxobjs), \ | ||
73 | $(if $(dir $(m)),$(dir $(m))))) | ||
74 | |||
75 | host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | ||
76 | |||
77 | |||
68 | __hostprogs := $(addprefix $(obj)/,$(__hostprogs)) | 78 | __hostprogs := $(addprefix $(obj)/,$(__hostprogs)) |
69 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) | 79 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) |
70 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) | 80 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) |
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 0a64688c2b5d..4b2721ca97da 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost | |||
@@ -51,19 +51,26 @@ _modpost: $(modules) | |||
51 | 51 | ||
52 | # Step 2), invoke modpost | 52 | # Step 2), invoke modpost |
53 | # Includes step 3,4 | 53 | # Includes step 3,4 |
54 | quiet_cmd_modpost = MODPOST | 54 | quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules |
55 | cmd_modpost = scripts/mod/modpost \ | 55 | cmd_modpost = scripts/mod/modpost \ |
56 | $(if $(CONFIG_MODVERSIONS),-m) \ | 56 | $(if $(CONFIG_MODVERSIONS),-m) \ |
57 | $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \ | 57 | $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \ |
58 | $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ | 58 | $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ |
59 | $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ | 59 | $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ |
60 | $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ | 60 | $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ |
61 | $(filter-out FORCE,$^) | 61 | $(if $(KBUILD_EXTMOD),-w) \ |
62 | $(wildcard vmlinux) $(filter-out FORCE,$^) | ||
62 | 63 | ||
63 | PHONY += __modpost | 64 | PHONY += __modpost |
64 | __modpost: $(wildcard vmlinux) $(modules:.ko=.o) FORCE | 65 | __modpost: $(modules:.ko=.o) FORCE |
65 | $(call cmd,modpost) | 66 | $(call cmd,modpost) |
66 | 67 | ||
68 | quiet_cmd_kernel-mod = MODPOST $@ | ||
69 | cmd_kernel-mod = $(cmd_modpost) | ||
70 | |||
71 | vmlinux: FORCE | ||
72 | $(call cmd,kernel-mod) | ||
73 | |||
67 | # Declare generated files as targets for modpost | 74 | # Declare generated files as targets for modpost |
68 | $(symverfile): __modpost ; | 75 | $(symverfile): __modpost ; |
69 | $(modules:.ko=.mod.c): __modpost ; | 76 | $(modules:.ko=.mod.c): __modpost ; |
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index e6499db4c8cc..a90d3cc76bfa 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
@@ -74,6 +74,7 @@ help: | |||
74 | @echo ' xconfig - Update current config utilising a QT based front-end' | 74 | @echo ' xconfig - Update current config utilising a QT based front-end' |
75 | @echo ' gconfig - Update current config utilising a GTK based front-end' | 75 | @echo ' gconfig - Update current config utilising a GTK based front-end' |
76 | @echo ' oldconfig - Update current config utilising a provided .config as base' | 76 | @echo ' oldconfig - Update current config utilising a provided .config as base' |
77 | @echo ' silentoldconfig - Same as oldconfig, but quietly' | ||
77 | @echo ' randconfig - New config with random answer to all options' | 78 | @echo ' randconfig - New config with random answer to all options' |
78 | @echo ' defconfig - New config with default answer to all options' | 79 | @echo ' defconfig - New config with default answer to all options' |
79 | @echo ' allmodconfig - New config selecting modules when possible' | 80 | @echo ' allmodconfig - New config selecting modules when possible' |
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index a69d8acbf274..69f96b398c22 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -193,8 +193,11 @@ load: | |||
193 | continue; | 193 | continue; |
194 | *p++ = 0; | 194 | *p++ = 0; |
195 | p2 = strchr(p, '\n'); | 195 | p2 = strchr(p, '\n'); |
196 | if (p2) | 196 | if (p2) { |
197 | *p2 = 0; | 197 | *p2-- = 0; |
198 | if (*p2 == '\r') | ||
199 | *p2 = 0; | ||
200 | } | ||
198 | if (def == S_DEF_USER) { | 201 | if (def == S_DEF_USER) { |
199 | sym = sym_find(line + 7); | 202 | sym = sym_find(line + 7); |
200 | if (!sym) { | 203 | if (!sym) { |
@@ -266,6 +269,7 @@ load: | |||
266 | ; | 269 | ; |
267 | } | 270 | } |
268 | break; | 271 | break; |
272 | case '\r': | ||
269 | case '\n': | 273 | case '\n': |
270 | break; | 274 | break; |
271 | default: | 275 | default: |
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index dfde0e87a765..41277963f47a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -23,6 +23,8 @@ int have_vmlinux = 0; | |||
23 | static int all_versions = 0; | 23 | static int all_versions = 0; |
24 | /* If we are modposting external module set to 1 */ | 24 | /* If we are modposting external module set to 1 */ |
25 | static int external_module = 0; | 25 | static int external_module = 0; |
26 | /* Only warn about unresolved symbols */ | ||
27 | static int warn_unresolved = 0; | ||
26 | /* How a symbol is exported */ | 28 | /* How a symbol is exported */ |
27 | enum export { | 29 | enum export { |
28 | export_plain, export_unused, export_gpl, | 30 | export_plain, export_unused, export_gpl, |
@@ -581,8 +583,8 @@ static int strrcmp(const char *s, const char *sub) | |||
581 | * fromsec = .data | 583 | * fromsec = .data |
582 | * atsym = *driver, *_template, *_sht, *_ops, *_probe, *probe_one | 584 | * atsym = *driver, *_template, *_sht, *_ops, *_probe, *probe_one |
583 | **/ | 585 | **/ |
584 | static int secref_whitelist(const char *tosec, const char *fromsec, | 586 | static int secref_whitelist(const char *modname, const char *tosec, |
585 | const char *atsym) | 587 | const char *fromsec, const char *atsym) |
586 | { | 588 | { |
587 | int f1 = 1, f2 = 1; | 589 | int f1 = 1, f2 = 1; |
588 | const char **s; | 590 | const char **s; |
@@ -618,8 +620,16 @@ static int secref_whitelist(const char *tosec, const char *fromsec, | |||
618 | for (s = pat2sym; *s; s++) | 620 | for (s = pat2sym; *s; s++) |
619 | if (strrcmp(atsym, *s) == 0) | 621 | if (strrcmp(atsym, *s) == 0) |
620 | f1 = 1; | 622 | f1 = 1; |
623 | if (f1 && f2) | ||
624 | return 1; | ||
621 | 625 | ||
622 | return f1 && f2; | 626 | /* Whitelist all references from .pci_fixup section if vmlinux */ |
627 | if (is_vmlinux(modname)) { | ||
628 | if ((strcmp(fromsec, ".pci_fixup") == 0) && | ||
629 | (strcmp(tosec, ".init.text") == 0)) | ||
630 | return 1; | ||
631 | } | ||
632 | return 0; | ||
623 | } | 633 | } |
624 | 634 | ||
625 | /** | 635 | /** |
@@ -726,7 +736,8 @@ static void warn_sec_mismatch(const char *modname, const char *fromsec, | |||
726 | 736 | ||
727 | /* check whitelist - we may ignore it */ | 737 | /* check whitelist - we may ignore it */ |
728 | if (before && | 738 | if (before && |
729 | secref_whitelist(secname, fromsec, elf->strtab + before->st_name)) | 739 | secref_whitelist(modname, secname, fromsec, |
740 | elf->strtab + before->st_name)) | ||
730 | return; | 741 | return; |
731 | 742 | ||
732 | if (before && after) { | 743 | if (before && after) { |
@@ -1187,16 +1198,19 @@ static void add_header(struct buffer *b, struct module *mod) | |||
1187 | /** | 1198 | /** |
1188 | * Record CRCs for unresolved symbols | 1199 | * Record CRCs for unresolved symbols |
1189 | **/ | 1200 | **/ |
1190 | static void add_versions(struct buffer *b, struct module *mod) | 1201 | static int add_versions(struct buffer *b, struct module *mod) |
1191 | { | 1202 | { |
1192 | struct symbol *s, *exp; | 1203 | struct symbol *s, *exp; |
1204 | int err = 0; | ||
1193 | 1205 | ||
1194 | for (s = mod->unres; s; s = s->next) { | 1206 | for (s = mod->unres; s; s = s->next) { |
1195 | exp = find_symbol(s->name); | 1207 | exp = find_symbol(s->name); |
1196 | if (!exp || exp->module == mod) { | 1208 | if (!exp || exp->module == mod) { |
1197 | if (have_vmlinux && !s->weak) | 1209 | if (have_vmlinux && !s->weak) { |
1198 | warn("\"%s\" [%s.ko] undefined!\n", | 1210 | warn("\"%s\" [%s.ko] undefined!\n", |
1199 | s->name, mod->name); | 1211 | s->name, mod->name); |
1212 | err = warn_unresolved ? 0 : 1; | ||
1213 | } | ||
1200 | continue; | 1214 | continue; |
1201 | } | 1215 | } |
1202 | s->module = exp->module; | 1216 | s->module = exp->module; |
@@ -1205,7 +1219,7 @@ static void add_versions(struct buffer *b, struct module *mod) | |||
1205 | } | 1219 | } |
1206 | 1220 | ||
1207 | if (!modversions) | 1221 | if (!modversions) |
1208 | return; | 1222 | return err; |
1209 | 1223 | ||
1210 | buf_printf(b, "\n"); | 1224 | buf_printf(b, "\n"); |
1211 | buf_printf(b, "static const struct modversion_info ____versions[]\n"); | 1225 | buf_printf(b, "static const struct modversion_info ____versions[]\n"); |
@@ -1225,6 +1239,8 @@ static void add_versions(struct buffer *b, struct module *mod) | |||
1225 | } | 1239 | } |
1226 | 1240 | ||
1227 | buf_printf(b, "};\n"); | 1241 | buf_printf(b, "};\n"); |
1242 | |||
1243 | return err; | ||
1228 | } | 1244 | } |
1229 | 1245 | ||
1230 | static void add_depends(struct buffer *b, struct module *mod, | 1246 | static void add_depends(struct buffer *b, struct module *mod, |
@@ -1402,8 +1418,9 @@ int main(int argc, char **argv) | |||
1402 | char *kernel_read = NULL, *module_read = NULL; | 1418 | char *kernel_read = NULL, *module_read = NULL; |
1403 | char *dump_write = NULL; | 1419 | char *dump_write = NULL; |
1404 | int opt; | 1420 | int opt; |
1421 | int err; | ||
1405 | 1422 | ||
1406 | while ((opt = getopt(argc, argv, "i:I:mo:a")) != -1) { | 1423 | while ((opt = getopt(argc, argv, "i:I:mo:aw")) != -1) { |
1407 | switch(opt) { | 1424 | switch(opt) { |
1408 | case 'i': | 1425 | case 'i': |
1409 | kernel_read = optarg; | 1426 | kernel_read = optarg; |
@@ -1421,6 +1438,9 @@ int main(int argc, char **argv) | |||
1421 | case 'a': | 1438 | case 'a': |
1422 | all_versions = 1; | 1439 | all_versions = 1; |
1423 | break; | 1440 | break; |
1441 | case 'w': | ||
1442 | warn_unresolved = 1; | ||
1443 | break; | ||
1424 | default: | 1444 | default: |
1425 | exit(1); | 1445 | exit(1); |
1426 | } | 1446 | } |
@@ -1441,6 +1461,8 @@ int main(int argc, char **argv) | |||
1441 | check_exports(mod); | 1461 | check_exports(mod); |
1442 | } | 1462 | } |
1443 | 1463 | ||
1464 | err = 0; | ||
1465 | |||
1444 | for (mod = modules; mod; mod = mod->next) { | 1466 | for (mod = modules; mod; mod = mod->next) { |
1445 | if (mod->skip) | 1467 | if (mod->skip) |
1446 | continue; | 1468 | continue; |
@@ -1448,7 +1470,7 @@ int main(int argc, char **argv) | |||
1448 | buf.pos = 0; | 1470 | buf.pos = 0; |
1449 | 1471 | ||
1450 | add_header(&buf, mod); | 1472 | add_header(&buf, mod); |
1451 | add_versions(&buf, mod); | 1473 | err |= add_versions(&buf, mod); |
1452 | add_depends(&buf, mod, modules); | 1474 | add_depends(&buf, mod, modules); |
1453 | add_moddevtable(&buf, mod); | 1475 | add_moddevtable(&buf, mod); |
1454 | add_srcversion(&buf, mod); | 1476 | add_srcversion(&buf, mod); |
@@ -1460,5 +1482,5 @@ int main(int argc, char **argv) | |||
1460 | if (dump_write) | 1482 | if (dump_write) |
1461 | write_dump(dump_write); | 1483 | write_dump(dump_write); |
1462 | 1484 | ||
1463 | return 0; | 1485 | return err; |
1464 | } | 1486 | } |
diff --git a/scripts/package/mkspec b/scripts/package/mkspec index df892841b118..ffd61fe0c1ad 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec | |||
@@ -63,9 +63,9 @@ fi | |||
63 | 63 | ||
64 | echo "%install" | 64 | echo "%install" |
65 | echo "%ifarch ia64" | 65 | echo "%ifarch ia64" |
66 | echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib $RPM_BUILD_ROOT/lib/modules' | 66 | echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib/modules' |
67 | echo "%else" | 67 | echo "%else" |
68 | echo 'mkdir -p $RPM_BUILD_ROOT/boot $RPM_BUILD_ROOT/lib $RPM_BUILD_ROOT/lib/modules' | 68 | echo 'mkdir -p $RPM_BUILD_ROOT/boot $RPM_BUILD_ROOT/lib/modules' |
69 | echo "%endif" | 69 | echo "%endif" |
70 | 70 | ||
71 | echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{_smp_mflags} modules_install' | 71 | echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{_smp_mflags} modules_install' |
diff --git a/scripts/unifdef.c b/scripts/unifdef.c new file mode 100644 index 000000000000..552025e72acb --- /dev/null +++ b/scripts/unifdef.c | |||
@@ -0,0 +1,1005 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002 - 2005 Tony Finch <dot@dotat.at>. All rights reserved. | ||
3 | * | ||
4 | * This code is derived from software contributed to Berkeley by Dave Yost. | ||
5 | * It was rewritten to support ANSI C by Tony Finch. The original version of | ||
6 | * unifdef carried the following copyright notice. None of its code remains | ||
7 | * in this version (though some of the names remain). | ||
8 | * | ||
9 | * Copyright (c) 1985, 1993 | ||
10 | * The Regents of the University of California. All rights reserved. | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer. | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in the | ||
19 | * documentation and/or other materials provided with the distribution. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #include <sys/cdefs.h> | ||
35 | |||
36 | #ifndef lint | ||
37 | #if 0 | ||
38 | static const char copyright[] = | ||
39 | "@(#) Copyright (c) 1985, 1993\n\ | ||
40 | The Regents of the University of California. All rights reserved.\n"; | ||
41 | #endif | ||
42 | #ifdef __IDSTRING | ||
43 | __IDSTRING(Berkeley, "@(#)unifdef.c 8.1 (Berkeley) 6/6/93"); | ||
44 | __IDSTRING(NetBSD, "$NetBSD: unifdef.c,v 1.8 2000/07/03 02:51:36 matt Exp $"); | ||
45 | __IDSTRING(dotat, "$dotat: things/unifdef.c,v 1.171 2005/03/08 12:38:48 fanf2 Exp $"); | ||
46 | #endif | ||
47 | #endif /* not lint */ | ||
48 | #ifdef __FBSDID | ||
49 | __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05/21 09:55:09 ru Exp $"); | ||
50 | #endif | ||
51 | |||
52 | /* | ||
53 | * unifdef - remove ifdef'ed lines | ||
54 | * | ||
55 | * Wishlist: | ||
56 | * provide an option which will append the name of the | ||
57 | * appropriate symbol after #else's and #endif's | ||
58 | * provide an option which will check symbols after | ||
59 | * #else's and #endif's to see that they match their | ||
60 | * corresponding #ifdef or #ifndef | ||
61 | * | ||
62 | * The first two items above require better buffer handling, which would | ||
63 | * also make it possible to handle all "dodgy" directives correctly. | ||
64 | */ | ||
65 | |||
66 | #include <ctype.h> | ||
67 | #include <err.h> | ||
68 | #include <stdarg.h> | ||
69 | #include <stdbool.h> | ||
70 | #include <stdio.h> | ||
71 | #include <stdlib.h> | ||
72 | #include <string.h> | ||
73 | #include <unistd.h> | ||
74 | |||
75 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
76 | |||
77 | /* types of input lines: */ | ||
78 | typedef enum { | ||
79 | LT_TRUEI, /* a true #if with ignore flag */ | ||
80 | LT_FALSEI, /* a false #if with ignore flag */ | ||
81 | LT_IF, /* an unknown #if */ | ||
82 | LT_TRUE, /* a true #if */ | ||
83 | LT_FALSE, /* a false #if */ | ||
84 | LT_ELIF, /* an unknown #elif */ | ||
85 | LT_ELTRUE, /* a true #elif */ | ||
86 | LT_ELFALSE, /* a false #elif */ | ||
87 | LT_ELSE, /* #else */ | ||
88 | LT_ENDIF, /* #endif */ | ||
89 | LT_DODGY, /* flag: directive is not on one line */ | ||
90 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, | ||
91 | LT_PLAIN, /* ordinary line */ | ||
92 | LT_EOF, /* end of file */ | ||
93 | LT_COUNT | ||
94 | } Linetype; | ||
95 | |||
96 | static char const * const linetype_name[] = { | ||
97 | "TRUEI", "FALSEI", "IF", "TRUE", "FALSE", | ||
98 | "ELIF", "ELTRUE", "ELFALSE", "ELSE", "ENDIF", | ||
99 | "DODGY TRUEI", "DODGY FALSEI", | ||
100 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", | ||
101 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", | ||
102 | "DODGY ELSE", "DODGY ENDIF", | ||
103 | "PLAIN", "EOF" | ||
104 | }; | ||
105 | |||
106 | /* state of #if processing */ | ||
107 | typedef enum { | ||
108 | IS_OUTSIDE, | ||
109 | IS_FALSE_PREFIX, /* false #if followed by false #elifs */ | ||
110 | IS_TRUE_PREFIX, /* first non-false #(el)if is true */ | ||
111 | IS_PASS_MIDDLE, /* first non-false #(el)if is unknown */ | ||
112 | IS_FALSE_MIDDLE, /* a false #elif after a pass state */ | ||
113 | IS_TRUE_MIDDLE, /* a true #elif after a pass state */ | ||
114 | IS_PASS_ELSE, /* an else after a pass state */ | ||
115 | IS_FALSE_ELSE, /* an else after a true state */ | ||
116 | IS_TRUE_ELSE, /* an else after only false states */ | ||
117 | IS_FALSE_TRAILER, /* #elifs after a true are false */ | ||
118 | IS_COUNT | ||
119 | } Ifstate; | ||
120 | |||
121 | static char const * const ifstate_name[] = { | ||
122 | "OUTSIDE", "FALSE_PREFIX", "TRUE_PREFIX", | ||
123 | "PASS_MIDDLE", "FALSE_MIDDLE", "TRUE_MIDDLE", | ||
124 | "PASS_ELSE", "FALSE_ELSE", "TRUE_ELSE", | ||
125 | "FALSE_TRAILER" | ||
126 | }; | ||
127 | |||
128 | /* state of comment parser */ | ||
129 | typedef enum { | ||
130 | NO_COMMENT = false, /* outside a comment */ | ||
131 | C_COMMENT, /* in a comment like this one */ | ||
132 | CXX_COMMENT, /* between // and end of line */ | ||
133 | STARTING_COMMENT, /* just after slash-backslash-newline */ | ||
134 | FINISHING_COMMENT, /* star-backslash-newline in a C comment */ | ||
135 | CHAR_LITERAL, /* inside '' */ | ||
136 | STRING_LITERAL /* inside "" */ | ||
137 | } Comment_state; | ||
138 | |||
139 | static char const * const comment_name[] = { | ||
140 | "NO", "C", "CXX", "STARTING", "FINISHING", "CHAR", "STRING" | ||
141 | }; | ||
142 | |||
143 | /* state of preprocessor line parser */ | ||
144 | typedef enum { | ||
145 | LS_START, /* only space and comments on this line */ | ||
146 | LS_HASH, /* only space, comments, and a hash */ | ||
147 | LS_DIRTY /* this line can't be a preprocessor line */ | ||
148 | } Line_state; | ||
149 | |||
150 | static char const * const linestate_name[] = { | ||
151 | "START", "HASH", "DIRTY" | ||
152 | }; | ||
153 | |||
154 | /* | ||
155 | * Minimum translation limits from ISO/IEC 9899:1999 5.2.4.1 | ||
156 | */ | ||
157 | #define MAXDEPTH 64 /* maximum #if nesting */ | ||
158 | #define MAXLINE 4096 /* maximum length of line */ | ||
159 | #define MAXSYMS 4096 /* maximum number of symbols */ | ||
160 | |||
161 | /* | ||
162 | * Sometimes when editing a keyword the replacement text is longer, so | ||
163 | * we leave some space at the end of the tline buffer to accommodate this. | ||
164 | */ | ||
165 | #define EDITSLOP 10 | ||
166 | |||
167 | /* | ||
168 | * Globals. | ||
169 | */ | ||
170 | |||
171 | static bool complement; /* -c: do the complement */ | ||
172 | static bool debugging; /* -d: debugging reports */ | ||
173 | static bool iocccok; /* -e: fewer IOCCC errors */ | ||
174 | static bool killconsts; /* -k: eval constant #ifs */ | ||
175 | static bool lnblank; /* -l: blank deleted lines */ | ||
176 | static bool lnnum; /* -n: add #line directives */ | ||
177 | static bool symlist; /* -s: output symbol list */ | ||
178 | static bool text; /* -t: this is a text file */ | ||
179 | |||
180 | static const char *symname[MAXSYMS]; /* symbol name */ | ||
181 | static const char *value[MAXSYMS]; /* -Dsym=value */ | ||
182 | static bool ignore[MAXSYMS]; /* -iDsym or -iUsym */ | ||
183 | static int nsyms; /* number of symbols */ | ||
184 | |||
185 | static FILE *input; /* input file pointer */ | ||
186 | static const char *filename; /* input file name */ | ||
187 | static int linenum; /* current line number */ | ||
188 | |||
189 | static char tline[MAXLINE+EDITSLOP];/* input buffer plus space */ | ||
190 | static char *keyword; /* used for editing #elif's */ | ||
191 | |||
192 | static Comment_state incomment; /* comment parser state */ | ||
193 | static Line_state linestate; /* #if line parser state */ | ||
194 | static Ifstate ifstate[MAXDEPTH]; /* #if processor state */ | ||
195 | static bool ignoring[MAXDEPTH]; /* ignore comments state */ | ||
196 | static int stifline[MAXDEPTH]; /* start of current #if */ | ||
197 | static int depth; /* current #if nesting */ | ||
198 | static int delcount; /* count of deleted lines */ | ||
199 | static bool keepthis; /* don't delete constant #if */ | ||
200 | |||
201 | static int exitstat; /* program exit status */ | ||
202 | |||
203 | static void addsym(bool, bool, char *); | ||
204 | static void debug(const char *, ...); | ||
205 | static void done(void); | ||
206 | static void error(const char *); | ||
207 | static int findsym(const char *); | ||
208 | static void flushline(bool); | ||
209 | static Linetype getline(void); | ||
210 | static Linetype ifeval(const char **); | ||
211 | static void ignoreoff(void); | ||
212 | static void ignoreon(void); | ||
213 | static void keywordedit(const char *); | ||
214 | static void nest(void); | ||
215 | static void process(void); | ||
216 | static const char *skipcomment(const char *); | ||
217 | static const char *skipsym(const char *); | ||
218 | static void state(Ifstate); | ||
219 | static int strlcmp(const char *, const char *, size_t); | ||
220 | static void unnest(void); | ||
221 | static void usage(void); | ||
222 | |||
223 | #define endsym(c) (!isalpha((unsigned char)c) && !isdigit((unsigned char)c) && c != '_') | ||
224 | |||
225 | /* | ||
226 | * The main program. | ||
227 | */ | ||
228 | int | ||
229 | main(int argc, char *argv[]) | ||
230 | { | ||
231 | int opt; | ||
232 | |||
233 | while ((opt = getopt(argc, argv, "i:D:U:I:cdeklnst")) != -1) | ||
234 | switch (opt) { | ||
235 | case 'i': /* treat stuff controlled by these symbols as text */ | ||
236 | /* | ||
237 | * For strict backwards-compatibility the U or D | ||
238 | * should be immediately after the -i but it doesn't | ||
239 | * matter much if we relax that requirement. | ||
240 | */ | ||
241 | opt = *optarg++; | ||
242 | if (opt == 'D') | ||
243 | addsym(true, true, optarg); | ||
244 | else if (opt == 'U') | ||
245 | addsym(true, false, optarg); | ||
246 | else | ||
247 | usage(); | ||
248 | break; | ||
249 | case 'D': /* define a symbol */ | ||
250 | addsym(false, true, optarg); | ||
251 | break; | ||
252 | case 'U': /* undef a symbol */ | ||
253 | addsym(false, false, optarg); | ||
254 | break; | ||
255 | case 'I': | ||
256 | /* no-op for compatibility with cpp */ | ||
257 | break; | ||
258 | case 'c': /* treat -D as -U and vice versa */ | ||
259 | complement = true; | ||
260 | break; | ||
261 | case 'd': | ||
262 | debugging = true; | ||
263 | break; | ||
264 | case 'e': /* fewer errors from dodgy lines */ | ||
265 | iocccok = true; | ||
266 | break; | ||
267 | case 'k': /* process constant #ifs */ | ||
268 | killconsts = true; | ||
269 | break; | ||
270 | case 'l': /* blank deleted lines instead of omitting them */ | ||
271 | lnblank = true; | ||
272 | break; | ||
273 | case 'n': /* add #line directive after deleted lines */ | ||
274 | lnnum = true; | ||
275 | break; | ||
276 | case 's': /* only output list of symbols that control #ifs */ | ||
277 | symlist = true; | ||
278 | break; | ||
279 | case 't': /* don't parse C comments */ | ||
280 | text = true; | ||
281 | break; | ||
282 | default: | ||
283 | usage(); | ||
284 | } | ||
285 | argc -= optind; | ||
286 | argv += optind; | ||
287 | if (argc > 1) { | ||
288 | errx(2, "can only do one file"); | ||
289 | } else if (argc == 1 && strcmp(*argv, "-") != 0) { | ||
290 | filename = *argv; | ||
291 | input = fopen(filename, "r"); | ||
292 | if (input == NULL) | ||
293 | err(2, "can't open %s", filename); | ||
294 | } else { | ||
295 | filename = "[stdin]"; | ||
296 | input = stdin; | ||
297 | } | ||
298 | process(); | ||
299 | abort(); /* bug */ | ||
300 | } | ||
301 | |||
302 | static void | ||
303 | usage(void) | ||
304 | { | ||
305 | fprintf(stderr, "usage: unifdef [-cdeklnst] [-Ipath]" | ||
306 | " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); | ||
307 | exit(2); | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * A state transition function alters the global #if processing state | ||
312 | * in a particular way. The table below is indexed by the current | ||
313 | * processing state and the type of the current line. | ||
314 | * | ||
315 | * Nesting is handled by keeping a stack of states; some transition | ||
316 | * functions increase or decrease the depth. They also maintain the | ||
317 | * ignore state on a stack. In some complicated cases they have to | ||
318 | * alter the preprocessor directive, as follows. | ||
319 | * | ||
320 | * When we have processed a group that starts off with a known-false | ||
321 | * #if/#elif sequence (which has therefore been deleted) followed by a | ||
322 | * #elif that we don't understand and therefore must keep, we edit the | ||
323 | * latter into a #if to keep the nesting correct. | ||
324 | * | ||
325 | * When we find a true #elif in a group, the following block will | ||
326 | * always be kept and the rest of the sequence after the next #elif or | ||
327 | * #else will be discarded. We edit the #elif into a #else and the | ||
328 | * following directive to #endif since this has the desired behaviour. | ||
329 | * | ||
330 | * "Dodgy" directives are split across multiple lines, the most common | ||
331 | * example being a multi-line comment hanging off the right of the | ||
332 | * directive. We can handle them correctly only if there is no change | ||
333 | * from printing to dropping (or vice versa) caused by that directive. | ||
334 | * If the directive is the first of a group we have a choice between | ||
335 | * failing with an error, or passing it through unchanged instead of | ||
336 | * evaluating it. The latter is not the default to avoid questions from | ||
337 | * users about unifdef unexpectedly leaving behind preprocessor directives. | ||
338 | */ | ||
339 | typedef void state_fn(void); | ||
340 | |||
341 | /* report an error */ | ||
342 | static void Eelif (void) { error("Inappropriate #elif"); } | ||
343 | static void Eelse (void) { error("Inappropriate #else"); } | ||
344 | static void Eendif(void) { error("Inappropriate #endif"); } | ||
345 | static void Eeof (void) { error("Premature EOF"); } | ||
346 | static void Eioccc(void) { error("Obfuscated preprocessor control line"); } | ||
347 | /* plain line handling */ | ||
348 | static void print (void) { flushline(true); } | ||
349 | static void drop (void) { flushline(false); } | ||
350 | /* output lacks group's start line */ | ||
351 | static void Strue (void) { drop(); ignoreoff(); state(IS_TRUE_PREFIX); } | ||
352 | static void Sfalse(void) { drop(); ignoreoff(); state(IS_FALSE_PREFIX); } | ||
353 | static void Selse (void) { drop(); state(IS_TRUE_ELSE); } | ||
354 | /* print/pass this block */ | ||
355 | static void Pelif (void) { print(); ignoreoff(); state(IS_PASS_MIDDLE); } | ||
356 | static void Pelse (void) { print(); state(IS_PASS_ELSE); } | ||
357 | static void Pendif(void) { print(); unnest(); } | ||
358 | /* discard this block */ | ||
359 | static void Dfalse(void) { drop(); ignoreoff(); state(IS_FALSE_TRAILER); } | ||
360 | static void Delif (void) { drop(); ignoreoff(); state(IS_FALSE_MIDDLE); } | ||
361 | static void Delse (void) { drop(); state(IS_FALSE_ELSE); } | ||
362 | static void Dendif(void) { drop(); unnest(); } | ||
363 | /* first line of group */ | ||
364 | static void Fdrop (void) { nest(); Dfalse(); } | ||
365 | static void Fpass (void) { nest(); Pelif(); } | ||
366 | static void Ftrue (void) { nest(); Strue(); } | ||
367 | static void Ffalse(void) { nest(); Sfalse(); } | ||
368 | /* variable pedantry for obfuscated lines */ | ||
369 | static void Oiffy (void) { if (!iocccok) Eioccc(); Fpass(); ignoreon(); } | ||
370 | static void Oif (void) { if (!iocccok) Eioccc(); Fpass(); } | ||
371 | static void Oelif (void) { if (!iocccok) Eioccc(); Pelif(); } | ||
372 | /* ignore comments in this block */ | ||
373 | static void Idrop (void) { Fdrop(); ignoreon(); } | ||
374 | static void Itrue (void) { Ftrue(); ignoreon(); } | ||
375 | static void Ifalse(void) { Ffalse(); ignoreon(); } | ||
376 | /* edit this line */ | ||
377 | static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } | ||
378 | static void Mtrue (void) { keywordedit("else\n"); state(IS_TRUE_MIDDLE); } | ||
379 | static void Melif (void) { keywordedit("endif\n"); state(IS_FALSE_TRAILER); } | ||
380 | static void Melse (void) { keywordedit("endif\n"); state(IS_FALSE_ELSE); } | ||
381 | |||
382 | static state_fn * const trans_table[IS_COUNT][LT_COUNT] = { | ||
383 | /* IS_OUTSIDE */ | ||
384 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, | ||
385 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, | ||
386 | print, done }, | ||
387 | /* IS_FALSE_PREFIX */ | ||
388 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, | ||
389 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, | ||
390 | drop, Eeof }, | ||
391 | /* IS_TRUE_PREFIX */ | ||
392 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, | ||
393 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | ||
394 | print, Eeof }, | ||
395 | /* IS_PASS_MIDDLE */ | ||
396 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, | ||
397 | Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, | ||
398 | print, Eeof }, | ||
399 | /* IS_FALSE_MIDDLE */ | ||
400 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, | ||
401 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | ||
402 | drop, Eeof }, | ||
403 | /* IS_TRUE_MIDDLE */ | ||
404 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, | ||
405 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, | ||
406 | print, Eeof }, | ||
407 | /* IS_PASS_ELSE */ | ||
408 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, | ||
409 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, | ||
410 | print, Eeof }, | ||
411 | /* IS_FALSE_ELSE */ | ||
412 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, | ||
413 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, | ||
414 | drop, Eeof }, | ||
415 | /* IS_TRUE_ELSE */ | ||
416 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, | ||
417 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, | ||
418 | print, Eeof }, | ||
419 | /* IS_FALSE_TRAILER */ | ||
420 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, | ||
421 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, | ||
422 | drop, Eeof } | ||
423 | /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF | ||
424 | TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) | ||
425 | PLAIN EOF */ | ||
426 | }; | ||
427 | |||
428 | /* | ||
429 | * State machine utility functions | ||
430 | */ | ||
431 | static void | ||
432 | done(void) | ||
433 | { | ||
434 | if (incomment) | ||
435 | error("EOF in comment"); | ||
436 | exit(exitstat); | ||
437 | } | ||
438 | static void | ||
439 | ignoreoff(void) | ||
440 | { | ||
441 | if (depth == 0) | ||
442 | abort(); /* bug */ | ||
443 | ignoring[depth] = ignoring[depth-1]; | ||
444 | } | ||
445 | static void | ||
446 | ignoreon(void) | ||
447 | { | ||
448 | ignoring[depth] = true; | ||
449 | } | ||
450 | static void | ||
451 | keywordedit(const char *replacement) | ||
452 | { | ||
453 | size_t size = tline + sizeof(tline) - keyword; | ||
454 | char *dst = keyword; | ||
455 | const char *src = replacement; | ||
456 | if (size != 0) { | ||
457 | while ((--size != 0) && (*src != '\0')) | ||
458 | *dst++ = *src++; | ||
459 | *dst = '\0'; | ||
460 | } | ||
461 | print(); | ||
462 | } | ||
463 | static void | ||
464 | nest(void) | ||
465 | { | ||
466 | depth += 1; | ||
467 | if (depth >= MAXDEPTH) | ||
468 | error("Too many levels of nesting"); | ||
469 | stifline[depth] = linenum; | ||
470 | } | ||
471 | static void | ||
472 | unnest(void) | ||
473 | { | ||
474 | if (depth == 0) | ||
475 | abort(); /* bug */ | ||
476 | depth -= 1; | ||
477 | } | ||
478 | static void | ||
479 | state(Ifstate is) | ||
480 | { | ||
481 | ifstate[depth] = is; | ||
482 | } | ||
483 | |||
484 | /* | ||
485 | * Write a line to the output or not, according to command line options. | ||
486 | */ | ||
487 | static void | ||
488 | flushline(bool keep) | ||
489 | { | ||
490 | if (symlist) | ||
491 | return; | ||
492 | if (keep ^ complement) { | ||
493 | if (lnnum && delcount > 0) | ||
494 | printf("#line %d\n", linenum); | ||
495 | fputs(tline, stdout); | ||
496 | delcount = 0; | ||
497 | } else { | ||
498 | if (lnblank) | ||
499 | putc('\n', stdout); | ||
500 | exitstat = 1; | ||
501 | delcount += 1; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | /* | ||
506 | * The driver for the state machine. | ||
507 | */ | ||
508 | static void | ||
509 | process(void) | ||
510 | { | ||
511 | Linetype lineval; | ||
512 | |||
513 | for (;;) { | ||
514 | linenum++; | ||
515 | lineval = getline(); | ||
516 | trans_table[ifstate[depth]][lineval](); | ||
517 | debug("process %s -> %s depth %d", | ||
518 | linetype_name[lineval], | ||
519 | ifstate_name[ifstate[depth]], depth); | ||
520 | } | ||
521 | } | ||
522 | |||
523 | /* | ||
524 | * Parse a line and determine its type. We keep the preprocessor line | ||
525 | * parser state between calls in the global variable linestate, with | ||
526 | * help from skipcomment(). | ||
527 | */ | ||
528 | static Linetype | ||
529 | getline(void) | ||
530 | { | ||
531 | const char *cp; | ||
532 | int cursym; | ||
533 | int kwlen; | ||
534 | Linetype retval; | ||
535 | Comment_state wascomment; | ||
536 | |||
537 | if (fgets(tline, MAXLINE, input) == NULL) | ||
538 | return (LT_EOF); | ||
539 | retval = LT_PLAIN; | ||
540 | wascomment = incomment; | ||
541 | cp = skipcomment(tline); | ||
542 | if (linestate == LS_START) { | ||
543 | if (*cp == '#') { | ||
544 | linestate = LS_HASH; | ||
545 | cp = skipcomment(cp + 1); | ||
546 | } else if (*cp != '\0') | ||
547 | linestate = LS_DIRTY; | ||
548 | } | ||
549 | if (!incomment && linestate == LS_HASH) { | ||
550 | keyword = tline + (cp - tline); | ||
551 | cp = skipsym(cp); | ||
552 | kwlen = cp - keyword; | ||
553 | /* no way can we deal with a continuation inside a keyword */ | ||
554 | if (strncmp(cp, "\\\n", 2) == 0) | ||
555 | Eioccc(); | ||
556 | if (strlcmp("ifdef", keyword, kwlen) == 0 || | ||
557 | strlcmp("ifndef", keyword, kwlen) == 0) { | ||
558 | cp = skipcomment(cp); | ||
559 | if ((cursym = findsym(cp)) < 0) | ||
560 | retval = LT_IF; | ||
561 | else { | ||
562 | retval = (keyword[2] == 'n') | ||
563 | ? LT_FALSE : LT_TRUE; | ||
564 | if (value[cursym] == NULL) | ||
565 | retval = (retval == LT_TRUE) | ||
566 | ? LT_FALSE : LT_TRUE; | ||
567 | if (ignore[cursym]) | ||
568 | retval = (retval == LT_TRUE) | ||
569 | ? LT_TRUEI : LT_FALSEI; | ||
570 | } | ||
571 | cp = skipsym(cp); | ||
572 | } else if (strlcmp("if", keyword, kwlen) == 0) | ||
573 | retval = ifeval(&cp); | ||
574 | else if (strlcmp("elif", keyword, kwlen) == 0) | ||
575 | retval = ifeval(&cp) - LT_IF + LT_ELIF; | ||
576 | else if (strlcmp("else", keyword, kwlen) == 0) | ||
577 | retval = LT_ELSE; | ||
578 | else if (strlcmp("endif", keyword, kwlen) == 0) | ||
579 | retval = LT_ENDIF; | ||
580 | else { | ||
581 | linestate = LS_DIRTY; | ||
582 | retval = LT_PLAIN; | ||
583 | } | ||
584 | cp = skipcomment(cp); | ||
585 | if (*cp != '\0') { | ||
586 | linestate = LS_DIRTY; | ||
587 | if (retval == LT_TRUE || retval == LT_FALSE || | ||
588 | retval == LT_TRUEI || retval == LT_FALSEI) | ||
589 | retval = LT_IF; | ||
590 | if (retval == LT_ELTRUE || retval == LT_ELFALSE) | ||
591 | retval = LT_ELIF; | ||
592 | } | ||
593 | if (retval != LT_PLAIN && (wascomment || incomment)) { | ||
594 | retval += LT_DODGY; | ||
595 | if (incomment) | ||
596 | linestate = LS_DIRTY; | ||
597 | } | ||
598 | /* skipcomment should have changed the state */ | ||
599 | if (linestate == LS_HASH) | ||
600 | abort(); /* bug */ | ||
601 | } | ||
602 | if (linestate == LS_DIRTY) { | ||
603 | while (*cp != '\0') | ||
604 | cp = skipcomment(cp + 1); | ||
605 | } | ||
606 | debug("parser %s comment %s line", | ||
607 | comment_name[incomment], linestate_name[linestate]); | ||
608 | return (retval); | ||
609 | } | ||
610 | |||
611 | /* | ||
612 | * These are the binary operators that are supported by the expression | ||
613 | * evaluator. Note that if support for division is added then we also | ||
614 | * need short-circuiting booleans because of divide-by-zero. | ||
615 | */ | ||
616 | static int op_lt(int a, int b) { return (a < b); } | ||
617 | static int op_gt(int a, int b) { return (a > b); } | ||
618 | static int op_le(int a, int b) { return (a <= b); } | ||
619 | static int op_ge(int a, int b) { return (a >= b); } | ||
620 | static int op_eq(int a, int b) { return (a == b); } | ||
621 | static int op_ne(int a, int b) { return (a != b); } | ||
622 | static int op_or(int a, int b) { return (a || b); } | ||
623 | static int op_and(int a, int b) { return (a && b); } | ||
624 | |||
625 | /* | ||
626 | * An evaluation function takes three arguments, as follows: (1) a pointer to | ||
627 | * an element of the precedence table which lists the operators at the current | ||
628 | * level of precedence; (2) a pointer to an integer which will receive the | ||
629 | * value of the expression; and (3) a pointer to a char* that points to the | ||
630 | * expression to be evaluated and that is updated to the end of the expression | ||
631 | * when evaluation is complete. The function returns LT_FALSE if the value of | ||
632 | * the expression is zero, LT_TRUE if it is non-zero, or LT_IF if the | ||
633 | * expression could not be evaluated. | ||
634 | */ | ||
635 | struct ops; | ||
636 | |||
637 | typedef Linetype eval_fn(const struct ops *, int *, const char **); | ||
638 | |||
639 | static eval_fn eval_table, eval_unary; | ||
640 | |||
641 | /* | ||
642 | * The precedence table. Expressions involving binary operators are evaluated | ||
643 | * in a table-driven way by eval_table. When it evaluates a subexpression it | ||
644 | * calls the inner function with its first argument pointing to the next | ||
645 | * element of the table. Innermost expressions have special non-table-driven | ||
646 | * handling. | ||
647 | */ | ||
648 | static const struct ops { | ||
649 | eval_fn *inner; | ||
650 | struct op { | ||
651 | const char *str; | ||
652 | int (*fn)(int, int); | ||
653 | } op[5]; | ||
654 | } eval_ops[] = { | ||
655 | { eval_table, { { "||", op_or } } }, | ||
656 | { eval_table, { { "&&", op_and } } }, | ||
657 | { eval_table, { { "==", op_eq }, | ||
658 | { "!=", op_ne } } }, | ||
659 | { eval_unary, { { "<=", op_le }, | ||
660 | { ">=", op_ge }, | ||
661 | { "<", op_lt }, | ||
662 | { ">", op_gt } } } | ||
663 | }; | ||
664 | |||
665 | /* | ||
666 | * Function for evaluating the innermost parts of expressions, | ||
667 | * viz. !expr (expr) defined(symbol) symbol number | ||
668 | * We reset the keepthis flag when we find a non-constant subexpression. | ||
669 | */ | ||
670 | static Linetype | ||
671 | eval_unary(const struct ops *ops, int *valp, const char **cpp) | ||
672 | { | ||
673 | const char *cp; | ||
674 | char *ep; | ||
675 | int sym; | ||
676 | |||
677 | cp = skipcomment(*cpp); | ||
678 | if (*cp == '!') { | ||
679 | debug("eval%d !", ops - eval_ops); | ||
680 | cp++; | ||
681 | if (eval_unary(ops, valp, &cp) == LT_IF) | ||
682 | return (LT_IF); | ||
683 | *valp = !*valp; | ||
684 | } else if (*cp == '(') { | ||
685 | cp++; | ||
686 | debug("eval%d (", ops - eval_ops); | ||
687 | if (eval_table(eval_ops, valp, &cp) == LT_IF) | ||
688 | return (LT_IF); | ||
689 | cp = skipcomment(cp); | ||
690 | if (*cp++ != ')') | ||
691 | return (LT_IF); | ||
692 | } else if (isdigit((unsigned char)*cp)) { | ||
693 | debug("eval%d number", ops - eval_ops); | ||
694 | *valp = strtol(cp, &ep, 0); | ||
695 | cp = skipsym(cp); | ||
696 | } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { | ||
697 | cp = skipcomment(cp+7); | ||
698 | debug("eval%d defined", ops - eval_ops); | ||
699 | if (*cp++ != '(') | ||
700 | return (LT_IF); | ||
701 | cp = skipcomment(cp); | ||
702 | sym = findsym(cp); | ||
703 | if (sym < 0) | ||
704 | return (LT_IF); | ||
705 | *valp = (value[sym] != NULL); | ||
706 | cp = skipsym(cp); | ||
707 | cp = skipcomment(cp); | ||
708 | if (*cp++ != ')') | ||
709 | return (LT_IF); | ||
710 | keepthis = false; | ||
711 | } else if (!endsym(*cp)) { | ||
712 | debug("eval%d symbol", ops - eval_ops); | ||
713 | sym = findsym(cp); | ||
714 | if (sym < 0) | ||
715 | return (LT_IF); | ||
716 | if (value[sym] == NULL) | ||
717 | *valp = 0; | ||
718 | else { | ||
719 | *valp = strtol(value[sym], &ep, 0); | ||
720 | if (*ep != '\0' || ep == value[sym]) | ||
721 | return (LT_IF); | ||
722 | } | ||
723 | cp = skipsym(cp); | ||
724 | keepthis = false; | ||
725 | } else { | ||
726 | debug("eval%d bad expr", ops - eval_ops); | ||
727 | return (LT_IF); | ||
728 | } | ||
729 | |||
730 | *cpp = cp; | ||
731 | debug("eval%d = %d", ops - eval_ops, *valp); | ||
732 | return (*valp ? LT_TRUE : LT_FALSE); | ||
733 | } | ||
734 | |||
735 | /* | ||
736 | * Table-driven evaluation of binary operators. | ||
737 | */ | ||
738 | static Linetype | ||
739 | eval_table(const struct ops *ops, int *valp, const char **cpp) | ||
740 | { | ||
741 | const struct op *op; | ||
742 | const char *cp; | ||
743 | int val; | ||
744 | |||
745 | debug("eval%d", ops - eval_ops); | ||
746 | cp = *cpp; | ||
747 | if (ops->inner(ops+1, valp, &cp) == LT_IF) | ||
748 | return (LT_IF); | ||
749 | for (;;) { | ||
750 | cp = skipcomment(cp); | ||
751 | for (op = ops->op; op->str != NULL; op++) | ||
752 | if (strncmp(cp, op->str, strlen(op->str)) == 0) | ||
753 | break; | ||
754 | if (op->str == NULL) | ||
755 | break; | ||
756 | cp += strlen(op->str); | ||
757 | debug("eval%d %s", ops - eval_ops, op->str); | ||
758 | if (ops->inner(ops+1, &val, &cp) == LT_IF) | ||
759 | return (LT_IF); | ||
760 | *valp = op->fn(*valp, val); | ||
761 | } | ||
762 | |||
763 | *cpp = cp; | ||
764 | debug("eval%d = %d", ops - eval_ops, *valp); | ||
765 | return (*valp ? LT_TRUE : LT_FALSE); | ||
766 | } | ||
767 | |||
768 | /* | ||
769 | * Evaluate the expression on a #if or #elif line. If we can work out | ||
770 | * the result we return LT_TRUE or LT_FALSE accordingly, otherwise we | ||
771 | * return just a generic LT_IF. | ||
772 | */ | ||
773 | static Linetype | ||
774 | ifeval(const char **cpp) | ||
775 | { | ||
776 | int ret; | ||
777 | int val; | ||
778 | |||
779 | debug("eval %s", *cpp); | ||
780 | keepthis = killconsts ? false : true; | ||
781 | ret = eval_table(eval_ops, &val, cpp); | ||
782 | debug("eval = %d", val); | ||
783 | return (keepthis ? LT_IF : ret); | ||
784 | } | ||
785 | |||
786 | /* | ||
787 | * Skip over comments, strings, and character literals and stop at the | ||
788 | * next character position that is not whitespace. Between calls we keep | ||
789 | * the comment state in the global variable incomment, and we also adjust | ||
790 | * the global variable linestate when we see a newline. | ||
791 | * XXX: doesn't cope with the buffer splitting inside a state transition. | ||
792 | */ | ||
793 | static const char * | ||
794 | skipcomment(const char *cp) | ||
795 | { | ||
796 | if (text || ignoring[depth]) { | ||
797 | for (; isspace((unsigned char)*cp); cp++) | ||
798 | if (*cp == '\n') | ||
799 | linestate = LS_START; | ||
800 | return (cp); | ||
801 | } | ||
802 | while (*cp != '\0') | ||
803 | /* don't reset to LS_START after a line continuation */ | ||
804 | if (strncmp(cp, "\\\n", 2) == 0) | ||
805 | cp += 2; | ||
806 | else switch (incomment) { | ||
807 | case NO_COMMENT: | ||
808 | if (strncmp(cp, "/\\\n", 3) == 0) { | ||
809 | incomment = STARTING_COMMENT; | ||
810 | cp += 3; | ||
811 | } else if (strncmp(cp, "/*", 2) == 0) { | ||
812 | incomment = C_COMMENT; | ||
813 | cp += 2; | ||
814 | } else if (strncmp(cp, "//", 2) == 0) { | ||
815 | incomment = CXX_COMMENT; | ||
816 | cp += 2; | ||
817 | } else if (strncmp(cp, "\'", 1) == 0) { | ||
818 | incomment = CHAR_LITERAL; | ||
819 | linestate = LS_DIRTY; | ||
820 | cp += 1; | ||
821 | } else if (strncmp(cp, "\"", 1) == 0) { | ||
822 | incomment = STRING_LITERAL; | ||
823 | linestate = LS_DIRTY; | ||
824 | cp += 1; | ||
825 | } else if (strncmp(cp, "\n", 1) == 0) { | ||
826 | linestate = LS_START; | ||
827 | cp += 1; | ||
828 | } else if (strchr(" \t", *cp) != NULL) { | ||
829 | cp += 1; | ||
830 | } else | ||
831 | return (cp); | ||
832 | continue; | ||
833 | case CXX_COMMENT: | ||
834 | if (strncmp(cp, "\n", 1) == 0) { | ||
835 | incomment = NO_COMMENT; | ||
836 | linestate = LS_START; | ||
837 | } | ||
838 | cp += 1; | ||
839 | continue; | ||
840 | case CHAR_LITERAL: | ||
841 | case STRING_LITERAL: | ||
842 | if ((incomment == CHAR_LITERAL && cp[0] == '\'') || | ||
843 | (incomment == STRING_LITERAL && cp[0] == '\"')) { | ||
844 | incomment = NO_COMMENT; | ||
845 | cp += 1; | ||
846 | } else if (cp[0] == '\\') { | ||
847 | if (cp[1] == '\0') | ||
848 | cp += 1; | ||
849 | else | ||
850 | cp += 2; | ||
851 | } else if (strncmp(cp, "\n", 1) == 0) { | ||
852 | if (incomment == CHAR_LITERAL) | ||
853 | error("unterminated char literal"); | ||
854 | else | ||
855 | error("unterminated string literal"); | ||
856 | } else | ||
857 | cp += 1; | ||
858 | continue; | ||
859 | case C_COMMENT: | ||
860 | if (strncmp(cp, "*\\\n", 3) == 0) { | ||
861 | incomment = FINISHING_COMMENT; | ||
862 | cp += 3; | ||
863 | } else if (strncmp(cp, "*/", 2) == 0) { | ||
864 | incomment = NO_COMMENT; | ||
865 | cp += 2; | ||
866 | } else | ||
867 | cp += 1; | ||
868 | continue; | ||
869 | case STARTING_COMMENT: | ||
870 | if (*cp == '*') { | ||
871 | incomment = C_COMMENT; | ||
872 | cp += 1; | ||
873 | } else if (*cp == '/') { | ||
874 | incomment = CXX_COMMENT; | ||
875 | cp += 1; | ||
876 | } else { | ||
877 | incomment = NO_COMMENT; | ||
878 | linestate = LS_DIRTY; | ||
879 | } | ||
880 | continue; | ||
881 | case FINISHING_COMMENT: | ||
882 | if (*cp == '/') { | ||
883 | incomment = NO_COMMENT; | ||
884 | cp += 1; | ||
885 | } else | ||
886 | incomment = C_COMMENT; | ||
887 | continue; | ||
888 | default: | ||
889 | abort(); /* bug */ | ||
890 | } | ||
891 | return (cp); | ||
892 | } | ||
893 | |||
894 | /* | ||
895 | * Skip over an identifier. | ||
896 | */ | ||
897 | static const char * | ||
898 | skipsym(const char *cp) | ||
899 | { | ||
900 | while (!endsym(*cp)) | ||
901 | ++cp; | ||
902 | return (cp); | ||
903 | } | ||
904 | |||
905 | /* | ||
906 | * Look for the symbol in the symbol table. If is is found, we return | ||
907 | * the symbol table index, else we return -1. | ||
908 | */ | ||
909 | static int | ||
910 | findsym(const char *str) | ||
911 | { | ||
912 | const char *cp; | ||
913 | int symind; | ||
914 | |||
915 | cp = skipsym(str); | ||
916 | if (cp == str) | ||
917 | return (-1); | ||
918 | if (symlist) { | ||
919 | printf("%.*s\n", (int)(cp-str), str); | ||
920 | /* we don't care about the value of the symbol */ | ||
921 | return (0); | ||
922 | } | ||
923 | for (symind = 0; symind < nsyms; ++symind) { | ||
924 | if (strlcmp(symname[symind], str, cp-str) == 0) { | ||
925 | debug("findsym %s %s", symname[symind], | ||
926 | value[symind] ? value[symind] : ""); | ||
927 | return (symind); | ||
928 | } | ||
929 | } | ||
930 | return (-1); | ||
931 | } | ||
932 | |||
933 | /* | ||
934 | * Add a symbol to the symbol table. | ||
935 | */ | ||
936 | static void | ||
937 | addsym(bool ignorethis, bool definethis, char *sym) | ||
938 | { | ||
939 | int symind; | ||
940 | char *val; | ||
941 | |||
942 | symind = findsym(sym); | ||
943 | if (symind < 0) { | ||
944 | if (nsyms >= MAXSYMS) | ||
945 | errx(2, "too many symbols"); | ||
946 | symind = nsyms++; | ||
947 | } | ||
948 | symname[symind] = sym; | ||
949 | ignore[symind] = ignorethis; | ||
950 | val = sym + (skipsym(sym) - sym); | ||
951 | if (definethis) { | ||
952 | if (*val == '=') { | ||
953 | value[symind] = val+1; | ||
954 | *val = '\0'; | ||
955 | } else if (*val == '\0') | ||
956 | value[symind] = ""; | ||
957 | else | ||
958 | usage(); | ||
959 | } else { | ||
960 | if (*val != '\0') | ||
961 | usage(); | ||
962 | value[symind] = NULL; | ||
963 | } | ||
964 | } | ||
965 | |||
966 | /* | ||
967 | * Compare s with n characters of t. | ||
968 | * The same as strncmp() except that it checks that s[n] == '\0'. | ||
969 | */ | ||
970 | static int | ||
971 | strlcmp(const char *s, const char *t, size_t n) | ||
972 | { | ||
973 | while (n-- && *t != '\0') | ||
974 | if (*s != *t) | ||
975 | return ((unsigned char)*s - (unsigned char)*t); | ||
976 | else | ||
977 | ++s, ++t; | ||
978 | return ((unsigned char)*s); | ||
979 | } | ||
980 | |||
981 | /* | ||
982 | * Diagnostics. | ||
983 | */ | ||
984 | static void | ||
985 | debug(const char *msg, ...) | ||
986 | { | ||
987 | va_list ap; | ||
988 | |||
989 | if (debugging) { | ||
990 | va_start(ap, msg); | ||
991 | vwarnx(msg, ap); | ||
992 | va_end(ap); | ||
993 | } | ||
994 | } | ||
995 | |||
996 | static void | ||
997 | error(const char *msg) | ||
998 | { | ||
999 | if (depth == 0) | ||
1000 | warnx("%s: %d: %s", filename, linenum, msg); | ||
1001 | else | ||
1002 | warnx("%s: %d: %s (#if line %d depth %d)", | ||
1003 | filename, linenum, msg, stifline[depth], depth); | ||
1004 | errx(2, "output may be truncated"); | ||
1005 | } | ||
diff --git a/usr/Makefile b/usr/Makefile index 5b31c0b61c76..e338e7bedb29 100644 --- a/usr/Makefile +++ b/usr/Makefile | |||
@@ -3,6 +3,8 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | klibcdirs:; | 5 | klibcdirs:; |
6 | PHONY += klibcdirs | ||
7 | |||
6 | 8 | ||
7 | # Generate builtin.o based on initramfs_data.o | 9 | # Generate builtin.o based on initramfs_data.o |
8 | obj-y := initramfs_data.o | 10 | obj-y := initramfs_data.o |