perf build: Add libperf objects building
[firefly-linux-kernel-4.4.55.git] / tools / build / Makefile.build
1 ###
2 # Main build makefile.
3 #
4 #  Lots of this code have been borrowed or heavily inspired from parts
5 #  of kbuild code, which is not credited, but mostly developed by:
6 #
7 #  Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015
8 #  Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015
9 #
10
11 PHONY := __build
12 __build:
13
14 ifeq ($(V),1)
15   quiet =
16 else
17   quiet=quiet_
18 endif
19
20 build-dir := $(srctree)/tools/build
21
22 # Generic definitions
23 include $(build-dir)/Build.include
24
25 # do not force detected configuration
26 -include .config-detected
27
28 # Init all relevant variables used in build files so
29 # 1) they have correct type
30 # 2) they do not inherit any value from the environment
31 subdir-y     :=
32 obj-y        :=
33 subdir-y     :=
34 subdir-obj-y :=
35
36 # Build definitions
37 build-file := $(dir)/Build
38 include $(build-file)
39
40 quiet_cmd_flex  = FLEX     $@
41 quiet_cmd_bison = BISON    $@
42
43 # Create directory unless it exists
44 quiet_cmd_mkdir = MKDIR    $(dir $@)
45       cmd_mkdir = mkdir -p $(dir $@)
46      rule_mkdir = $(if $(wildcard $(dir $@)),,@$(call echo-cmd,mkdir) $(cmd_mkdir))
47
48 # Compile command
49 quiet_cmd_cc_o_c = CC       $@
50       cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
51
52 # Link agregate command
53 # If there's nothing to link, create empty $@ object.
54 quiet_cmd_ld_multi = LD       $@
55       cmd_ld_multi = $(if $(strip $(obj-y)),\
56                        $(LD) -r -o $@ $(obj-y),rm -f $@; $(AR) rcs $@)
57
58 # Build rules
59 $(OUTPUT)%.o: %.c FORCE
60         $(call rule_mkdir)
61         $(call if_changed_dep,cc_o_c)
62
63 $(OUTPUT)%.o: %.S FORCE
64         $(call rule_mkdir)
65         $(call if_changed_dep,cc_o_c)
66
67 # Gather build data:
68 #   obj-y        - list of build objects
69 #   subdir-y     - list of directories to nest
70 #   subdir-obj-y - list of directories objects 'dir/$(obj)-in.o'
71 obj-y        := $($(obj)-y)
72 subdir-y     := $(patsubst %/,%,$(filter %/, $(obj-y)))
73 obj-y        := $(patsubst %/, %/$(obj)-in.o, $(obj-y))
74 subdir-obj-y := $(filter %/$(obj)-in.o, $(obj-y))
75
76 # '$(OUTPUT)/dir' prefix to all objects
77 prefix       := $(subst ./,,$(OUTPUT)$(dir)/)
78 obj-y        := $(addprefix $(prefix),$(obj-y))
79 subdir-obj-y := $(addprefix $(prefix),$(subdir-obj-y))
80
81 # Final '$(obj)-in.o' object
82 in-target := $(prefix)$(obj)-in.o
83
84 PHONY += $(subdir-y)
85
86 $(subdir-y):
87         @$(MAKE) -f $(build-dir)/Makefile.build dir=$(dir)/$@ obj=$(obj)
88
89 $(sort $(subdir-obj-y)): $(subdir-y) ;
90
91 $(in-target): $(obj-y) FORCE
92         $(call rule_mkdir)
93         $(call if_changed,ld_multi)
94
95 __build: $(in-target)
96         @:
97
98 PHONY += FORCE
99 FORCE:
100
101 # Include all cmd files to get all the dependency rules
102 # for all objects included
103 targets   := $(wildcard $(sort $(obj-y) $(in-target)))
104 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
105
106 ifneq ($(cmd_files),)
107   include $(cmd_files)
108 endif
109
110 .PHONY: $(PHONY)