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