Skip to content

Commit 767e581

Browse files
committed
kbuild: enable use of code from a different dir
To introduce support for source in one directory but output files in another directory during a non O= build prefix all paths with $(src) repsectively $(obj). Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 5447d34 commit 767e581

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

‎scripts/Makefile.build‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
131131
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
132132
cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
133133

134-
%.s: %.c FORCE
134+
$(obj)/%.s: $(src)/%.c FORCE
135135
$(call if_changed_dep,cc_s_c)
136136

137137
quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
138138
cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
139139

140-
%.i: %.c FORCE
140+
$(obj)/%.i: $(src)/%.c FORCE
141141
$(call if_changed_dep,cc_i_c)
142142

143143
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
@@ -146,7 +146,7 @@ cmd_cc_symtypes_c = \
146146
| $(GENKSYMS) -T $@ >/dev/null; \
147147
test -s $@ || rm -f $@
148148

149-
%.symtypes : %.c FORCE
149+
$(obj)/%.symtypes : $(src)/%.c FORCE
150150
$(call if_changed_dep,cc_symtypes_c)
151151

152152
# C (.c) files
@@ -198,14 +198,13 @@ define rule_cc_o_c
198198
endef
199199

200200
# Built-in and composite module parts
201-
202-
%.o: %.c FORCE
201+
$(obj)/%.o: $(src)/%.c FORCE
203202
$(call cmd,force_checksrc)
204203
$(call if_changed_rule,cc_o_c)
205204

206205
# Single-part modules are special since we need to mark them in $(MODVERDIR)
207206

208-
$(single-used-m): %.o: %.c FORCE
207+
$(single-used-m): $(obj)/%.o: $(src)/%.c FORCE
209208
$(call cmd,force_checksrc)
210209
$(call if_changed_rule,cc_o_c)
211210
@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
@@ -215,7 +214,7 @@ quiet_cmd_cc_lst_c = MKLST $@
215214
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
216215
System.map $(OBJDUMP) > $@
217216

218-
%.lst: %.c FORCE
217+
$(obj)/%.lst: $(src)/%.c FORCE
219218
$(call if_changed_dep,cc_lst_c)
220219

221220
# Compile assembler sources (.S)
@@ -229,13 +228,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
229228
quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
230229
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
231230

232-
%.s: %.S FORCE
231+
$(obj)/%.s: $(src)/%.S FORCE
233232
$(call if_changed_dep,as_s_S)
234233

235234
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
236235
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
237236

238-
%.o: %.S FORCE
237+
$(obj)/%.o: $(src)/%.S FORCE
239238
$(call if_changed_dep,as_o_S)
240239

241240
targets += $(real-objs-y) $(real-objs-m) $(lib-y)
@@ -246,7 +245,7 @@ targets += $(extra-y) $(MAKECMDGOALS) $(always)
246245
quiet_cmd_cpp_lds_S = LDS $@
247246
cmd_cpp_lds_S = $(CPP) $(cpp_flags) -D__ASSEMBLY__ -o $@ $<
248247

249-
%.lds: %.lds.S FORCE
248+
$(obj)/%.lds: $(src)/%.lds.S FORCE
250249
$(call if_changed_dep,cpp_lds_S)
251250

252251
# Build the compiled-in targets

‎scripts/Makefile.host‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags)
114114
quiet_cmd_host-csingle = HOSTCC $@
115115
cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \
116116
$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
117-
$(host-csingle): %: %.c FORCE
117+
$(host-csingle): $(obj)/%: $(src)/%.c FORCE
118118
$(call if_changed_dep,host-csingle)
119119

120120
# Link an executable based on list of .o files, all plain c
@@ -123,14 +123,14 @@ quiet_cmd_host-cmulti = HOSTLD $@
123123
cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
124124
$(addprefix $(obj)/,$($(@F)-objs)) \
125125
$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
126-
$(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
126+
$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
127127
$(call if_changed,host-cmulti)
128128

129129
# Create .o file from a single .c file
130130
# host-cobjs -> .o
131131
quiet_cmd_host-cobjs = HOSTCC $@
132132
cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
133-
$(host-cobjs): %.o: %.c FORCE
133+
$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
134134
$(call if_changed_dep,host-cobjs)
135135

136136
# Link an executable based on list of .o files, a mixture of .c and .cc
@@ -140,20 +140,20 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
140140
$(foreach o,objs cxxobjs,\
141141
$(addprefix $(obj)/,$($(@F)-$(o)))) \
142142
$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
143-
$(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
143+
$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
144144
$(call if_changed,host-cxxmulti)
145145

146146
# Create .o file from a single .cc (C++) file
147147
quiet_cmd_host-cxxobjs = HOSTCXX $@
148148
cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
149-
$(host-cxxobjs): %.o: %.cc FORCE
149+
$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
150150
$(call if_changed_dep,host-cxxobjs)
151151

152152
# Compile .c file, create position independent .o file
153153
# host-cshobjs -> .o
154154
quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
155155
cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
156-
$(host-cshobjs): %.o: %.c FORCE
156+
$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
157157
$(call if_changed_dep,host-cshobjs)
158158

159159
# Link a shared library, based on position independent .o files
@@ -162,7 +162,7 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
162162
cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
163163
$(addprefix $(obj)/,$($(@F:.so=-objs))) \
164164
$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
165-
$(host-cshlib): %: $(host-cshobjs) FORCE
165+
$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
166166
$(call if_changed,host-cshlib)
167167

168168
targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\

0 commit comments

Comments
 (0)