📄 builtin.jam
字号:
# Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears in
# all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
# Defines standard features and rules.
import "class" : new ;
import feature : feature compose ;
import toolset : flags ;
import errors : error ;
import type ;
import scanner ;
import generators ;
import regex ;
import virtual-target ;
import os ;
import prebuilt ;
import symlink ;
import alias ;
import property ;
import print ;
import utility ;
# This feature is used to determine which OS we're on.
# In future, this may become <target-os> and <host-os>
local os = [ modules.peek : OS ] ;
feature os : $(os) : propagated link-incompatible ;
feature toolset : : implicit propagated link-incompatible symmetric ;
feature stdlib : native : propagated link-incompatible composite ;
feature link : shared static : propagated ;
feature link-runtime : shared static : propagated ;
feature runtime-debugging : on off : propagated ;
feature optimization : off speed space : propagated ;
feature profiling : off on : propagated ;
feature inlining : off on full : propagated ;
feature threading : single multi : link-incompatible propagated ;
feature rtti : on off : link-incompatible propagated ;
feature exception-handling : on off : propagated ;
feature debug-symbols : on off : propagated ;
feature define : : free ;
feature "include" : : free path ;
feature cflags : : free ;
feature cxxflags : : free ;
feature linkflags : : free ;
feature archiveflags : : free ;
feature version : : free ;
feature use : : free dependency ;
feature implicit-dependency : : free dependency ;
feature library : : free dependency ;
feature find-shared-library : : free ;
feature find-static-library : : free ;
feature library-path : : free path ;
# Internal feature.
feature library-file : : free dependency ;
feature uses : : free ;
feature name : : free ;
feature tag : : free ;
feature search : : free path ;
feature location : : free path ;
feature dll-path : : free path ;
feature hardcode-dll-paths : false true : incidental propagated ;
#provides means to specify def-file for windows dlls.
feature def-file : : free dependency ;
# This feature is used to allow specific generators to run.
# For example, QT tools can only be invoked when QT library
# is used. In that case, <allow>qt will be in usage requirement
# of the library.
feature allow : : free ;
feature dependency : : free dependency ;
# Windows-specific features
feature user-interface : console gui wince native auto ;
feature variant : : implicit composite propagated symmetric ;
# Declares a new variant.
# First determines explicit properties for this variant, by
# refining parents' explicit properties with the passed explicit
# properties. The result is remembered and will be used if
# this variant is used as parent.
#
# Second, determines the full property set for this variant by
# adding to the explicit properties default values for all properties
# which neither present nor are symmetric.
#
# Lastly, makes appropriate value of 'variant' property expand
# to the full property set.
rule variant ( name # Name of the variant
: parents-or-properties * # Specifies parent variants, if
# 'explicit-properties' are given,
# and explicit-properties otherwise.
: explicit-properties * # Explicit properties.
)
{
local parents ;
if ! $(explicit-properties)
{
if $(parents-or-properties[1]:G)
{
explicit-properties = $(parents-or-properties) ;
}
else
{
parents = $(parents-or-properties) ;
}
}
else
{
parents = $(parents-or-properties) ;
}
# The problem is that we have to check for conflicts
# between base variants.
if $(parents[2])
{
error "multiple base variants are not yet supported" ;
}
local inherited ;
# Add explicitly specified properties for parents
for local p in $(parents)
{
# TODO: the check may be sticter
if ! [ feature.is-implicit-value $(p) ]
{
error "Invalid base varaint" $(p) ;
}
inherited += $(.explicit-properties.$(p)) ;
}
property.validate $(explicit-properties) ;
explicit-properties = [ property.refine $(inherited) : $(explicit-properties) ] ;
# Record explicitly specified properties for this variant
# We do this after inheriting parents' properties, so that
# they affect other variants, derived from this one.
.explicit-properties.$(name) = $(explicit-properties) ;
feature.extend variant : $(name) ;
feature.compose <variant>$(name) : $(explicit-properties) ;
}
IMPORT $(__name__) : variant : : variant ;
variant debug : <optimization>off <debug-symbols>on <inlining>off <runtime-debugging>on ;
variant release : <optimization>speed <debug-symbols>off <inlining>full <runtime-debugging>off ;
variant profile : release : <profiling>on <debug-symbols>on ;
# When <optimization>speed is specified, we need to add <define>NDEBUG
# It is done via 'active' features, because it should be done for
# all targets built with <optimization>speed. Since <define> is free, it is
# not propagated, we can't just add it to 'release'. And we cannot make
# <define> propagated, because (i) free features cannot be propagated and
# (ii) this is dangerous.
rule handle-ndebug ( property : properties * )
{
return <define>NDEBUG ;
}
feature.action <optimization>speed : handle-ndebug ;
class searched-lib-target : abstract-file-target
{
rule __init__ ( name
: project
: shared ?
: real-name ?
: search *
)
{
abstract-file-target.__init__ $(name) : SEARCHED_LIB : $(project) ;
self.shared = $(shared) ;
self.real-name = $(real-name) ;
self.real-name ?= $(name) ;
self.search = $(search) ;
}
rule shared ( )
{
return $(self.shared) ;
}
rule real-name ( )
{
return $(self.real-name) ;
}
rule search ( )
{
return $(self.search) ;
}
rule actualize-location ( target )
{
NOTFILE $(target) ;
}
rule path ( )
{
}
}
type.register LIB : : : main ;
# register the given type on the specified OSes, or on remaining OSes
# if os is not specified.
local rule declare-type ( os * : type : suffixes * : base-type ? : main ? )
{
if ! [ type.registered $(type) ]
{
if ( ! $(os) ) || [ os.name ] in $(os)
{
type.register $(type) : $(suffixes) : $(base-type) : $(main) ;
}
}
}
#
# Common target types.
#
declare-type NT CYGWIN : OBJ : obj : : main ;
declare-type : OBJ : o : : main ;
declare-type NT CYGWIN : STATIC_LIB : lib a : LIB : main ;
declare-type : STATIC_LIB : a : LIB : main ;
declare-type : IMPORT_LIB : : STATIC_LIB : main ;
type.set-generated-target-suffix IMPORT_LIB : : lib ;
declare-type NT CYGWIN : SHARED_LIB : dll : LIB : main ;
declare-type : SHARED_LIB : so : LIB : main ;
declare-type : SEARCHED_LIB : : LIB : main ;
declare-type NT CYGWIN : EXE : exe : : ;
declare-type : EXE : : : ;
declare-type : PYTHON_EXTENSION : : SHARED_LIB : main ;
# We can't give "dll" suffix to PYTHON_EXTENSION, because
# we would not know what "a.dll" is: python extenstion or
# ordinary library. Therefore, we specify only suffixes
# used for generation of targets.
type.set-generated-target-suffix PYTHON_EXTENSION : : so ;
type.set-generated-target-suffix PYTHON_EXTENSION : <os>NT : so ;
type.set-generated-target-suffix PYTHON_EXTENSION : <os>CYGWIN : dll ;
type.register CPP : cpp cxx cc ;
import stage ;
class c-scanner : scanner
{
import regex virtual-target path scanner ;
rule __init__ ( includes * )
{
scanner.__init__ ;
self.includes = $(includes) ;
}
rule pattern ( )
{
return "#include[ ]*(<(.*)>|\"(.*)\")" ;
}
rule process ( target : matches * : binding )
{
local angle = [ regex.transform $(matches) : "<(.*)>" ] ;
local quoted = [ regex.transform $(matches) : "\"(.*)\"" ] ;
# CONSIDER: the new scoping rule seem to defeat "on target" variables.
local g = [ on $(target) return $(HDRGRIST) ] ;
local b = [ NORMALIZE_PATH $(binding:D) ] ;
# Attach binding of including file to included targets.
# When target is directly created from virtual target
# this extra information is unnecessary. But in other
# cases, it allows to distinguish between two headers of the
# same name included from different places.
# We don't need this extra information for angle includes,
# since they should not depend on including file (we can't
# get literal "." in include path).
local g2 = $(g)"#"$(b) ;
angle = $(angle:G=$(g)) ;
quoted = $(quoted:G=$(g2)) ;
local all = $(angle) $(quoted) ;
INCLUDES $(target) : $(all) ;
NOCARE $(all) ;
SEARCH on $(angle) = $(self.includes:G=) ;
SEARCH on $(quoted) = $(b) $(self.includes:G=) ;
# Just propagate current scanner to includes, in a hope
# that includes do not change scanners.
scanner.propagate $(__name__) : $(angle) $(quoted) : $(target) ;
}
}
scanner.register c-scanner : include ;
type.set-scanner CPP : c-scanner ;
type.register H : h ;
type.register HPP : hpp : H ;
type.register C : c ;
class lib-target-class : basic-target
{
import generators : construct : generators.construct ;
import type ;
import path ;
rule __init__ ( name : project
: sources * : requirements * : default-build * : usage-requirements * )
{
basic-target.__init__ $(name) : $(project)
: $(sources) : $(requirements) : $(default-build) : $(usage-requirements) ;
}
rule construct ( source-targets * : property-set )
{
local properties = [ $(property-set).raw ] ;
# Determine the needed target type
local actual-type ;
if <search> in $(properties:G) || <name> in $(properties:G)
{
actual-type = SEARCHED_LIB ;
}
else if <link>shared in $(properties)
{
actual-type = SHARED_LIB ;
}
else
{
actual-type = STATIC_LIB ;
}
property-set = [ $(property-set).add-raw <main-target-type>LIB ] ;
# Construct the target.
return [ generators.construct $(self.project) $(self.name) : $(actual-type)
: $(property-set) : $(source-targets) : LIB ] ;
}
rule compute-usage-requirements ( subvariant )
{
local rproperties = [ $(subvariant).build-properties ] ;
local created-targets = [ $(subvariant).created-targets ] ;
local result = [ basic-target.compute-usage-requirements $(subvariant) ] ;
# For lib targets with <search>, add the value of <search> as <library-path>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -