Linux Audio

Check our new training course

Embedded Linux training

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