blob: 35174d92047693fc272a34b711d8d228ecdec61d [file] [log] [blame]
Jiri Olsac819e2c2014-12-29 13:51:45 +01001###
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
11PHONY := __build
12__build:
13
14ifeq ($(V),1)
15 quiet =
16else
17 quiet=quiet_
18endif
19
20build-dir := $(srctree)/tools/build
21
22# Generic definitions
23include $(build-dir)/Build.include
24
Jiri Olsafcfd6612014-12-31 17:37:00 +010025# do not force detected configuration
26-include .config-detected
27
Jiri Olsac819e2c2014-12-29 13:51:45 +010028# 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
31subdir-y :=
32obj-y :=
33subdir-y :=
34subdir-obj-y :=
35
36# Build definitions
37build-file := $(dir)/Build
38include $(build-file)
39
40# Compile command
41quiet_cmd_cc_o_c = CC $@
42 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
43
44# Link agregate command
45# If there's nothing to link, create empty $@ object.
46quiet_cmd_ld_multi = LD $@
47 cmd_ld_multi = $(if $(strip $(obj-y)),\
48 $(LD) -r -o $@ $(obj-y),rm -f $@; $(AR) rcs $@)
49
50# Build rules
51$(OUTPUT)%.o: %.c FORCE
52 $(call if_changed_dep,cc_o_c)
53
54$(OUTPUT)%.o: %.S FORCE
55 $(call if_changed_dep,cc_o_c)
56
57# Gather build data:
58# obj-y - list of build objects
59# subdir-y - list of directories to nest
60# subdir-obj-y - list of directories objects 'dir/$(obj)-in.o'
61obj-y := $($(obj)-y)
62subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
63obj-y := $(patsubst %/, %/$(obj)-in.o, $(obj-y))
64subdir-obj-y := $(filter %/$(obj)-in.o, $(obj-y))
65
66# '$(OUTPUT)/dir' prefix to all objects
67prefix := $(subst ./,,$(OUTPUT)$(dir)/)
68obj-y := $(addprefix $(prefix),$(obj-y))
69subdir-obj-y := $(addprefix $(prefix),$(subdir-obj-y))
70
71# Final '$(obj)-in.o' object
72in-target := $(prefix)$(obj)-in.o
73
74PHONY += $(subdir-y)
75
76$(subdir-y):
77 @$(MAKE) -f $(build-dir)/Makefile.build dir=$(dir)/$@ obj=$(obj)
78
79$(sort $(subdir-obj-y)): $(subdir-y) ;
80
81$(in-target): $(obj-y) FORCE
82 $(call rule_mkdir)
83 $(call if_changed,ld_multi)
84
85__build: $(in-target)
86 @:
87
88PHONY += FORCE
89FORCE:
90
91# Include all cmd files to get all the dependency rules
92# for all objects included
93targets := $(wildcard $(sort $(obj-y) $(in-target)))
94cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
95
96ifneq ($(cmd_files),)
97 include $(cmd_files)
98endif
99
100.PHONY: $(PHONY)