]>
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 | ||
24 | # Generic definitions | |
25 | include $(build-dir)/Build.include | |
26 | ||
fcfd6611 | 27 | # do not force detected configuration |
64227379 | 28 | -include $(OUTPUT).config-detected |
fcfd6611 | 29 | |
c819e2cf JO |
30 | # Init all relevant variables used in build files so |
31 | # 1) they have correct type | |
32 | # 2) they do not inherit any value from the environment | |
33 | subdir-y := | |
34 | obj-y := | |
35 | subdir-y := | |
36 | subdir-obj-y := | |
37 | ||
38 | # Build definitions | |
39 | build-file := $(dir)/Build | |
d7a3d85e | 40 | -include $(build-file) |
c819e2cf | 41 | |
9352aaba JO |
42 | quiet_cmd_flex = FLEX $@ |
43 | quiet_cmd_bison = BISON $@ | |
44 | ||
579ff6d4 JO |
45 | # Create directory unless it exists |
46 | quiet_cmd_mkdir = MKDIR $(dir $@) | |
47 | cmd_mkdir = mkdir -p $(dir $@) | |
48 | rule_mkdir = $(if $(wildcard $(dir $@)),,@$(call echo-cmd,mkdir) $(cmd_mkdir)) | |
49 | ||
c819e2cf JO |
50 | # Compile command |
51 | quiet_cmd_cc_o_c = CC $@ | |
52 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< | |
53 | ||
1999307b JO |
54 | quiet_cmd_cc_i_c = CPP $@ |
55 | cmd_cc_i_c = $(CC) $(c_flags) -E -o $@ $< | |
56 | ||
57 | quiet_cmd_cc_s_c = AS $@ | |
58 | cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $< | |
59 | ||
237fae79 AH |
60 | quiet_cmd_gen = GEN $@ |
61 | ||
c819e2cf JO |
62 | # Link agregate command |
63 | # If there's nothing to link, create empty $@ object. | |
64 | quiet_cmd_ld_multi = LD $@ | |
65 | cmd_ld_multi = $(if $(strip $(obj-y)),\ | |
0bdede8a | 66 | $(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@) |
c819e2cf JO |
67 | |
68 | # Build rules | |
69 | $(OUTPUT)%.o: %.c FORCE | |
579ff6d4 | 70 | $(call rule_mkdir) |
c819e2cf JO |
71 | $(call if_changed_dep,cc_o_c) |
72 | ||
73 | $(OUTPUT)%.o: %.S FORCE | |
579ff6d4 | 74 | $(call rule_mkdir) |
c819e2cf JO |
75 | $(call if_changed_dep,cc_o_c) |
76 | ||
1999307b JO |
77 | $(OUTPUT)%.i: %.c FORCE |
78 | $(call rule_mkdir) | |
79 | $(call if_changed_dep,cc_i_c) | |
80 | ||
81 | $(OUTPUT)%.i: %.S FORCE | |
82 | $(call rule_mkdir) | |
83 | $(call if_changed_dep,cc_i_c) | |
84 | ||
85 | $(OUTPUT)%.s: %.c FORCE | |
86 | $(call rule_mkdir) | |
87 | $(call if_changed_dep,cc_s_c) | |
88 | ||
c819e2cf JO |
89 | # Gather build data: |
90 | # obj-y - list of build objects | |
91 | # subdir-y - list of directories to nest | |
92 | # subdir-obj-y - list of directories objects 'dir/$(obj)-in.o' | |
93 | obj-y := $($(obj)-y) | |
94 | subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) | |
95 | obj-y := $(patsubst %/, %/$(obj)-in.o, $(obj-y)) | |
96 | subdir-obj-y := $(filter %/$(obj)-in.o, $(obj-y)) | |
97 | ||
98 | # '$(OUTPUT)/dir' prefix to all objects | |
75e84ab9 LW |
99 | objprefix := $(subst ./,,$(OUTPUT)$(dir)/) |
100 | obj-y := $(addprefix $(objprefix),$(obj-y)) | |
101 | subdir-obj-y := $(addprefix $(objprefix),$(subdir-obj-y)) | |
c819e2cf JO |
102 | |
103 | # Final '$(obj)-in.o' object | |
75e84ab9 | 104 | in-target := $(objprefix)$(obj)-in.o |
c819e2cf JO |
105 | |
106 | PHONY += $(subdir-y) | |
107 | ||
108 | $(subdir-y): | |
ceed252f | 109 | $(Q)$(MAKE) -f $(build-dir)/Makefile.build dir=$(dir)/$@ obj=$(obj) |
c819e2cf JO |
110 | |
111 | $(sort $(subdir-obj-y)): $(subdir-y) ; | |
112 | ||
113 | $(in-target): $(obj-y) FORCE | |
114 | $(call rule_mkdir) | |
115 | $(call if_changed,ld_multi) | |
116 | ||
117 | __build: $(in-target) | |
118 | @: | |
119 | ||
120 | PHONY += FORCE | |
121 | FORCE: | |
122 | ||
123 | # Include all cmd files to get all the dependency rules | |
124 | # for all objects included | |
1999307b | 125 | targets := $(wildcard $(sort $(obj-y) $(in-target) $(MAKECMDGOALS))) |
c819e2cf JO |
126 | cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
127 | ||
128 | ifneq ($(cmd_files),) | |
129 | include $(cmd_files) | |
130 | endif | |
131 | ||
132 | .PHONY: $(PHONY) |