Blame view

scripts/Makefile.build 17.2 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  # SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
  # ==========================================================================
  # Building
  # ==========================================================================
  
  src := $(obj)
4f1933620   Paul Smith   kbuild: change kb...
7
  PHONY := __build
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
  __build:
d72e5edbf   Sam Ravnborg   kbuild: avoid env...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  # Init all relevant variables used in kbuild files so
  # 1) they have correct type
  # 2) they do not inherit any value from the environment
  obj-y :=
  obj-m :=
  lib-y :=
  lib-m :=
  always :=
  targets :=
  subdir-y :=
  subdir-m :=
  EXTRA_AFLAGS   :=
  EXTRA_CFLAGS   :=
  EXTRA_CPPFLAGS :=
  EXTRA_LDFLAGS  :=
f77bf0142   Sam Ravnborg   kbuild: introduce...
24
25
26
27
  asflags-y  :=
  ccflags-y  :=
  cppflags-y :=
  ldflags-y  :=
d72e5edbf   Sam Ravnborg   kbuild: avoid env...
28

720097d89   Sam Ravnborg   kbuild: introduce...
29
30
  subdir-asflags-y :=
  subdir-ccflags-y :=
3156fd052   Robert P. J. Day   kbuild: fix some ...
31
  # Read auto.conf if it exists, otherwise ignore
c955ccafc   Roman Zippel   kconfig: fix .con...
32
  -include include/config/auto.conf
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33

20a468b51   Sam Ravnborg   kbuild: make cc-v...
34
  include scripts/Kbuild.include
2a6914703   Sam Ravnborg   kbuild: fix make ...
35
  # The filename Kbuild has precedence over Makefile
db8c1a7b2   Sam Ravnborg   kbuild: fix build...
36
  kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
0c53c8e6e   Sam Ravnborg   kbuild: check for...
37
38
  kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
  include $(kbuild-file)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  include scripts/Makefile.lib
3156fd052   Robert P. J. Day   kbuild: fix some ...
40
  # Do not include host rules unless needed
244038743   Emese Revfy   Shared library su...
41
  ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
  include scripts/Makefile.host
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
  ifndef obj
  $(warning kbuild: Makefile.build is included improperly)
  endif
394053f4a   Masahiro Yamada   kbuild: make sing...
47
  ifeq ($(need-modorder),)
c07d8d47b   Masahiro Yamada   kbuild: show hint...
48
49
50
51
52
  ifneq ($(obj-m),)
  $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
  $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
  endif
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  # ===========================================================================
a4954fd77   Masahiro Yamada   kbuild: remove ob...
54
  ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  lib-target := $(obj)/lib.a
