tools build: Add new build support
Subsystems (3)
tip-bot for Jiri Olsa
merge botCommit-ID: c819e2cf2eb6f65d3208d195d7a0edef6108d533 Gitweb: http://git.kernel.org/tip/c819e2cf2eb6f65d3208d195d7a0edef6108d533 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 29 Dec 2014 13:51:45 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Feb 2015 18:30:03 -0300
tools build: Add new build support
Adding new build framework into 'tools/build' to be used by tools.
There's no change for actual building at this point, it comes in the next patches.
The idea and more details are explained in the
'tools/build/Documentation/Build.txt' file.
I adopted everything from the kernel build system, with some changes to allow for multiple binaries build definitions.
While the kernel's build output is single image (forget modules) we need to be able to build several binaries/libraries.
The basic idea is that sser provides 'Build' files with objects definitions like:
perf-y += a.o
perf-y += b.o
libperf-y += c.o
libperf-y += d.o
and the build framework outputs files:
perf-in.o # a.o, b.o compiled in
libperf-in.o # c.o, d.o compiled in
--- tools/build/Build.include | 81 ++++++++++++ tools/build/Documentation/Build.txt | 139 +++++++++++++++++++++ tools/build/Makefile.build | 97 ++++++++++++++ tools/build/tests/ex/Build | 8 ++ tools/build/tests/ex/Makefile | 23 ++++ tools/build/tests/ex/a.c | 5 + tools/build/tests/ex/arch/Build | 2 + tools/build/tests/ex/arch/e.c | 5 + tools/build/tests/ex/arch/f.c | 5 + tools/build/tests/ex/b.c | 5 + tools/build/tests/ex/c.c | 5 + tools/build/tests/ex/d.c | 5 + .../build/tests/ex/empty/Build | 0 tools/build/tests/ex/ex.c | 19 +++ tools/build/tests/run.sh | 42 +++++++ tools/perf/MANIFEST | 1 + 16 files changed, 442 insertions(+)
tools/build/Build.include new file +81 -0
@@ -0,0 +1,81 @@ +### +# build: Generic definitions +# +# Lots of this code have been borrowed or heavily inspired from parts +# of kbuild code, which is not credited, but mostly developed by: +# +# Copyright (C) Sam Ravnborg <[email protected]>, 2015 +# Copyright (C) Linus Torvalds <[email protected]>, 2015 +# + +### +# Convenient variables +comma := , +squote := ' + +### +# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o +dot-target = $(dir $@).$(notdir $@) + +### +# filename of target with directory and extension stripped +basetarget = $(basename $(notdir $@)) + +### +# The temporary file to save gcc -MD generated dependencies must not +# contain a comma +depfile = $(subst $(comma),_,$(dot-target).d) + +### +# Check if both arguments has same arguments. Result is empty string if equal. +arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ + $(filter-out $(cmd_$@), $(cmd_$(1))) ) + +### +# Escape single quote for use in echo statements +escsq = $(subst $(squote),'\$(squote)',$1) + +# Echo command +# Short version is used, if $(quiet) equals `quiet_', otherwise full one. +echo-cmd = $(if $($(quiet)cmd_$(1)),\ + echo ' $(call escsq,$($(quiet)cmd_$(1)))';) + +### +# Replace >$< with >$$< to preserve $ when reloading the .cmd file +# (needed for make) +# Replace >#< with >\#< to avoid starting a comment in the .cmd file +# (needed for make) +# Replace >'< with >'\''< to be able to enclose the whole string in '...' +# (needed for the shell) +make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1))))) + +### +# Find any prerequisites that is newer than target or that does not exist. +# PHONY targets skipped in both cases. +any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) + +### +# if_changed_dep - execute command if any prerequisite is newer than +# target, or command line has changed and update +# dependencies in the cmd file +if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \ + @set -e; \ + $(echo-cmd) $(cmd_$(1)); \ + cat $(depfile) > $(dot-target).cmd; \ + printf '%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd) + +# if_changed - execute command if any prerequisite is newer than +# target, or command line has changed +if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ + @set -e; \ + $(echo-cmd) $(cmd_$(1)); \ + printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) + +### +# C flags to be used in rule definitions, includes: +# - depfile generation +# - global $(CFLAGS) +# - per target C flags +# - 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))
tools/build/Documentation/Build.txt new file +139 -0
139 lines not on this page · raw message
tools/build/Makefile.build new file +97 -0
97 lines not on this page · raw message
tools/build/tests/ex/Build new file +8 -0
@@ -0,0 +1,8 @@ +ex-y += ex.o +ex-y += a.o +ex-y += b.o +ex-y += empty/ + +libex-y += c.o +libex-y += d.o +libex-y += arch/
tools/build/tests/ex/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +export srctree := ../../../.. +export CC := gcc +export LD := ld +export AR := ar + +build := -f $(srctree)/tools/build/Makefile.build dir=. obj +ex: ex-in.o libex-in.o + gcc -o $@ $^ + +ex.%: FORCE + make -f $(srctree)/tools/build/Makefile.build dir=. $@ + +ex-in.o: FORCE + make $(build)=ex + +libex-in.o: FORCE + make $(build)=libex + +clean: + find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete + rm -f ex ex.i ex.s + +.PHONY: FORCE
tools/build/tests/ex/a.c new file +5 -0
@@ -0,0 +1,5 @@ + +int a (void ) +{ +return 0 ; +}
tools/build/tests/ex/arch/Build new file +2 -0
@@ -0,0 +1,2 @@ +libex-y += e.o +libex-y += f.o
tools/build/tests/ex/arch/e.c new file +5 -0
@@ -0,0 +1,5 @@ + +int e (void ) +{ +return 0 ; +}
tools/build/tests/ex/arch/f.c new file +5 -0
@@ -0,0 +1,5 @@ + +int f (void ) +{ +return 0 ; +}
tools/build/tests/ex/b.c new file +5 -0
@@ -0,0 +1,5 @@ + +int b (void ) +{ +return 0 ; +}
tools/build/tests/ex/c.c new file +5 -0
@@ -0,0 +1,5 @@ + +int c (void ) +{ +return 0 ; +}
tools/build/tests/ex/d.c new file +5 -0
@@ -0,0 +1,5 @@ + +int d (void ) +{ +return 0 ; +}
tools/build/tests/ex/empty/Build renamed from arch/arm/mach-nspire/Makefile.boot +0 -0
tools/build/tests/ex/ex.c new file +19 -0
@@ -0,0 +1,19 @@ + +int a (void ); +int b (void ); +int c (void ); +int d (void ); +int e (void ); +int f (void ); + +int main (void ) +{ +a (); +b (); +c (); +d (); +e (); +f (); + +return 0 ; +}
tools/build/tests/run.sh new file +42 -0
42 lines not on this page · raw message
tools/perf/MANIFEST +1 -0
@@ -1,5 +1,6 @@ tools/perf tools/scripts +tools/build tools/lib/traceevent tools/lib/api tools/lib/symbol/kallsyms.c