Boost logo

Boost-Build :

From: Thomas Witt (witt_at_[hidden])
Date: 2002-02-26 06:08:11


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

The attached patch introduces a new rule template that can be used to
conveniently define project wide requirements. Furthermore
a change to the with-command-file rule is made to allow for
additional prefix string that contains non-sources. I need this to circumvent
cmdline restrictions with long libpathes on windows.

Here is an example of template usage.

#
# Defining requirements template
#
template TplBase
:
:
# requirements
<include>../myinclude
<define>TEMPLATE
# build not covered so far.
;

#
# Defining another requirements template
# that inherits requirements
#
template TplDerived
:
# only <template> dependencies go here
<template>TplBase
:
<include>../anotherinclude
<define>DERIVED_TEMPLATE
;

#
# Exe that uses requirements from TplDerived
#
exe MyExe
:
main.cpp
<template>TplDerived
:
:
debug
;

I am using template in two projects and it reduces the maintenance work
by at least an order of magnitude. Currently template covers only
requirements but I think it can be extended to cover build settings to. The
need for requirements was just more pressing :-). If this goes in I will
happily update the documentation.

Thomas

- --
Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001
http://www.ive.uni-hannover.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8e2yg0ds/gS3XsBoRAlOtAKCGvE3yuhgpMiGQZf4voYt/YQr2CwCfWEoa
fv8flr9IuLiXrrp6vlELgX0=
=4NKn
-----END PGP SIGNATURE-----
 --------------Boundary-00=_N905ZF6G18HN03F0MXB6 Content-Type: text/x-diff;
charset="us-ascii";
name="boost-base.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="boost-base.patch"

*** boost-base.jam Tue Feb 26 11:31:48 2002
--- boost-base-cvs.jam Tue Feb 26 10:38:03 2002
***************
*** 1153,1159 ****
local x-target = [ expand-target-names $(target) : $(target-type) ] ;
local x-sources = [ expand-source-names $(sources) ] ;

! # We add SOURCE_GRIST to the base target name here because we're referring the
# abstract target which generates all of the actual builds. We need a way to
# distinguish targets of the same name from different subprojects.
local target-id = [ FGristFiles $(x-target) ] ;
--- 1153,1159 ----
local x-target = [ expand-target-names $(target) : $(target-type) ] ;
local x-sources = [ expand-source-names $(sources) ] ;

! # We add SOURCE_GRIST the base target name here because we're referring the
# abstract target which generates all of the actual builds. We need a way to
# distinguish targets of the same name from different subprojects.
local target-id = [ FGristFiles $(x-target) ] ;
***************
*** 1174,1180 ****
= $(requirements) $(gTARGET_TYPE_REQUIREMENTS($(target-type))) <target-type>$(target-type) ;
local libs ;
local dlls ;
- local templates ;
for local source in [ select-gristed $(x-sources) ]
{
local grist = [ SUBST $(source:G) (<)(.*)(>) $2 ] ;
--- 1174,1179 ----
***************
*** 1186,1203 ****
{
dlls += $(source:G=) ;
}
- if $(gTARGET_TYPE_ID($(grist))) = TEMPLATE
- {
- templates += $(source:G=) ;
- }
}
! gTARGET_LIBS($(target-id)) = $(libs) ;
! gTARGET_DLLS($(target-id)) = $(dlls) ;
! gTARGET_TEMPLATES($(target-id)) = $(templates) ;

gTARGET_SOURCES($(target-id))
= [ FGristFiles
! [ difference $(x-sources:G=) : $(gTARGET_LIBS($(target-id))) $(gTARGET_DLLS($(target-id))) $(gTARGET_TEMPLATES($(target-id))) ] ] ;

}
else if $(gTARGET_TYPE($(target-id))) != $(target-type)
--- 1185,1197 ----
{
dlls += $(source:G=) ;
}
}
! gTARGET_LIBS($(target-id)) = $(libs) ;
! gTARGET_DLLS($(target-id)) = $(dlls) ;

