2014-12-29 15:51:45 +03:00
###
# Main build makefile.
#
# Lots of this code have been borrowed or heavily inspired from parts
# of kbuild code, which is not credited, but mostly developed by:
#
# Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015
# Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015
#
PHONY := __build
__build :
i f e q ( $( V ) , 1 )
quiet =
2015-01-12 01:59:55 +03:00
Q =
2014-12-29 15:51:45 +03:00
e l s e
quiet = quiet_
2015-01-12 01:59:55 +03:00
Q = @
2014-12-29 15:51:45 +03:00
e n d i f
2017-05-19 14:42:30 +03:00
i f n e q ( $( findstring s ,$ ( filter -out --%,$ ( MAKEFLAGS ) ) ) , )
2017-01-19 07:16:55 +03:00
quiet = silent_
e n d i f
2014-12-29 15:51:45 +03:00
build-dir := $( srctree) /tools/build
2015-09-23 13:34:00 +03:00
# Define $(fixdep) for dep-cmd function
i f e q ( $( OUTPUT ) , )
fixdep := $( build-dir) /fixdep
e l s e
fixdep := $( OUTPUT) /fixdep
e n d i f
2014-12-29 15:51:45 +03:00
# Generic definitions
i n c l u d e $( build -dir ) / B u i l d . i n c l u d e
2014-12-31 19:37:00 +03:00
# do not force detected configuration
2015-07-01 14:54:42 +03:00
- i n c l u d e $( OUTPUT ) . c o n f i g - d e t e c t e d
2014-12-31 19:37:00 +03:00
2014-12-29 15:51:45 +03:00
# Init all relevant variables used in build files so
# 1) they have correct type
# 2) they do not inherit any value from the environment
subdir-y :=
obj-y :=
subdir-y :=
subdir-obj-y :=
# Build definitions
build-file := $( dir) /Build
2015-05-29 18:42:58 +03:00
- i n c l u d e $( build -file )
2014-12-29 15:51:45 +03:00
2014-12-29 19:42:46 +03:00
quiet_cmd_flex = FLEX $@
quiet_cmd_bison = BISON $@
2014-12-30 18:44:11 +03:00
# Create directory unless it exists
quiet_cmd_mkdir = MKDIR $( dir $@ )
cmd_mkdir = mkdir -p $( dir $@ )
rule_mkdir = $( if $( wildcard $( dir $@ ) ) ,,@$( call echo-cmd,mkdir) $( cmd_mkdir) )
2014-12-29 15:51:45 +03:00
# Compile command
quiet_cmd_cc_o_c = CC $@
cmd_cc_o_c = $( CC) $( c_flags) -c -o $@ $<
2016-09-27 17:18:46 +03:00
quiet_cmd_host_cc_o_c = HOSTCC $@
cmd_host_cc_o_c = $( HOSTCC) $( host_c_flags) -c -o $@ $<
2016-09-26 10:26:55 +03:00
quiet_cmd_cxx_o_c = CXX $@
cmd_cxx_o_c = $( CXX) $( cxx_flags) -c -o $@ $<
2016-04-08 05:24:47 +03:00
quiet_cmd_cpp_i_c = CPP $@
cmd_cpp_i_c = $( CC) $( c_flags) -E -o $@ $<
2014-12-30 20:44:38 +03:00
quiet_cmd_cc_s_c = AS $@
cmd_cc_s_c = $( CC) $( c_flags) -S -o $@ $<
2015-08-13 10:14:55 +03:00
quiet_cmd_gen = GEN $@
2014-12-29 15:51:45 +03:00
# Link agregate command
# If there's nothing to link, create empty $@ object.
quiet_cmd_ld_multi = LD $@
cmd_ld_multi = $( if $( strip $( obj-y) ) ,\
2016-09-27 17:18:46 +03:00
$( LD) -r -o $@ $( filter $( obj-y) ,$^) ,rm -f $@ ; $( AR) rcs $@ )
quiet_cmd_host_ld_multi = HOSTLD $@
cmd_host_ld_multi = $( if $( strip $( obj-y) ) ,\
$( HOSTLD) -r -o $@ $( filter $( obj-y) ,$^) ,rm -f $@ ; $( HOSTAR) rcs $@ )
i f n e q ( $( filter $ ( obj ) ,$ ( hostprogs ) ) , )
host = host_
e n d i f
2014-12-29 15:51:45 +03:00
# Build rules
$(OUTPUT)%.o : %.c FORCE
2014-12-30 18:44:11 +03:00
$( call rule_mkdir)
2016-09-27 17:18:46 +03:00
$( call if_changed_dep,$( host) cc_o_c)
2014-12-29 15:51:45 +03:00
2016-09-26 10:26:55 +03:00
$(OUTPUT)%.o : %.cpp FORCE
$( call rule_mkdir)
$( call if_changed_dep,cxx_o_c)
2014-12-29 15:51:45 +03:00
$(OUTPUT)%.o : %.S FORCE
2014-12-30 18:44:11 +03:00
$( call rule_mkdir)
2016-09-27 17:18:46 +03:00
$( call if_changed_dep,$( host) cc_o_c)
2014-12-29 15:51:45 +03:00
2014-12-30 20:44:38 +03:00
$(OUTPUT)%.i : %.c FORCE
$( call rule_mkdir)
2016-04-08 05:24:47 +03:00
$( call if_changed_dep,cpp_i_c)
2014-12-30 20:44:38 +03:00
2016-01-31 20:59:00 +03:00
$(OUTPUT)%.s : %.S FORCE
2014-12-30 20:44:38 +03:00
$( call rule_mkdir)
2016-04-08 05:24:47 +03:00
$( call if_changed_dep,cpp_i_c)
2014-12-30 20:44:38 +03:00
$(OUTPUT)%.s : %.c FORCE
$( call rule_mkdir)
$( call if_changed_dep,cc_s_c)
2014-12-29 15:51:45 +03:00
# Gather build data:
# obj-y - list of build objects
# subdir-y - list of directories to nest
# subdir-obj-y - list of directories objects 'dir/$(obj)-in.o'
obj-y := $( $( obj) -y)
subdir-y := $( patsubst %/,%,$( filter %/, $( obj-y) ) )
obj-y := $( patsubst %/, %/$( obj) -in.o, $( obj-y) )
subdir-obj-y := $( filter %/$( obj) -in.o, $( obj-y) )
# '$(OUTPUT)/dir' prefix to all objects
2015-06-18 14:00:32 +03:00
objprefix := $( subst ./,,$( OUTPUT) $( dir) /)
obj-y := $( addprefix $( objprefix) ,$( obj-y) )
subdir-obj-y := $( addprefix $( objprefix) ,$( subdir-obj-y) )
2014-12-29 15:51:45 +03:00
# Final '$(obj)-in.o' object
2015-06-18 14:00:32 +03:00
in-target := $( objprefix) $( obj) -in.o
2014-12-29 15:51:45 +03:00
PHONY += $( subdir-y)
$(subdir-y) :
2015-01-12 01:59:55 +03:00
$( Q) $( MAKE) -f $( build-dir) /Makefile.build dir = $( dir) /$@ obj = $( obj)
2014-12-29 15:51:45 +03:00
$(sort $(subdir-obj-y)) : $( subdir -y ) ;
$(in-target) : $( obj -y ) FORCE
$( call rule_mkdir)
2016-09-27 17:18:46 +03:00
$( call if_changed,$( host) ld_multi)
2014-12-29 15:51:45 +03:00
__build : $( in -target )
@:
PHONY += FORCE
FORCE :
# Include all cmd files to get all the dependency rules
# for all objects included
2014-12-30 20:44:38 +03:00
targets := $( wildcard $( sort $( obj-y) $( in-target) $( MAKECMDGOALS) ) )
2014-12-29 15:51:45 +03:00
cmd_files := $( wildcard $( foreach f,$( targets) ,$( dir $( f) ) .$( notdir $( f) ) .cmd) )
i f n e q ( $( cmd_files ) , )
include $( cmd_files)
e n d i f
.PHONY : $( PHONY )