Blame view

scripts/Makefile.build 17.3 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
  # 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 :=
5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
17
18
  always-y :=
  always-m :=
d72e5edbf   Sam Ravnborg   kbuild: avoid env...
19
20
21
22
23
24
25
  targets :=
  subdir-y :=
  subdir-m :=
  EXTRA_AFLAGS   :=
  EXTRA_CFLAGS   :=
  EXTRA_CPPFLAGS :=
  EXTRA_LDFLAGS  :=
f77bf0142   Sam Ravnborg   kbuild: introduce...
26
27
28
29
  asflags-y  :=
  ccflags-y  :=
  cppflags-y :=
  ldflags-y  :=
d72e5edbf   Sam Ravnborg   kbuild: avoid env...
30

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

20a468b51   Sam Ravnborg   kbuild: make cc-v...
36
  include scripts/Kbuild.include
2a6914703   Sam Ravnborg   kbuild: fix make ...
37
  # The filename Kbuild has precedence over Makefile
db8c1a7b2   Sam Ravnborg   kbuild: fix build...
38
  kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
0c53c8e6e   Sam Ravnborg   kbuild: check for...
39
40
  kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
  include $(kbuild-file)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  include scripts/Makefile.lib
85569d19d   Masahiro Yamada   kbuild: sort host...
42
43
44
  # Do not include hostprogs rules unless needed.
  # $(sort ...) is used here to remove duplicated words and excessive spaces.
  hostprogs := $(sort $(hostprogs))
42640b134   Masahiro Yamada   kbuild: move host...
45
  ifneq ($(hostprogs),)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  include scripts/Makefile.host
  endif
7f3a59db2   Masahiro Yamada   kbuild: add infra...
48
  # Do not include userprogs rules unless needed.
85569d19d   Masahiro Yamada   kbuild: sort host...
49
  # $(sort ...) is used here to remove duplicated words and excessive spaces.
7f3a59db2   Masahiro Yamada   kbuild: add infra...
50
51
52
53
  userprogs := $(sort $(userprogs))
  ifneq ($(userprogs),)
  include scripts/Makefile.userprogs
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
  ifndef obj
  $(warning kbuild: Makefile.build is included improperly)
  endif
394053f4a   Masahiro Yamada   kbuild: make sing...
57
  ifeq ($(need-modorder),)
c07d8d47b   Masahiro Yamada   kbuild: show hint...
58
59
60
61
62
  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
63
  # ===========================================================================
454753d9f   Masahiro Yamada   kbuild: make modu...
64
  # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
aaa385ba9   Masahiro Yamada   kbuild: rename su...
65
  subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
b2c885549   Masahiro Yamada   kbuild: update mo...
66
  subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
6ba3bcb01   Masahiro Yamada   kbuild: move subd...
67

f3908ab3f   Masahiro Yamada   kbuild: refactor ...
68
  targets-for-builtin := $(extra-y)
a4954fd77   Masahiro Yamada   kbuild: remove ob...
69
  ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
f3908ab3f   Masahiro Yamada   kbuild: refactor ...
70
  targets-for-builtin += $(obj)/lib.a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  endif
56d589361   Masahiro Yamada   kbuild: do not cr...
72
  ifdef need-builtin
f3908ab3f   Masahiro Yamada   kbuild: refactor ...
73
  targets-for-builtin += $(obj)/built-in.a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  endif
b2c885549   Masahiro Yamada   kbuild: update mo...
75
  targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
f3908ab3f   Masahiro Yamada   kbuild: refactor ...
76

b480fec98   Masahiro Yamada   kbuild: clear KBU...
77
  ifdef need-modorder
f3908ab3f   Masahiro Yamada   kbuild: refactor ...
78
  targets-for-modules += $(obj)/modules.order
1d8001ef3   Masahiro Yamada   kbuild: generate ...
79
  endif
551559e13   Tejun Heo   kbuild: implement...
80