gTARGET_SOURCES($(target-id))
= [ FGristFiles
! [ difference $(x-sources:G=) : $(gTARGET_LIBS($(target-id))) $(gTARGET_DLLS($(target-id))) ] ] ;

}
else if $(gTARGET_TYPE($(target-id))) != $(target-type)
***************
*** 1212,1219 ****

declare-fake-targets $(target) : $(target-id) ;

- evaluate-templates $(target-id) ;
-
# Just gather information if we are including a library's Jamfile for a
# dependent target. Don't generate build instructions here.
if ! $(gIN_LIB_INCLUDE)
--- 1206,1211 ----
***************
*** 1223,1276 ****
return $(gTARGET_FILES($(target-id))) ;
}

- # declare-local-template name : sources : requirements
- #
- # declares a subproject-local template target of the given name.
- rule declare-local-template ( target : sources * : requirements * )
- {
- # We expand out the name of the target and sources
- local x-target = [ expand-target-names $(target) : TEMPLATE ] ;
-
- # We add SOURCE_GRIST the base target name here because we're referring the
- # abstract target which generates all of the actual builds. We need a way to
- # distinguish targets of the same name from different subprojects.
- local target-id = [ FGristFiles $(x-target) ] ;
-
- if ! $(gTARGET_TYPE($(target-id)))
- {
- gTARGET_TYPE($(target-id)) = TEMPLATE ;
- gTARGET_NAME($(target-id)) = $(target) ;
-
- # Add the specified requirements to any requirements given by the target.
- gTARGET_REQUIREMENTS($(target-id))
- = $(requirements) ;
- local templates ;
- for local source in $(sources)
- {
- local grist = [ SUBST $(source:G) (<)(.*)(>) $2 ] ;
- if $(gTARGET_TYPE_ID($(grist))) = TEMPLATE
- {
- templates += $(source:G=) ;
- }
- else
- {
- EXIT Only <template> sources allowed for template "$(x-target)" ;
- }
- }
- gTARGET_TEMPLATES($(target-id)) = $(templates) ;
-
- }
- else if $(gTARGET_TYPE($(target-id))) != $(target-type)
- {
- EXIT conflicting target types for "$(x-target)":
- "$(gTARGET_TYPE($(target-id)))" "$(target-type)" ;
- }
-
- evaluate-templates $(target-id) ;
-
- return "" ;
- }
-
# directory-of files...
#
# Returns a list of the directories containing each element of files
--- 1215,1220 ----
***************
*** 1448,1479 ****
return $(result) ;
}

- # rule grist-templates templates ...
- #
- # Returns a list of target-ids for the given template
- # pathes.
- #
- rule grist-templates ( templates + )
- {
- local result ;
-
- for local lib-path in $(templates)
- {
- local new-subdir = TOP [ top-relative-tokens [ directory-of $(lib-path) ] ] ;
-
- # protect global variables from being permanently set by SubDir
- local [ protect-subdir ] ;
-
- # Enter the dependee subproject
- SubDir $(new-subdir) ;
-
- result += [ FGristFiles $(lib-path:D=) ] ;
- }
-
- return $(result) ;
- }
-
-
# Which configuration(s) to build if nothing is explicitly specified
DEFAULT_BUILD ?= debug ;

--- 1392,1397 ----
***************
*** 1661,1695 ****
return $(gTARGET_FILES($(subvariant))) ;
}

- # template-target target
- #
- # Accumulates requirements from templates for the given targets.
- #
- rule evaluate-templates ( target-id-list + )
- {
- for local target-id in $(target-id-list)
- {
- if ! $(gTEMPLATES_EVALUATED($(target-id)))
- {
- # include each jamfile describing a dependee target.
- dependent-include $(gTARGET_TEMPLATES($(target-id))) ;
-
- local template-requirements = ;
-
- if $(gTARGET_TEMPLATES($(target-id)))
- {
- local template-ids = [ grist-templates $(gTARGET_TEMPLATES($(target-id))) ] ;
-
- template-requirements = $(gTARGET_REQUIREMENTS($(template-ids))) ;
- }
-
- gTARGET_REQUIREMENTS($(target-id)) = $(template-requirements) $(gTARGET_REQUIREMENTS($(target-id))) ;
-
- gTEMPLATES_EVALUATED($(target-id)) = true ;
- }
- }
- }
-
# main-target target : local-build
#
# Generates requested subvariant build instructions for the given main target
--- 1579,1584 ----
***************
*** 1760,1777 ****
declare-local-target $(target) : $(sources) : $(requirements) : $(default-build) : LIB ;
}

