]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/build/Makefile.build
ipv4: convert dst_metrics.refcnt from atomic_t to refcount_t
[mirror_ubuntu-artful-kernel.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 Q =
17 else
18 quiet=quiet_
19 Q=@
20 endif
21
22 ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
23 quiet=silent_
24 endif
25
26 build-dir := $(srctree)/tools/build
27
28 # Define $(fixdep) for dep-cmd function
29 ifeq ($(OUTPUT),)
30 fixdep := $(build-dir)/fixdep
31 else
32 fixdep := $(OUTPUT)/fixdep
33 endif
34
35 # Generic definitions
36 include $(build-dir)/Build.include
37
38 # do not force detected configuration
39 -include $(OUTPUT).config-detected
40
41 # Init all relevant variables used in build files so
42 # 1) they have correct type
43 # 2) they do not inherit any value from the environment
44 subdir-y :=
45 obj-y :=
46 subdir-y :=
47 subdir-obj-y :=
48
49 # Build definitions
50 build-file := $(dir)/Build
51 -include $(build-file)
52
53 quiet_cmd_flex = FLEX $@
54 quiet_cmd_bison = BISON $@
55
56 # Create directory unless it exists
57 quiet_cmd_mkdir = MKDIR $(dir $@)
58 cmd_mkdir = mkdir -p $(dir $@)
59 rule_mkdir = $(if $(wildcard $(dir $@)),,@$(call echo-cmd,mkdir) $(cmd_mkdir))
60
61 # Compile command
62 quiet_cmd_cc_o_c = CC $@
63 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
64
65 quiet_cmd_host_cc_o_c = HOSTCC $@
66 cmd_host_cc_o_c = $(HOSTCC) $(host_c_flags) -c -o $@ $<
67
68 quiet_cmd_cxx_o_c = CXX $@
69 cmd_cxx_o_c = $(CXX) $(cxx_flags) -c -o $@ $<
70
71 quiet_cmd_cpp_i_c = CPP $@
72 cmd_cpp_i_c = $(CC) $(c_flags) -E -o $@ $<
73
74 quiet_cmd_cc_s_c = AS $@
75 cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $<
76
77 quiet_cmd_gen = GEN $@
78
79 # Link agregate command
80 # If there's nothing to link, create empty $@ object.
81 quiet_cmd_ld_multi = LD $@
82 cmd_ld_multi = $(if $(strip $(obj-y)),\
83 $(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@)
84
85 quiet_cmd_host_ld_multi = HOSTLD $@
86 cmd_host_ld_multi = $(if $(strip $(obj-y)),\
87 $(HOSTLD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(HOSTAR) rcs $@)
88
89 ifneq ($(filter $(obj),$(hostprogs)),)
90 host = host_
91 endif
92
93 # Build rules
94 $(OUTPUT)%.o: %.c FORCE
95 $(call rule_mkdir)
96 $(call if_changed_dep,$(host)cc_o_c)
97
98 $(OUTPUT)%.o: %.cpp FORCE
99 $(call rule_mkdir)
100 $(call if_changed_dep,cxx_o_c)
101
102 $(OUTPUT)%.o: %.S FORCE
103 $(call rule_mkdir)
104 $(call if_changed_dep,$(host)cc_o_c)
105
106 $(OUTPUT)%.i: %.c FORCE
107 $(call rule_mkdir)
108 $(call if_changed_dep,cpp_i_c)
109
110 $(OUTPUT)%.s: %.S FORCE
111 $(call rule_mkdir)
112 $(call if_changed_dep,cpp_i_c)
113
114 $(OUTPUT)%.s: %.c FORCE
115 $(call rule_mkdir)
116 $(call if_changed_dep,cc_s_c)
117
118 # Gather build data:
119 # obj-y - list of build objects
120 # subdir-y - list of directories to nest
121 # subdir-obj-y - list of directories objects 'dir/$(obj)-in.o'
122 obj-y := $($(obj)-y)
123 subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
124 obj-y := $(patsubst %/, %/$(obj)-in.o, $(obj-y))
125 subdir-obj-y := $(filter %/$(obj)-in.o, $(obj-y))
126
127 # '$(OUTPUT)/dir' prefix to all objects
128 objprefix := $(subst ./,,$(OUTPUT)$(dir)/)
129 obj-y := $(addprefix $(objprefix),$(obj-y))
130 subdir-obj-y := $(addprefix $(objprefix),$(subdir-obj-y))
131
132 # Final '$(obj)-in.o' object
133 in-target := $(objprefix)$(obj)-in.o
134
135 PHONY += $(subdir-y)
136
137 $(subdir-y):
138 $(Q)$(MAKE) -f $(build-dir)/Makefile.build dir=$(dir)/$@ obj=$(obj)
139
140 $(sort $(subdir-obj-y)): $(subdir-y) ;
141
142 $(in-target): $(obj-y) FORCE
143 $(call rule_mkdir)
144 $(call if_changed,$(host)ld_multi)
145
146 __build: $(in-target)
147 @:
148
149 PHONY += FORCE
150 FORCE:
151
152 # Include all cmd files to get all the dependency rules
153 # for all objects included
154 targets := $(wildcard $(sort $(obj-y) $(in-target) $(MAKECMDGOALS)))
155 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
156
157 ifneq ($(cmd_files),)
158 include $(cmd_files)
159 endif
160
161 .PHONY: $(PHONY)