Name

mk_resolve_target — Resolve target to fully-qualified form

Synopsis

MODULES="... core ..."

mk_resolve_target target

Options

target

the target to resolve

Description

This function resolves a target in MakeKit target notation to a fully-qualified form which always identifies a unique resource on the filesystem. A fully-qualified target is always of the form @path where path indicates the path of the resource on the filesystem, usually relative to the root build directory.

Resolution is performed according to the form of target as follows:

@path

target is already fully-qualified and is returned verbatim by mk_resolve_target.

/file

When target is an absolute path, it designates a final build product which is placed in the stage directory while building. The qualified form is obtained by prepending @$MK_STAGE_DIR/ to file.

file

When target is a relative path, it designates a file either in the source directory hierarchy or object directory hierarchy, depending on whether file designates a source file or an intermediate build product. The file is taken to be relative to the directory containing the MakeKitBuild which specifies it. If the file exists in the source directory, the qualified form is obtained by prepending @$MK_SOURCE_DIR$MK_SUBDIR/ to file. Otherwise, the qualified form is obtained by prepending @$MK_OBJECT_DIR$MK_SUBDIR/.

This function returns 0 on success and sets result to the fully-qualified target.

Examples

# For the following examples, let:
# MK_SOURCE_DIR=source
# MK_OBJECT_DIR=object
# MK_BINDIR=/usr/bin
#
# Assume our MakeKitBuild file is in source/foobar, which also contains foo.c
     
# Example result: @source/foobar/foo.c
mk_resolve_target "foo.c"

# Example result: @object/foobar/foo.o
mk_resolve_target "foo.o"

# Example result: @stage/usr/bin/foobar
mk_resolve_target "${MK_BINDIR}/foobar"