- gTARGET_TYPE_ID(template) = TEMPLATE ;
- gGENERATOR_FUNCTION(TEMPLATE) = ;
- # template target : sources : requirements : local-build
- #
- # Declare a template target.
- # Template targets can be used to globally define
- # requirements and builds
- rule template ( target : sources * : requirements * )
- {
- declare-local-template $(target) : $(sources) : $(requirements) ;
- }
-
# unit-test target : sources : requirements : local-build
#
# Declare an executable target, to be run by tests.
--- 1649,1654 ----
***************
*** 1789,1806 ****
}
}

! # Used to build command files from a list of sources
! # and an optional prefix. The prefix typically contains
! # additional link options like LIBPATH and so on.
! rule build-command-file ( command : prefix * : sources * )
{
- NOTFILE $(prefix) ;
DEPENDS $(command) : $(sources) ;
! DEPENDS $(command) : $(prefix) ;
! ALWAYS $(prefix) ;
!
! local x-sources = $(prefix) $(sources) ;
!
# Check whether there's anything to dump, so that we don't end up
# executing a line of the form:
#
--- 1666,1676 ----
}
}

! # Used to build command files from a list of sources.
! rule build-command-file ( command : sources * )
{
DEPENDS $(command) : $(sources) ;
!
# Check whether there's anything to dump, so that we don't end up
# executing a line of the form:
#
***************
*** 1809,1825 ****
# on Windows this writes "echo is on." into the command-file,
# which then breaks the link.

! if $(x-sources[1])
{
# Handle the first target specially, so that the first source file
# will clear the command file
! command-file-dump-1st $(command) : $(x-sources[1]) ;
}

! if $(x-sources[2])
{
# Then fill the rest up piecemeal
! command-file-dump-rest $(command) : $(x-sources[2-]) ;
}
}

--- 1679,1695 ----
# on Windows this writes "echo is on." into the command-file,
# which then breaks the link.

! if $(sources[1])
{
# Handle the first target specially, so that the first source file
# will clear the command file
! command-file-dump-1st $(command) : $(sources[1]) ;
}

! if $(sources[2])
{
# Then fill the rest up piecemeal
! command-file-dump-rest $(command) : $(sources[2-]) ;
}
}

***************
*** 1849,1861 ****
# build TARGETS from SOURCES using a command-file, where RULE-NAME is
# used to generate the build instructions from the command-file to
# TARGETS
! rule with-command-file ( rule-name targets * : sources * : prefix * )
{
# create a command-file target and place it where the first target
# will be built
local command-file = $(targets[1]:S=.CMD) ;
LOCATE on $(command-file) = $(gLOCATE($(targets[1]))) ;
! build-command-file $(command-file) : $(prefix) : $(sources) ;

# Build the targets from the command-file instead of the sources
DEPENDS $(targets) : $(command-file) ;
--- 1719,1731 ----
# build TARGETS from SOURCES using a command-file, where RULE-NAME is
# used to generate the build instructions from the command-file to
# TARGETS
! rule with-command-file ( rule-name targets * : sources * )
{
# create a command-file target and place it where the first target
# will be built
local command-file = $(targets[1]:S=.CMD) ;
LOCATE on $(command-file) = $(gLOCATE($(targets[1]))) ;
! build-command-file $(command-file) : $(sources) ;

# Build the targets from the command-file instead of the sources
DEPENDS $(targets) : $(command-file) ;
 --------------Boundary-00=_N905ZF6G18HN03F0MXB6--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk