diff --git a/build/jam/BuildSetup b/build/jam/BuildSetup index 79d2923808..43b48e69f7 100644 --- a/build/jam/BuildSetup +++ b/build/jam/BuildSetup @@ -11,13 +11,22 @@ # directory paths and the like. -# If the target to be built is "all" (i.e. the default) and we're in the output -# directory, the root directory of the build system, or in "src/", we change the -# target to be built to "haiku-image". +# analyze an optionally replace jam's target parameters HAIKU_ORIGINAL_JAM_TARGETS = $(JAM_TARGETS) ; -if $(JAM_TARGETS) = all { - if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src { - JAM_TARGETS = haiku-image ; +if $(JAM_TARGETS) { + # If the target to be built is "all" (i.e. the default) and we're in the + # output directory, the root directory of the build system, or in "src/", we + # change the target to be built to "haiku-image". + if $(JAM_TARGETS) = all { + if ! $(INVOCATION_SUBDIR) || $(INVOCATION_SUBDIR) = src { + JAM_TARGETS = haiku-image ; + } + + # The "run" target allows for running arbitrary command lines containing + # build system targets, which are built and replaced accordingly. + } else if $(JAM_TARGETS[1]) = run && $(JAM_TARGETS[2]) { + local run = [ RunCommandLine $(JAM_TARGETS[2-]) ] ; + JAM_TARGETS = $(run) ; } } diff --git a/build/jam/MiscRules b/build/jam/MiscRules index 0246215686..95d7ce1818 100644 --- a/build/jam/MiscRules +++ b/build/jam/MiscRules @@ -159,3 +159,61 @@ rule NewUniqueTarget basename local id = [ NextID ] ; return $(basename[1]:E=_target:G=unique!target)_$(id) ; } + + +# pragma mark - RunCommandLine + + +rule RunCommandLine commandLine +{ + # RunCommandLine + # + # Creates a pseudo target that, when made by jam, causes the supplied shell + # command line to be executed. Elements of with the prefix ":" + # are replaced by the rule. After stripping the prefix such a string specifies + # a build system target and the finally executed command line will contain + # a path to the target instead. + # The pseudo target will depend on all targets thus identified. Each + # invocation of this rule creates a different pseudo target, which is + # returned to the caller. + + # collect the targets in the command line and replace them by $targetX* + # variables + local substitutedCommandLine ; + local targets ; + + local targetVarName = target ; + local i ; + for i in $(commandLine) { + # targets are marked by the ":" prefix + local target = [ Match :(.*) : $(i) ] ; + if $(target) { + targets += $(target) ; + targetVarName = $(targetVarName)X ; + i = "$"$(targetVarName) ; + } + + substitutedCommandLine += $(i) ; + } + + # define the "run" target + local run = [ NewUniqueTarget run ] ; + COMMAND_LINE on $(run) = $(substitutedCommandLine) ; + NotFile $(run) ; + Always $(run) ; + Depends $(run) : $(targets) ; + RunCommandLine1 $(run) : $(targets) ; + + return $(run) ; +} + +actions RunCommandLine1 { + target=target; + for t in $(2) ; do + target+=X + eval "${target}=${t}" + done + $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) + $(COMMAND_LINE) +} +