f3908ab3f   Masahiro Yamada   kbuild: refactor ...
81
  targets += $(targets-for-builtin) $(targets-for-modules)
9f69a496f   Masahiro Yamada   kbuild: split out...
82

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
  # Linus' kernel sanity checking tool
7d0ea2524   Masahiro Yamada   kbuild: use 'else...
84
85
  ifeq ($(KBUILD_CHECKSRC),1)
    quiet_cmd_checksrc       = CHECK   $<
e5d289100   Masahiro Yamada   kbuild: remove tr...
86
          cmd_checksrc       = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
7d0ea2524   Masahiro Yamada   kbuild: use 'else...
87
88
  else ifeq ($(KBUILD_CHECKSRC),2)
    quiet_cmd_force_checksrc = CHECK   $<
e5d289100   Masahiro Yamada   kbuild: remove tr...
89
          cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  endif
e27128db6   Masahiro Yamada   kbuild: rename KB...
91
  ifneq ($(KBUILD_EXTRA_WARN),)
e5d289100   Masahiro Yamada   kbuild: remove tr...
92
    cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
3a025e1d1   Matthew Wilcox   Add optional chec...
93
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
  # Compile C sources (.c)
  # ---------------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
0f6372e52   Sami Tolvanen   treewide: remove ...
97
        cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) -fverbose-asm -S -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98

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

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

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

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

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

433db3e26   Vinícius Tinti   kbuild: Add suppo...
123
124
125
126
127
128
129
  # 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
130
131
132
133
134
  # 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 ...
135
        cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136

ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
137
  ifdef CONFIG_MODVERSIONS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
  # When module versioning is enabled the following steps are executed:
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
139
140
141
  # 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
142
143
  # 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...
144
  #   that they are usable as a linker script
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
145
  # o generate .tmp_<file>.o from <file>.o using the linker to
2ea038917   Sam Ravnborg   Revert "kbuild: s...
146
147
  #   replace the unresolved symbols __crc_exported_symbol with
  #   the actual value of the checksum generated by genksyms
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
148
  # o remove .tmp_<file>.o to <file>.o
4efca4ed0   Nicholas Piggin   kbuild: modversio...
149
150
  
  cmd_modversions_c =								\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
151
  	if $(OBJDUMP) -h $@ | grep -q __ksymtab; then				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
152
  		$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
e26d6b834   Don Zickus   Makefile.build: m...
153
154
  		    > $(@D)/.tmp_$(@F:.o=.ver);					\
  										\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
155
  		$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ 		\
e26d6b834   Don Zickus   Makefile.build: m...
156
  			-T $(@D)/.tmp_$(@F:.o=.ver);				\
e26d6b834   Don Zickus   Makefile.build: m...
157
  		mv -f $(@D)/.tmp_$(@F) $@;					\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
158
  		rm -f $(@D)/.tmp_$(@F:.o=.ver);					\
e5d289100   Masahiro Yamada   kbuild: remove tr...
159
  	fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
  endif
8da3821ba   Steven Rostedt   ftrace: create __...
161
  ifdef CONFIG_FTRACE_MCOUNT_RECORD
07d040812   Vasily Gorbik   tracing: Avoid ca...
162
163
  ifndef CC_USING_RECORD_MCOUNT
  # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
72441cb1f   Steven Rostedt   ftrace/x86: Add s...
164
  ifdef BUILD_C_RECORDMCOUNT
85356f802   Steven Rostedt   kbuild/recordmcou...
165
166
167
  ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
    RECORDMCOUNT_FLAGS = -w
  endif
d7b4d6de5   Steven Rostedt   ftrace: Remove re...
168
169
  # 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...
170
171
  # the target endianness and word size. It is made before all other C
  # files, including recordmcount.
45677454d   Wu Zhangjin   ftrace: Speed up ...
172
173
  sub_cmd_record_mcount =					\
  	if [ $(@) != "scripts/mod/empty.o" ]; then	\