f98fe47ce   Masahiro Yamada   kbuild: link $(re...
56
  real-obj-y += $(obj)/lib-ksyms.o
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  endif
f98fe47ce   Masahiro Yamada   kbuild: link $(re...
58
  ifneq ($(strip $(real-obj-y) $(need-builtin)),)
f49821ee3   Nicholas Piggin   kbuild: rename bu...
59
  builtin-target := $(obj)/built-in.a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  endif
7e1319187   Masahiro Yamada   kbuild: do not cr...
61
  ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
551559e13   Tejun Heo   kbuild: implement...
62
  modorder-target := $(obj)/modules.order
1d8001ef3   Masahiro Yamada   kbuild: generate ...
63
  endif
551559e13   Tejun Heo   kbuild: implement...
64

9f69a496f   Masahiro Yamada   kbuild: split out...
65
  mod-targets := $(patsubst %.o, %.mod, $(obj-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  # Linus' kernel sanity checking tool
7d0ea2524   Masahiro Yamada   kbuild: use 'else...
67
68
  ifeq ($(KBUILD_CHECKSRC),1)
    quiet_cmd_checksrc       = CHECK   $<
e5d289100   Masahiro Yamada   kbuild: remove tr...
69
          cmd_checksrc       = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
7d0ea2524   Masahiro Yamada   kbuild: use 'else...
70
71
  else ifeq ($(KBUILD_CHECKSRC),2)
    quiet_cmd_force_checksrc = CHECK   $<
e5d289100   Masahiro Yamada   kbuild: remove tr...
72
          cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  endif
e27128db6   Masahiro Yamada   kbuild: rename KB...
74
  ifneq ($(KBUILD_EXTRA_WARN),)
e5d289100   Masahiro Yamada   kbuild: remove tr...
75
    cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
3a025e1d1   Matthew Wilcox   Add optional chec...
76
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
  # Compile C sources (.c)
  # ---------------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
1e88e415e   Masahiro Yamada   kbuild: Disable e...
80
        cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

767e581d7   Sam Ravnborg   kbuild: enable us...
82
  $(obj)/%.s: $(src)/%.c FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
  	$(call if_changed_dep,cc_s_c)
23d438487   Masahiro Yamada   kbuild: rename cm...
84
85
  quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
  cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86

767e581d7   Sam Ravnborg   kbuild: enable us...
87
  $(obj)/%.i: $(src)/%.c FORCE
23d438487   Masahiro Yamada   kbuild: rename cm...
88
  	$(call if_changed_dep,cpp_i_c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89

4efca4ed0   Nicholas Piggin   kbuild: modversio...
90
91
  # These mirror gensymtypes_S and co below, keep them in synch.
  cmd_gensymtypes_c =                                                         \
37a8d9f67   Sam Ravnborg   kbuild: simplify ...
92
      $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
88110713c   Masahiro Yamada   kbuild: hardcode ...
93
      scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
56067812d   Ard Biesheuvel   kbuild: modversio...
94
       $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
37a8d9f67   Sam Ravnborg   kbuild: simplify ...
95
       $(if $(KBUILD_PRESERVE),-p)                                            \
e26d6b834   Don Zickus   Makefile.build: m...
96
       -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
37a8d9f67   Sam Ravnborg   kbuild: simplify ...
97

15fde6751   Andreas Gruenbacher   kbuild: support f...
98
  quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
37a8d9f67   Sam Ravnborg   kbuild: simplify ...
99
  cmd_cc_symtypes_c =                                                         \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
100
      $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
37a8d9f67   Sam Ravnborg   kbuild: simplify ...
101
      test -s $@ || rm -f $@
15fde6751   Andreas Gruenbacher   kbuild: support f...
102

767e581d7   Sam Ravnborg   kbuild: enable us...
103
  $(obj)/%.symtypes : $(src)/%.c FORCE
64e6c1e12   Andreas Gruenbacher   genksyms: track s...
104
  	$(call cmd,cc_symtypes_c)
15fde6751   Andreas Gruenbacher   kbuild: support f...
105

433db3e26   Vinícius Tinti   kbuild: Add suppo...
106
107
108
109
110
111
112
  # LLVM assembly
  # Generate .ll files from .c
  quiet_cmd_cc_ll_c = CC $(quiet_modtag)  $@
        cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
  
  $(obj)/%.ll: $(src)/%.c FORCE
  	$(call if_changed_dep,cc_ll_c)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
115
116
117
  # C (.c) files
  # The C file is compiled and updated dependency information is generated.
  # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
  
  quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
118
        cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119

ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
120
  ifdef CONFIG_MODVERSIONS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  # When module versioning is enabled the following steps are executed:
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
122
123
124
  # o compile a <file>.o from <file>.c
  # o if <file>.o doesn't contain a __ksymtab version, i.e. does
  #   not export symbols, it's done.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
  # o otherwise, we calculate symbol versions using the good old
  #   genksyms on the preprocessed source and postprocess them in a way
2ea038917   Sam Ravnborg   Revert "kbuild: s...
127
  #   that they are usable as a linker script
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
128
  # o generate .tmp_<file>.o from <file>.o using the linker to
2ea038917   Sam Ravnborg   Revert "kbuild: s...
129
130
  #   replace the unresolved symbols __crc_exported_symbol with
  #   the actual value of the checksum generated by genksyms
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
131
  # o remove .tmp_<file>.o to <file>.o
4efca4ed0   Nicholas Piggin   kbuild: modversio...
132
133
  
  cmd_modversions_c =								\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
134
  	if $(OBJDUMP) -h $@ | grep -q __ksymtab; then				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
135
  		$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
e26d6b834   Don Zickus   Makefile.build: m...
136
137
  		    > $(@D)/.tmp_$(@F:.o=.ver);					\
  										\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
138
  		$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ 		\
e26d6b834   Don Zickus   Makefile.build: m...
139
  			-T $(@D)/.tmp_$(@F:.o=.ver);				\
e26d6b834   Don Zickus   Makefile.build: m...
140
  		mv -f $(@D)/.tmp_$(@F) $@;					\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
141
  		rm -f $(@D)/.tmp_$(@F:.o=.ver);					\
e5d289100   Masahiro Yamada   kbuild: remove tr...
142
  	fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
  endif
8da3821ba   Steven Rostedt   ftrace: create __...
144
  ifdef CONFIG_FTRACE_MCOUNT_RECORD
07d040812   Vasily Gorbik   tracing: Avoid ca...
145
146
  ifndef CC_USING_RECORD_MCOUNT
  # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
72441cb1f   Steven Rostedt   ftrace/x86: Add s...
147
  ifdef BUILD_C_RECORDMCOUNT
85356f802   Steven Rostedt   kbuild/recordmcou...
148
149
150
  ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
    RECORDMCOUNT_FLAGS = -w
  endif
d7b4d6de5   Steven Rostedt   ftrace: Remove re...
151
152
  # Due to recursion, we must skip empty.o.
  # The empty.o file is created in the make process in order to determine
312a3d091   Cao jin   kbuild: trivial c...
153
154
  # the target endianness and word size. It is made before all other C
  # files, including recordmcount.
45677454d   Wu Zhangjin   ftrace: Speed up ...
155
156
  sub_cmd_record_mcount =					\
  	if [ $(@) != "scripts/mod/empty.o" ]; then	\
85356f802   Steven Rostedt   kbuild/recordmcou...
157
  		$(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)";	\
45677454d   Wu Zhangjin   ftrace: Speed up ...
158
  	fi;
d6971822c   Michal Marek   ftrace/kbuild: Ad...
159
160
  recordmcount_source := $(srctree)/scripts/recordmcount.c \
  		    $(srctree)/scripts/recordmcount.h
72441cb1f   Steven Rostedt   ftrace/x86: Add s...
161
  else
4317ee3b6   Masahiro Yamada   kbuild: remove re...
162
  sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
e6299d267   Wu Zhangjin   MIPS: Tracing: Ad...
163
  	"$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
b3acf29af   Steven Rostedt   ftrace, kbuild: c...
164
  	"$(if $(CONFIG_64BIT),64,32)" \
5a4630aad   Joel Stanley   ftrace: Build wit...
165
  	"$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
d503ac531   Masahiro Yamada   kbuild: rename LD...
166
  	"$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
18c167fd6   Shaohua Li   ftrace, ia64: mak...
167
  	"$(if $(part-of-module),1,0)" "$(@)";
d6971822c   Michal Marek   ftrace/kbuild: Ad...
168
  recordmcount_source := $(srctree)/scripts/recordmcount.pl
312a3d091   Cao jin   kbuild: trivial c...
169
  endif # BUILD_C_RECORDMCOUNT
1a49b2fd8   Joe Lawrence   kbuild: strip whi...
170
171
  cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),	\
  	$(sub_cmd_record_mcount))
07d040812   Vasily Gorbik   tracing: Avoid ca...
172
  endif # CC_USING_RECORD_MCOUNT
312a3d091   Cao jin   kbuild: trivial c...
173
  endif # CONFIG_FTRACE_MCOUNT_RECORD
8da3821ba   Steven Rostedt   ftrace: create __...
174

b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
175
  ifdef CONFIG_STACK_VALIDATION
3b27a0c85   Josh Poimboeuf   objtool: Detect a...
176
  ifneq ($(SKIP_STACK_VALIDATION),1)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
177
178
  
  __objtool_obj := $(objtree)/tools/objtool/objtool
11af84744   Josh Poimboeuf   x86/unwind: Renam...
179
  objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
180

ca41b97ed   Peter Zijlstra   objtool: Add modu...
181
  objtool_args += $(if $(part-of-module), --module,)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
182
183
184
  ifndef CONFIG_FRAME_POINTER
  objtool_args += --no-fp
  endif
867ac9d73   Josh Poimboeuf   objtool: Fix gcov...
185
186
187
  ifdef CONFIG_GCOV_KERNEL
  objtool_args += --no-unreachable
  endif
b5bc2231b   Peter Zijlstra   objtool: Add retp...
188
189
190
  ifdef CONFIG_RETPOLINE
    objtool_args += --retpoline
  endif
ea24213d8   Peter Zijlstra   objtool: Add UACC...
191
192
193
  ifdef CONFIG_X86_SMAP
    objtool_args += --uaccess
  endif
b5bc2231b   Peter Zijlstra   objtool: Add retp...
194

b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
195
196
197
198
199
  # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
  # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
  cmd_objtool = $(if $(patsubst y%,, \
  	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
e5d289100   Masahiro Yamada   kbuild: remove tr...
200
  	$(__objtool_obj) $(objtool_args) $@)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
201
202
203
  objtool_obj = $(if $(patsubst y%,, \
  	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  	$(__objtool_obj))
3b27a0c85   Josh Poimboeuf   objtool: Detect a...
204
  endif # SKIP_STACK_VALIDATION
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
205
  endif # CONFIG_STACK_VALIDATION
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
206
207
208
209
  # Rebuild all objects when objtool changes, or is enabled/disabled.
  objtool_dep = $(objtool_obj)					\
  	      $(wildcard include/config/orc/unwinder.h		\
  			 include/config/stack/validation.h)
bbda5ec67   Masahiro Yamada   kbuild: simplify ...
210
211
  ifdef CONFIG_TRIM_UNUSED_KSYMS
  cmd_gen_ksymdeps = \
e5d289100   Masahiro Yamada   kbuild: remove tr...
212
  	$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
bbda5ec67   Masahiro Yamada   kbuild: simplify ...
213
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
  define rule_cc_o_c
3a2429e1f   Masahiro Yamada   kbuild: change if...
215
216
217
218
219
220
221
  	$(call cmd,checksrc)
  	$(call cmd_and_fixdep,cc_o_c)
  	$(call cmd,gen_ksymdeps)
  	$(call cmd,checkdoc)
  	$(call cmd,objtool)
  	$(call cmd,modversions_c)
  	$(call cmd,record_mcount)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
  endef
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
223
  define rule_as_o_S
3a2429e1f   Masahiro Yamada   kbuild: change if...
224
225
226
227
  	$(call cmd_and_fixdep,as_o_S)
  	$(call cmd,gen_ksymdeps)
  	$(call cmd,objtool)
  	$(call cmd,modversions_S)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
228
  endef
9895c03d4   Nicolas Pitre   kbuild: record ne...
229
230
  # List module undefined symbols (or empty line if not enabled)
  ifdef CONFIG_TRIM_UNUSED_KSYMS
9f69a496f   Masahiro Yamada   kbuild: split out...
231
  cmd_undef_syms = $(NM) $< | sed -n 's/^  *U //p' | xargs echo
9895c03d4   Nicolas Pitre   kbuild: record ne...
232
233
234
  else
  cmd_undef_syms = echo
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
  # Built-in and composite module parts
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
236
  $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
  	$(call cmd,force_checksrc)
  	$(call if_changed_rule,cc_o_c)
9f69a496f   Masahiro Yamada   kbuild: split out...
239
240
241
242
243
244
245
246
247
  cmd_mod = { \
  	echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
  	$(cmd_undef_syms); \
  	} > $@
  
  $(obj)/%.mod: $(obj)/%.o FORCE
  	$(call if_changed,mod)
  
  targets += $(mod-targets)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
249
250
251
252
  
  quiet_cmd_cc_lst_c = MKLST   $@
        cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
  		     $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
  				     System.map $(OBJDUMP) > $@
767e581d7   Sam Ravnborg   kbuild: enable us...
253
  $(obj)/%.lst: $(src)/%.c FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254
255
256
257
  	$(call if_changed_dep,cc_lst_c)
  
  # Compile assembler sources (.S)
  # ---------------------------------------------------------------------------
4efca4ed0   Nicholas Piggin   kbuild: modversio...
258
259
260
261
262
263
264
265
266
267
268
269
  # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
  # or a file that it includes, in order to get versioned symbols. We build a
  # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
  # the .S file (with trailing ';'), and run genksyms on that, to extract vers.
  #
  # This is convoluted. The .S file must first be preprocessed to run guards and
  # expand names, then the resulting exports must be constructed into plain
  # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
  # to make the genksyms input.
  #
  # These mirror gensymtypes_c and co above, keep them in synch.
  cmd_gensymtypes_S =                                                         \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
270
     { echo "\#include <linux/kernel.h>" ;                                    \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
271
272
       echo "\#include <asm/asm-prototypes.h>" ;                              \
      $(CPP) $(a_flags) $< |                                                  \
cc6acc11c   Nicholas Piggin   kbuild: be more c...
273
       grep "\<___EXPORT_SYMBOL\>" |                                          \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
274
       sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
275
      $(CPP) -D__GENKSYMS__ $(c_flags) -xc - |                                \
88110713c   Masahiro Yamada   kbuild: hardcode ...
276
      scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
56067812d   Ard Biesheuvel   kbuild: modversio...
277
       $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
278
279
280
281
282
       $(if $(KBUILD_PRESERVE),-p)                                            \
       -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  
  quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
  cmd_cc_symtypes_S =                                                         \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
283
284
285
286
287
      $(call cmd_gensymtypes_S,true,$@) >/dev/null;                           \
      test -s $@ || rm -f $@
  
  $(obj)/%.symtypes : $(src)/%.S FORCE
  	$(call cmd,cc_symtypes_S)
e0f41e52d   Masahiro Yamada   kbuild: rename cm...
288
289
  quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  cmd_cpp_s_S       = $(CPP) $(a_flags) -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290

767e581d7   Sam Ravnborg   kbuild: enable us...
291
  $(obj)/%.s: $(src)/%.S FORCE
e0f41e52d   Masahiro Yamada   kbuild: rename cm...
292
  	$(call if_changed_dep,cpp_s_S)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
294
  
  quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
295
        cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
4efca4ed0   Nicholas Piggin   kbuild: modversio...
296

2ff2b7ec6   Masahiro Yamada   kbuild: add CONFI...
297
  ifdef CONFIG_ASM_MODVERSIONS
4efca4ed0   Nicholas Piggin   kbuild: modversio...
298
299
300
  
  # versioning matches the C process described above, with difference that
  # we parse asm-prototypes.h C header to get function definitions.
4efca4ed0   Nicholas Piggin   kbuild: modversio...
301
  cmd_modversions_S =								\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
302
  	if $(OBJDUMP) -h $@ | grep -q __ksymtab; then				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
303
304
305
  		$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
  		    > $(@D)/.tmp_$(@F:.o=.ver);					\
  										\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
306
  		$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ 		\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
307
  			-T $(@D)/.tmp_$(@F:.o=.ver);				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
308
  		mv -f $(@D)/.tmp_$(@F) $@;					\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
309
  		rm -f $(@D)/.tmp_$(@F:.o=.ver);					\
e5d289100   Masahiro Yamada   kbuild: remove tr...
310
  	fi
4efca4ed0   Nicholas Piggin   kbuild: modversio...
311
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312

ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
313
  $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
314
  	$(call if_changed_rule,as_o_S)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
316
  targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
319
320
321
  targets += $(extra-y) $(MAKECMDGOALS) $(always)
  
  # Linker scripts preprocessor (.lds.S -> .lds)
  # ---------------------------------------------------------------------------
  quiet_cmd_cpp_lds_S = LDS     $@
5cb0512c0   Linus Torvalds   Kbuild: don't pas...
322
        cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
42f29a252   Tim Abbott   kbuild: Don't def...
323
  	                     -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324

767e581d7   Sam Ravnborg   kbuild: enable us...
325
  $(obj)/%.lds: $(src)/%.lds.S FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
  	$(call if_changed_dep,cpp_lds_S)
4520c6a49   David Howells   X.509: Add simple...
327
328
  # ASN.1 grammar
  # ---------------------------------------------------------------------------
49d5089d9   Masahiro Yamada   kbuild: use $(bas...
329
  quiet_cmd_asn1_compiler = ASN.1   $(basename $@).[ch]
4520c6a49   David Howells   X.509: Add simple...
330
        cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
49d5089d9   Masahiro Yamada   kbuild: use $(bas...
331
  				$(basename $@).c $(basename $@).h
4520c6a49   David Howells   X.509: Add simple...
332

4fa8bc949   Masahiro Yamada   kbuild: rename *-...
333
  $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
4520c6a49   David Howells   X.509: Add simple...
334
  	$(call cmd,asn1_compiler)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
338
339
340
341
  # Build the compiled-in targets
  # ---------------------------------------------------------------------------
  
  # To build objects in subdirs, we need to descend into the directories
  $(sort $(subdir-obj-y)): $(subdir-ym) ;
  
  #
dee949530   Masahiro Yamada   kbuild: remove to...
342
  # Rule to compile a set of .o files into one .a file (without symbol table)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
  #
  ifdef builtin-target
a5967db9a   Stephen Rothwell   kbuild: allow arc...
345

5e18f0290   Masahiro Yamada   kbuild: clean up ...
346
  quiet_cmd_ar_builtin = AR      $@
13dc8c029   Masahiro Yamada   kbuild: remove ar...
347
        cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
349
  $(builtin-target): $(real-obj-y) FORCE
5e18f0290   Masahiro Yamada   kbuild: clean up ...
350
  	$(call if_changed,ar_builtin)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
352
353
354
355
  
  targets += $(builtin-target)
  endif # builtin-target
  
  #
551559e13   Tejun Heo   kbuild: implement...
356
357
358
359
  # Rule to create modules.order file
  #
  # Create commands to either record .ko file or cat modules.order from
  # a subdirectory
551559e13   Tejun Heo   kbuild: implement...
360
  $(modorder-target): $(subdir-ym) FORCE
e0e1b1ec3   Masahiro Yamada   kbuild: remove du...
361
362
363
  	$(Q){ $(foreach m, $(modorder), \
  	$(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
  	| $(AWK) '!x[$$0]++' - > $@
551559e13   Tejun Heo   kbuild: implement...
364
365
  
  #
dee949530   Masahiro Yamada   kbuild: remove to...
366
  # Rule to compile a set of .o files into one .a file (with symbol table)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367
368
  #
  ifdef lib-target
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
  
  $(lib-target): $(lib-y) FORCE
898f5a009   Masahiro Yamada   kbuild: move arch...
371
  	$(call if_changed,ar)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
  
  targets += $(lib-target)
7f2084fa5   Al Viro   [kbuild] handle e...
374
375
376
  
  dummy-object = $(obj)/.lib_exports.o
  ksyms-lds = $(dot-target).lds
7f2084fa5   Al Viro   [kbuild] handle e...
377
378
379
  
  quiet_cmd_export_list = EXPORTS $@
  cmd_export_list = $(OBJDUMP) -h $< | \
704db5433   Masahiro Yamada   kbuild: remove CO...
380
  	sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\
7f2084fa5   Al Viro   [kbuild] handle e...
381
  	rm -f $(dummy-object);\
9da2f584b   Nicholas Piggin   kbuild: improve l...
382
  	echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\
7f2084fa5   Al Viro   [kbuild] handle e...
383
384
385
386
387
  	$(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
  	rm $(dummy-object) $(ksyms-lds)
  
  $(obj)/lib-ksyms.o: $(lib-target) FORCE
  	$(call if_changed,export_list)
989cea5c1   Nicholas Piggin   kbuild: prevent l...
388
389
  
  targets += $(obj)/lib-ksyms.o
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
  endif
afa974b77   Masahiro Yamada   kbuild: add real-...
391
392
393
394
  # NOTE:
  # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
  # module is turned into a multi object module, $^ will contain header file
  # dependencies recorded in the .*.cmd file.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
  quiet_cmd_link_multi-m = LD [M]  $@
b7dca6dd1   Masahiro Yamada   kbuild: create *....
396
        cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397

c8589d1e9   Masahiro Yamada   kbuild: handle mu...
398
  $(multi-used-m): FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
  	$(call if_changed,link_multi-m)
cf4f21938   Michal Marek   kbuild: Allow to ...
400
  $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
402
  targets += $(multi-used-m)
591f66899   Masahiro Yamada   kbuild: filter-ou...
403
  targets := $(filter-out $(PHONY), $(targets))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
404

b23d1a241   Masahiro Yamada   kbuild: add %.lex...
405
406
407
408
409
410
  # Add intermediate targets:
  # When building objects with specific suffix patterns, add intermediate
  # targets that the final targets are derived from.
  intermediate_targets = $(foreach sfx, $(2), \
  				$(patsubst %$(strip $(1)),%$(sfx), \
  					$(filter %$(strip $(1)), $(targets))))
54a702f70   Masahiro Yamada   kbuild: mark $(ta...
411
  # %.asn1.o <- %.asn1.[ch] <- %.asn1
a7f924190   Masahiro Yamada   kbuild: add %.dtb...
412
  # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
b23d1a241   Masahiro Yamada   kbuild: add %.lex...
413
414
  # %.lex.o <- %.lex.c <- %.l
  # %.tab.o <- %.tab.[ch] <- %.y
54a702f70   Masahiro Yamada   kbuild: mark $(ta...
415
416
  targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
  	   $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
a7f924190   Masahiro Yamada   kbuild: add %.dtb...
417
  	   $(call intermediate_targets, .lex.o, .lex.c) \
b23d1a241   Masahiro Yamada   kbuild: add %.lex...
418
  	   $(call intermediate_targets, .tab.o, .tab.c .tab.h)
394053f4a   Masahiro Yamada   kbuild: make sing...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
  # Build
  # ---------------------------------------------------------------------------
  
  ifdef single-build
  
  curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \
  			$(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x))))
  
  # Handle single targets without any rule: show "Nothing to be done for ..." or
  # "No rule to make target ..." depending on whether the target exists.
  unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \
  			$(filter $(obj)/%, \
  				$(filter-out $(curdir-single), \
  					$(KBUILD_SINGLE_TARGETS))))
  
  __build: $(curdir-single) $(subdir-ym)
  ifneq ($(unknown-single),)
  	$(Q)$(MAKE) -f /dev/null $(unknown-single)
  endif
  	@:
  
  ifeq ($(curdir-single),)
  # Nothing to do in this directory. Do not include any .*.cmd file for speed-up
  targets :=
  else
  targets += $(curdir-single)
  endif
  
  else
  
  __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
  	 $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \
  	 $(subdir-ym) $(always)
  	@:
  
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
  # Descending
  # ---------------------------------------------------------------------------
4f1933620   Paul Smith   kbuild: change kb...
457
  PHONY += $(subdir-ym)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458
  $(subdir-ym):
d9f78edfd   Masahiro Yamada   kbuild: fix false...
459
  	$(Q)$(MAKE) $(build)=$@ \
394053f4a   Masahiro Yamada   kbuild: make sing...
460
  	$(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
4f2c8f308   Masahiro Yamada   kbuild: generate ...
461
462
  	need-builtin=$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \
  	need-modorder=$(if $(need-modorder),$(if $(filter $@/modules.order, $(modorder)),1))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
463
464
465
  
  # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  # ---------------------------------------------------------------------------
4f1933620   Paul Smith   kbuild: change kb...
466
  PHONY += FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
468
469
470
471
472
473
  
  FORCE:
  
  # Read all saved command lines and dependencies for the $(targets) we
  # may be building above, using $(if_changed{,_dep}). As an
  # optimization, we don't need to read them if the target does not
  # exist, we will rebuild anyway in that case.
392885ee8   Masahiro Yamada   kbuild: let fixde...
474
  existing-targets := $(wildcard $(sort $(targets)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475

392885ee8   Masahiro Yamada   kbuild: let fixde...
476
  -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
4f1933620   Paul Smith   kbuild: change kb...
477

051f278e9   Masahiro Yamada   kbuild: replace K...
478
  ifdef building_out_of_srctree
8a78756eb   Masahiro Yamada   kbuild: create ob...
479
480
  # Create directories for object files if they do not exist
  obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
392885ee8   Masahiro Yamada   kbuild: let fixde...
481
482
483
  # If targets exist, their directories apparently exist. Skip mkdir.
  existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
  obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
c4da7ed0e   Masahiro Yamada   kbuild: optimize ...
484
  ifneq ($(obj-dirs),)
8a78756eb   Masahiro Yamada   kbuild: create ob...
485
486
  $(shell mkdir -p $(obj-dirs))
  endif
c4da7ed0e   Masahiro Yamada   kbuild: optimize ...
487
  endif
8a78756eb   Masahiro Yamada   kbuild: create ob...
488

4f1933620   Paul Smith   kbuild: change kb...
489
  .PHONY: $(PHONY)