Skip to content

Commit

Permalink
tools build: Add support for host programs format
Browse files Browse the repository at this point in the history
In some cases, like for fixdep and shortly for jevents, we need to build a tool
to run on the host that will be used in building a tool, such as perf, that is
being cross compiled, so do like the kernel and provide HOSTCC, HOSTLD and HOSTAR
to do that.

Signed-off-by: Jiri Olsa <[email protected]>
Requested-by: Andi Kleen <[email protected]>
Requested-and-Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Madhavan Srinivasan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sukadev Bhattiprolu <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/20160927141846.GA6589@krava
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Jiri Olsa authored and acmel committed Oct 3, 2016
1 parent 18ef15c commit 0c3b7e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions tools/build/Build.include
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
# - per object C flags
# - BUILD_STR macro to allow '-D"$(variable)"' constructs
c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj))

###
## HOSTCC C flags

host_c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CHOSTFLAGS) -D"BUILD_STR(s)=\#s" $(CHOSTFLAGS_$(basetarget).o) $(CHOSTFLAGS_$(obj))
6 changes: 6 additions & 0 deletions tools/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ endef
$(call allow-override,CC,$(CROSS_COMPILE)gcc)
$(call allow-override,LD,$(CROSS_COMPILE)ld)

HOSTCC ?= gcc
HOSTLD ?= ld
HOSTAR ?= ar

export HOSTCC HOSTLD HOSTAR

ifeq ($(V),1)
Q =
else
Expand Down
19 changes: 15 additions & 4 deletions tools/build/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ quiet_cmd_mkdir = MKDIR $(dir $@)
quiet_cmd_cc_o_c = CC $@
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<

quiet_cmd_host_cc_o_c = HOSTCC $@
cmd_host_cc_o_c = $(HOSTCC) $(host_c_flags) -c -o $@ $<

quiet_cmd_cpp_i_c = CPP $@
cmd_cpp_i_c = $(CC) $(c_flags) -E -o $@ $<

Expand All @@ -70,16 +73,24 @@ quiet_cmd_gen = GEN $@
# If there's nothing to link, create empty $@ object.
quiet_cmd_ld_multi = LD $@
cmd_ld_multi = $(if $(strip $(obj-y)),\
$(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@)
$(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@)

quiet_cmd_host_ld_multi = HOSTLD $@
cmd_host_ld_multi = $(if $(strip $(obj-y)),\
$(HOSTLD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(HOSTAR) rcs $@)

ifneq ($(filter $(obj),$(hostprogs)),)
host = host_
endif

# Build rules
$(OUTPUT)%.o: %.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
$(call if_changed_dep,$(host)cc_o_c)

$(OUTPUT)%.o: %.S FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
$(call if_changed_dep,$(host)cc_o_c)

$(OUTPUT)%.i: %.c FORCE
$(call rule_mkdir)
Expand Down Expand Up @@ -119,7 +130,7 @@ $(sort $(subdir-obj-y)): $(subdir-y) ;

$(in-target): $(obj-y) FORCE
$(call rule_mkdir)
$(call if_changed,ld_multi)
$(call if_changed,$(host)ld_multi)

__build: $(in-target)
@:
Expand Down

0 comments on commit 0c3b7e4

Please sign in to comment.