Skip to content

Commit

Permalink
mk/subdir.mk: introduce srcs_ext-y and srcs_ext_base-y
Browse files Browse the repository at this point in the history
Introduce two new variables srcs_ext-y and srcs_ext_base-y to deal with
compiling source code outside of this git (optee_os.git).

srcs_ext_base-y assigns the root directory of the external source files
to compile. srcs_ext-y works as srcs-y except that it's relative to the
$(srcs_ext_base-y) directory.

Introduce the per source file variable oname-<file name>-y to override
the default output object file name. This helps to shorten and make a
more sane name for the output object file name when the source file is
outside optee_os source tree, for instance, a third-party library.

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
  • Loading branch information
jenswi-linaro authored and jforissier committed Nov 4, 2024
1 parent 5db2cbd commit 2e48051
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
3 changes: 1 addition & 2 deletions mk/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ $2: $1 FORCE-GENSRC$(sm)

endef

$(foreach f, $(srcs), $(eval $(call \
process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o)))
$(foreach f, $(srcs), $(eval $(call process_srcs,$(f),$$(oname-$(sm)-$(f)))))

# Handle generated source files, that is, files that are compiled from out-dir
$(foreach f, $(gen-srcs), $(eval $(call process_srcs,$(f),$$(basename $f).o)))
Expand Down
49 changes: 39 additions & 10 deletions mk/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ asm-defines-files :=

uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))

define process-file-vars
# $1 is source file name
define process-file-vars-helper
# $1 is local source file name
# $2 is output file name
cflags-$(2) := $$(cflags-y) $$(cflags-$(1)-y)
cflags-remove-$(2) := $$(cflags-remove-y) $$(cflags-remove-$(1)-y)
Expand All @@ -49,23 +49,48 @@ cppflags-lib-y :=
aflags-$(1)-y :=
aflags-remove-$(1)-y :=
incdirs-$(1)-y :=
endef #process-file-vars
endef #process-file-vars-helper

define process-file-vars
# $1 is local source file name
# $2 is output file name
# $3 is tree source file name
oname-$(sm)-$3 := $$(if $$(oname-$1-y),$(out-dir)/$(base-prefix)/$$(oname-$1-y),$2)
$$(eval $$(call process-file-vars-helper,$1,$$(oname-$(sm)-$3)))
endef

define process-subdir-srcs-y
ifeq ($$(sub-dir),.)
srcs += $1
oname := $(out-dir)/$(base-prefix)$(basename $1).o
srcs += $1
fname := $1
oname := $(out-dir)/$(base-prefix)$(basename $1).o
else
ifneq ($(filter /%,$(1)),)
# $1 is an absolute path - start with "/"
srcs += $1
oname := $(out-dir)/$(base-prefix)$(basename $1).o
srcs += $1
fname := $1
oname := $(out-dir)/$(base-prefix)$(basename $1).o
else
srcs += $(sub-dir)/$1
oname := $(out-dir)/$(base-prefix)$(basename $$(sub-dir)/$1).o
srcs += $(sub-dir)/$1
fname := $(sub-dir)/$1
oname := $(out-dir)/$(base-prefix)$(basename $$(sub-dir)/$1).o
endif
endif
$$(eval $$(call process-file-vars,$1,$$(oname)))
$$(eval $$(call process-file-vars,$1,$$(oname),$$(fname)))
endef #process-subdir-srcs-y

define process-subdir-srcs_ext-y
ifneq ($(filter /%,$(1)),)
$$(error Absolute path not supported for srcs_ext-y: $(1))
endif
srcs += $2/$1
fname := $2/$1
ifeq ($$(sub-dir),.)
oname := $(out-dir)/$(base-prefix)$(basename $1).o
else
oname := $(out-dir)/$(base-prefix)$(basename $$(sub-dir)/$1).o
endif
$$(eval $$(call process-file-vars,$1,$$(oname),$$(fname)))
endef #process-subdir-srcs-y

define process-subdir-gensrcs-helper
Expand Down Expand Up @@ -124,9 +149,13 @@ endif
# Process files in current directory
$$(foreach g, $$(gensrcs-y), $$(eval $$(call process-subdir-gensrcs-y,$$(g))))
$$(foreach s, $$(srcs-y), $$(eval $$(call process-subdir-srcs-y,$$(s))))
$$(foreach s, $$(srcs_ext-y), $$(eval $$(call \
process-subdir-srcs_ext-y,$$(s),$$(firstword $$(srcs_ext_base-y)))))
$$(foreach a, $$(asm-defines-y), $$(eval $$(call process-subdir-asm-defines-y,$$(a))))
# Clear flags used when processing current directory
srcs-y :=
srcs_ext-y :=
srcs_ext_base-y :=
cflags-y :=
cflags-lib-y :=
cxxflags-y :=
Expand Down

0 comments on commit 2e48051

Please sign in to comment.