85356f802   Steven Rostedt   kbuild/recordmcou...
174
  		$(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)";	\
45677454d   Wu Zhangjin   ftrace: Speed up ...
175
  	fi;
d6971822c   Michal Marek   ftrace/kbuild: Ad...
176
177
  recordmcount_source := $(srctree)/scripts/recordmcount.c \
  		    $(srctree)/scripts/recordmcount.h
72441cb1f   Steven Rostedt   ftrace/x86: Add s...
178
  else
4317ee3b6   Masahiro Yamada   kbuild: remove re...
179
  sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
e6299d267   Wu Zhangjin   MIPS: Tracing: Ad...
180
  	"$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
b3acf29af   Steven Rostedt   ftrace, kbuild: c...
181
  	"$(if $(CONFIG_64BIT),64,32)" \
5a4630aad   Joel Stanley   ftrace: Build wit...
182
  	"$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
d503ac531   Masahiro Yamada   kbuild: rename LD...
183
  	"$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
18c167fd6   Shaohua Li   ftrace, ia64: mak...
184
  	"$(if $(part-of-module),1,0)" "$(@)";
d6971822c   Michal Marek   ftrace/kbuild: Ad...
185
  recordmcount_source := $(srctree)/scripts/recordmcount.pl
312a3d091   Cao jin   kbuild: trivial c...
186
  endif # BUILD_C_RECORDMCOUNT
1a49b2fd8   Joe Lawrence   kbuild: strip whi...
187
188
  cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),	\
  	$(sub_cmd_record_mcount))
07d040812   Vasily Gorbik   tracing: Avoid ca...
189
  endif # CC_USING_RECORD_MCOUNT
312a3d091   Cao jin   kbuild: trivial c...
190
  endif # CONFIG_FTRACE_MCOUNT_RECORD
8da3821ba   Steven Rostedt   ftrace: create __...
191

b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
192
  ifdef CONFIG_STACK_VALIDATION
3b27a0c85   Josh Poimboeuf   objtool: Detect a...
193
  ifneq ($(SKIP_STACK_VALIDATION),1)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
194
195
  
  __objtool_obj := $(objtree)/tools/objtool/objtool
11af84744   Josh Poimboeuf   x86/unwind: Renam...
196
  objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
197

ca41b97ed   Peter Zijlstra   objtool: Add modu...
198
  objtool_args += $(if $(part-of-module), --module,)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
199
200
201
  ifndef CONFIG_FRAME_POINTER
  objtool_args += --no-fp
  endif
867ac9d73   Josh Poimboeuf   objtool: Fix gcov...
202
203
204
  ifdef CONFIG_GCOV_KERNEL
  objtool_args += --no-unreachable
  endif
b5bc2231b   Peter Zijlstra   objtool: Add retp...
205
206
207
  ifdef CONFIG_RETPOLINE
    objtool_args += --retpoline
  endif
ea24213d8   Peter Zijlstra   objtool: Add UACC...
208
209
210
  ifdef CONFIG_X86_SMAP
    objtool_args += --uaccess
  endif
b5bc2231b   Peter Zijlstra   objtool: Add retp...
211

b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
212
213
214
215
216
  # '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...
217
  	$(__objtool_obj) $(objtool_args) $@)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
218
219
220
  objtool_obj = $(if $(patsubst y%,, \
  	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  	$(__objtool_obj))
3b27a0c85   Josh Poimboeuf   objtool: Detect a...
221
  endif # SKIP_STACK_VALIDATION
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
222
  endif # CONFIG_STACK_VALIDATION
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
223
224
225
226
  # 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 ...
227
228
  ifdef CONFIG_TRIM_UNUSED_KSYMS
  cmd_gen_ksymdeps = \
e5d289100   Masahiro Yamada   kbuild: remove tr...
229
  	$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
7d32358be   Masahiro Yamada   kbuild: avoid spl...
230
231
232
  
  # List module undefined symbols
  undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
bbda5ec67   Masahiro Yamada   kbuild: simplify ...
233
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
  define rule_cc_o_c
3a2429e1f   Masahiro Yamada   kbuild: change if...
235
236
  	$(call cmd_and_fixdep,cc_o_c)
  	$(call cmd,gen_ksymdeps)
0c33f1257   Luc Van Oostenryck   kbuild: run the c...
237
  	$(call cmd,checksrc)
3a2429e1f   Masahiro Yamada   kbuild: change if...
238
239
240
241
  	$(call cmd,checkdoc)
  	$(call cmd,objtool)
  	$(call cmd,modversions_c)
  	$(call cmd,record_mcount)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
  endef
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
243
  define rule_as_o_S
3a2429e1f   Masahiro Yamada   kbuild: change if...
244
245
246
247
  	$(call cmd_and_fixdep,as_o_S)
  	$(call cmd,gen_ksymdeps)
  	$(call cmd,objtool)
  	$(call cmd,modversions_S)
b9ab5ebb1   Josh Poimboeuf   objtool: Add CONF...
248
  endef
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
  # Built-in and composite module parts
ee9f8fce9   Josh Poimboeuf   x86/unwind: Add t...
250
  $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251
  	$(call if_changed_rule,cc_o_c)
0c33f1257   Luc Van Oostenryck   kbuild: run the c...
252
  	$(call cmd,force_checksrc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253

9f69a496f   Masahiro Yamada   kbuild: split out...
254
255
  cmd_mod = { \
  	echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
7d32358be   Masahiro Yamada   kbuild: avoid spl...
256
  	$(undefined_syms) echo; \
9f69a496f   Masahiro Yamada   kbuild: split out...
257
258
259
260
  	} > $@
  
  $(obj)/%.mod: $(obj)/%.o FORCE
  	$(call if_changed,mod)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
262
263
264
  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...
265
  $(obj)/%.lst: $(src)/%.c FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
266
267
268
269
  	$(call if_changed_dep,cc_lst_c)
  
  # Compile assembler sources (.S)
  # ---------------------------------------------------------------------------
4efca4ed0   Nicholas Piggin   kbuild: modversio...
270
271
272
273
274
275
276
277
278
279
280
281
  # .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...
282
     { echo "\#include <linux/kernel.h>" ;                                    \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
283
284
       echo "\#include <asm/asm-prototypes.h>" ;                              \
      $(CPP) $(a_flags) $< |                                                  \
cc6acc11c   Nicholas Piggin   kbuild: be more c...
285
       grep "\<___EXPORT_SYMBOL\>" |                                          \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
286
       sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
287
      $(CPP) -D__GENKSYMS__ $(c_flags) -xc - |                                \
88110713c   Masahiro Yamada   kbuild: hardcode ...
288
      scripts/genksyms/genksyms $(if $(1), -T $(2))                           \
56067812d   Ard Biesheuvel   kbuild: modversio...
289
       $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS))                             \
4efca4ed0   Nicholas Piggin   kbuild: modversio...
290
291
292
293
294
       $(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...
295
296
297
298
299
      $(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...
300
301
  quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  cmd_cpp_s_S       = $(CPP) $(a_flags) -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302

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

2ff2b7ec6   Masahiro Yamada   kbuild: add CONFI...
309
  ifdef CONFIG_ASM_MODVERSIONS
4efca4ed0   Nicholas Piggin   kbuild: modversio...
310
311
312
  
  # 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...
313
  cmd_modversions_S =								\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
314
  	if $(OBJDUMP) -h $@ | grep -q __ksymtab; then				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
315
316
317
  		$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
  		    > $(@D)/.tmp_$(@F:.o=.ver);					\
  										\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
318
  		$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ 		\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
319
  			-T $(@D)/.tmp_$(@F:.o=.ver);				\
4efca4ed0   Nicholas Piggin   kbuild: modversio...
320
  		mv -f $(@D)/.tmp_$(@F) $@;					\
ee3e46b7e   Masahiro Yamada   kbuild: refactor ...
321
  		rm -f $(@D)/.tmp_$(@F:.o=.ver);					\
e5d289100   Masahiro Yamada   kbuild: remove tr...
322
  	fi
4efca4ed0   Nicholas Piggin   kbuild: modversio...
323
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324

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

b2c885549   Masahiro Yamada   kbuild: update mo...
328
329
330
  targets += $(filter-out $(subdir-builtin), $(real-obj-y))
  targets += $(filter-out $(subdir-modorder), $(real-obj-m))
  targets += $(lib-y) $(always-y) $(MAKECMDGOALS)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
334
  
  # Linker scripts preprocessor (.lds.S -> .lds)
  # ---------------------------------------------------------------------------
  quiet_cmd_cpp_lds_S = LDS     $@
5cb0512c0   Linus Torvalds   Kbuild: don't pas...
335
        cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
42f29a252   Tim Abbott   kbuild: Don't def...
336
  	                     -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
337

767e581d7   Sam Ravnborg   kbuild: enable us...
338
  $(obj)/%.lds: $(src)/%.lds.S FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
  	$(call if_changed_dep,cpp_lds_S)
4520c6a49   David Howells   X.509: Add simple...
340
341
  # ASN.1 grammar
  # ---------------------------------------------------------------------------
49d5089d9   Masahiro Yamada   kbuild: use $(bas...
342
  quiet_cmd_asn1_compiler = ASN.1   $(basename $@).[ch]
4520c6a49   David Howells   X.509: Add simple...
343
        cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
49d5089d9   Masahiro Yamada   kbuild: use $(bas...
344
  				$(basename $@).c $(basename $@).h
4520c6a49   David Howells   X.509: Add simple...
345

4fa8bc949   Masahiro Yamada   kbuild: rename *-...
346
  $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
4520c6a49   David Howells   X.509: Add simple...
347
  	$(call cmd,asn1_compiler)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
350
351
  # Build the compiled-in targets
  # ---------------------------------------------------------------------------
  
  # To build objects in subdirs, we need to descend into the directories
aaa385ba9   Masahiro Yamada   kbuild: rename su...
352
  $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
454753d9f   Masahiro Yamada   kbuild: make modu...
353
  $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
  
  #
dee949530   Masahiro Yamada   kbuild: remove to...
356
  # Rule to compile a set of .o files into one .a file (without symbol table)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
  #
a5967db9a   Stephen Rothwell   kbuild: allow arc...
358

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

e578edc72   Masahiro Yamada   kbuild: remove if...
362
  $(obj)/built-in.a: $(real-obj-y) FORCE
5e18f0290   Masahiro Yamada   kbuild: clean up ...
363
  	$(call if_changed,ar_builtin)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
365
  #
551559e13   Tejun Heo   kbuild: implement...
366
367
368
369
  # Rule to create modules.order file
  #
  # Create commands to either record .ko file or cat modules.order from
  # a subdirectory
b2c885549   Masahiro Yamada   kbuild: update mo...
370
371
372
373
374
  # Add $(obj-m) as the prerequisite to avoid updating the timestamp of
  # modules.order unless contained modules are updated.
  
  cmd_modules_order = { $(foreach m, $(real-prereqs), \
  	$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
e0e1b1ec3   Masahiro Yamada   kbuild: remove du...
375
  	| $(AWK) '!x[$$0]++' - > $@
551559e13   Tejun Heo   kbuild: implement...
376

b2c885549   Masahiro Yamada   kbuild: update mo...
377
378
  $(obj)/modules.order: $(obj-m) FORCE
  	$(call if_changed,modules_order)
551559e13   Tejun Heo   kbuild: implement...
379
  #
dee949530   Masahiro Yamada   kbuild: remove to...
380
  # Rule to compile a set of .o files into one .a file (with symbol table)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
  #
e578edc72   Masahiro Yamada   kbuild: remove if...
382
  $(obj)/lib.a: $(lib-y) FORCE
898f5a009   Masahiro Yamada   kbuild: move arch...
383
  	$(call if_changed,ar)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384

afa974b77   Masahiro Yamada   kbuild: add real-...
385
386
387
388
  # 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
389
  quiet_cmd_link_multi-m = LD [M]  $@
b7dca6dd1   Masahiro Yamada   kbuild: create *....
390
        cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
391

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

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

b23d1a241   Masahiro Yamada   kbuild: add %.lex...
399
400
401
402
403
404
  # 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...
405
  # %.asn1.o <- %.asn1.[ch] <- %.asn1
a7f924190   Masahiro Yamada   kbuild: add %.dtb...
406
  # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
b23d1a241   Masahiro Yamada   kbuild: add %.lex...
407
408
  # %.lex.o <- %.lex.c <- %.l
  # %.tab.o <- %.tab.[ch] <- %.y
54a702f70   Masahiro Yamada   kbuild: mark $(ta...
409
410
  targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
  	   $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
a7f924190   Masahiro Yamada   kbuild: add %.dtb...
411
  	   $(call intermediate_targets, .lex.o, .lex.c) \
b23d1a241   Masahiro Yamada   kbuild: add %.lex...
412
  	   $(call intermediate_targets, .tab.o, .tab.c .tab.h)
394053f4a   Masahiro Yamada   kbuild: make sing...
413
414
415
416
  # Build
  # ---------------------------------------------------------------------------
  
  ifdef single-build
203126293   Masahiro Yamada   kbuild: reduce KB...
417
  KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS))
394053f4a   Masahiro Yamada   kbuild: make sing...
418
419
420
421
422
423
  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)), \
203126293   Masahiro Yamada   kbuild: reduce KB...
424
  			$(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS)))
394053f4a   Masahiro Yamada   kbuild: make sing...
425

2dffd23f8   Masahiro Yamada   kbuild: make sing...
426
427
428
429
  single-subdirs := $(foreach d, $(subdir-ym), \
  			$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
  
  __build: $(curdir-single) $(single-subdirs)
394053f4a   Masahiro Yamada   kbuild: make sing...
430
431
432
433
434
435
436
437
438
439
440
441
442
  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
f3908ab3f   Masahiro Yamada   kbuild: refactor ...
443
444
  __build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
  	 $(if $(KBUILD_MODULES), $(targets-for-modules)) \
5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
445
  	 $(subdir-ym) $(always-y)
394053f4a   Masahiro Yamada   kbuild: make sing...
446
447
448
  	@:
  
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
449
450
  # Descending
  # ---------------------------------------------------------------------------
4f1933620   Paul Smith   kbuild: change kb...
451
  PHONY += $(subdir-ym)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452
  $(subdir-ym):
d9f78edfd   Masahiro Yamada   kbuild: fix false...
453
  	$(Q)$(MAKE) $(build)=$@ \
394053f4a   Masahiro Yamada   kbuild: make sing...
454
  	$(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
aaa385ba9   Masahiro Yamada   kbuild: rename su...
455
  	need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
454753d9f   Masahiro Yamada   kbuild: make modu...
456
  	need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
458
459
  
  # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  # ---------------------------------------------------------------------------
4f1933620   Paul Smith   kbuild: change kb...
460
  PHONY += FORCE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
465
466
467
  
  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...
468
  existing-targets := $(wildcard $(sort $(targets)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
469

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

8a78756eb   Masahiro Yamada   kbuild: create ob...
472
  # Create directories for object files if they do not exist
cc8a51ca6   Masahiro Yamada   kbuild: always cr...
473
  obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets))))
392885ee8   Masahiro Yamada   kbuild: let fixde...
474
475
476
  # 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 ...
477
  ifneq ($(obj-dirs),)
8a78756eb   Masahiro Yamada   kbuild: create ob...
478
479
  $(shell mkdir -p $(obj-dirs))
  endif
4f1933620   Paul Smith   kbuild: change kb...
480
  .PHONY: $(PHONY)