mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 13:22:11 +00:00
510 lines
17 KiB
Plaintext
510 lines
17 KiB
Plaintext
# Copyright (c) 2001 David Abrahams.
|
|
# Copyright (c) 2002-2003 Rene Rivera.
|
|
# Copyright (c) 2002-2003 Vladimir Prus.
|
|
#
|
|
# Use, modification and distribution is subject to the Boost Software
|
|
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
|
|
# http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
import toolset : flags ;
|
|
import property ;
|
|
import generators ;
|
|
import os ;
|
|
import type ;
|
|
import feature ;
|
|
import "class" : new ;
|
|
import set ;
|
|
import common ;
|
|
import errors ;
|
|
|
|
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
|
|
{
|
|
.debug-configuration = true ;
|
|
}
|
|
|
|
|
|
feature.extend toolset : gcc ;
|
|
|
|
import unix ;
|
|
toolset.inherit-generators gcc : unix : unix.link unix.link.dll ;
|
|
toolset.inherit-flags gcc : unix ;
|
|
toolset.inherit-rules gcc : unix ;
|
|
|
|
generators.override gcc.prebuilt : builtin.prebuilt ;
|
|
generators.override gcc.searched-lib-generator : searched-lib-generator ;
|
|
|
|
|
|
# Make the "o" suffix used for gcc toolset on all
|
|
# platforms
|
|
type.set-generated-target-suffix OBJ : <toolset>gcc : o ;
|
|
type.set-generated-target-suffix STATIC_LIB : <toolset>gcc : a ;
|
|
|
|
import rc ;
|
|
|
|
# Initializes the gcc toolset for the given version.
|
|
# If necessary, command may be used to specify where the compiler
|
|
# is located.
|
|
# The parameter 'options' is a space-delimited list of options, each
|
|
# one being specified as <option-name>option-value. Valid option names
|
|
# are: cxxflags, linkflags and linker-type. Accepted values for linker-type
|
|
# are gnu and sun, gnu being the default.
|
|
# Example:
|
|
# using gcc : 3.4 : : <cxxflags>foo <linkflags>bar <linker-type>sun ;
|
|
rule init ( version ? : command * : options * )
|
|
{
|
|
local condition = [ common.check-init-parameters gcc : version $(version) ] ;
|
|
|
|
local command = [ common.get-invocation-command gcc : g++ : $(command) ] ;
|
|
|
|
common.handle-options gcc : $(condition) : $(command) : $(options) ;
|
|
|
|
local linker = [ feature.get-values <linker-type> : $(options) ] ;
|
|
if ! $(linker) {
|
|
|
|
if [ os.name ] = OSF
|
|
{
|
|
linker = osf ;
|
|
}
|
|
else
|
|
{
|
|
linker = gnu ;
|
|
}
|
|
}
|
|
init-link-flags gcc $(linker) $(condition) ;
|
|
|
|
local root = [ feature.get-values <root> : $(options) ] ;
|
|
local bin ;
|
|
if $(command)
|
|
{
|
|
bin ?= [ common.get-absolute-tool-path $(command[-1]) ] ;
|
|
root ?= $(bin:D) ;
|
|
}
|
|
|
|
# If gcc is installed in non-standard location, we'd need to
|
|
# add LD_LIBRARY_PATH when running programs created with it
|
|
# (for unit-test/run rules).
|
|
if $(command)
|
|
{
|
|
# On multilib 64-bit boxes, there are both 32-bit and 64-bit
|
|
# libraries and all must be added to LD_LIBRARY_PATH. The linker
|
|
# will pick the right onces.
|
|
# Note that we don't provide a clean way to build 32-bit binary
|
|
# with 64-bit compiler, but user can always pass -m32 manually.
|
|
local lib_path = $(root)/lib $(root)/lib32 $(root)/lib64 ;
|
|
if $(.debug-configuration)
|
|
{
|
|
ECHO notice: using gcc libraries :: $(condition) :: $(lib_path) ;
|
|
}
|
|
flags gcc.link RUN_PATH $(condition) : $(lib_path) ;
|
|
}
|
|
|
|
#~ If it's not a system gcc install we should adjust the various
|
|
#~ programs as needed to prefer using the install specific versions.
|
|
#~ This is essential for correct use of MinGW and for cross-compiling.
|
|
|
|
#~ - The archive builder.
|
|
local archiver =
|
|
[ common.get-invocation-command gcc
|
|
: ar : [ feature.get-values <archiver> : $(options) ] : $(bin) : search-path ] ;
|
|
flags gcc.archive .AR $(condition) : $(archiver[1]) ;
|
|
if $(.debug-configuration)
|
|
{
|
|
ECHO notice: using gcc archiver :: $(condition) :: $(archiver[1]) ;
|
|
}
|
|
|
|
#~ - The resource compiler.
|
|
local rc =
|
|
[ common.get-invocation-command gcc
|
|
: windres : [ feature.get-values <rc> : $(options) ] : $(bin) : search-path ] ;
|
|
local rc-type =
|
|
[ feature.get-values <rc-type> : $(options) ] ;
|
|
rc-type ?= windres ;
|
|
if ! $(rc)
|
|
{
|
|
#~ If we can't find an RC compiler we fallback to a null RC compiler
|
|
#~ that creates empty object files. This allows the same Jamfiles
|
|
#~ to work across the board. The null RC uses the assembler to create
|
|
#~ the empty objects, so configure that.
|
|
local rc =
|
|
[ common.get-invocation-command gcc
|
|
: as : : $(bin) : search-path ] ;
|
|
rc-type = null ;
|
|
}
|
|
rc.configure $(rc) : $(condition) : <rc-type>$(rc-type) ;
|
|
}
|
|
|
|
if [ os.name ] = NT
|
|
{
|
|
# This causes single-line command invocation to not go through
|
|
# .bat files, thus avoiding command-line length limitations
|
|
JAMSHELL = % ;
|
|
}
|
|
|
|
generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : <toolset>gcc ;
|
|
generators.register-c-compiler gcc.compile.c : C : OBJ : <toolset>gcc ;
|
|
generators.register-c-compiler gcc.compile.asm : ASM : OBJ : <toolset>gcc ;
|
|
|
|
|
|
# Declare flags and action for compilation
|
|
flags gcc.compile OPTIONS <optimization>off : -O0 ;
|
|
flags gcc.compile OPTIONS <optimization>speed : -O3 ;
|
|
flags gcc.compile OPTIONS <optimization>space : -Os ;
|
|
|
|
flags gcc.compile OPTIONS <inlining>off : -fno-inline ;
|
|
flags gcc.compile OPTIONS <inlining>on : -Wno-inline ;
|
|
flags gcc.compile OPTIONS <inlining>full : -finline-functions -Wno-inline ;
|
|
|
|
flags gcc.compile OPTIONS <warnings>off : -w ;
|
|
flags gcc.compile OPTIONS <warnings>on : -Wall ;
|
|
flags gcc.compile OPTIONS <warnings>all : -Wall -pedantic ;
|
|
flags gcc.compile OPTIONS <warnings-as-errors>on : -Werror ;
|
|
|
|
flags gcc.compile OPTIONS <debug-symbols>on : -g ;
|
|
flags gcc.compile OPTIONS <profiling>on : -pg ;
|
|
# On cygwin and mingw, gcc generates position independent code by default,
|
|
# and warns if -fPIC is specified. This might not be the right way
|
|
# of checking if we're using cygwin. For example, it's possible
|
|
# to run cygwin gcc from NT shell, or using crosscompiling.
|
|
# But we'll solve that problem when it's time. In that case
|
|
# we'll just add another parameter to 'init' and move this login
|
|
# inside 'init'.
|
|
if [ os.name ] != CYGWIN && [ os.name ] != NT
|
|
{
|
|
# This logic will add -fPIC for all compilations:
|
|
#
|
|
# lib a : a.cpp b ;
|
|
# obj b : b.cpp ;
|
|
# exe c : c.cpp a d ;
|
|
# obj d : d.cpp ;
|
|
#
|
|
# This all is fine, except that 'd' will be compiled with
|
|
# -fPIC even though it's not needed, as 'd' is used only in
|
|
# exe. However, it's hard to detect where a target is going to
|
|
# be used. Alternative, we can set -fPIC only when main target type
|
|
# is LIB but than 'b' will be compiled without -fPIC. In x86-64 that
|
|
# will lead to link errors. So, compile everything with -fPIC.
|
|
#
|
|
# Yet another alternative would be to create propagated <sharedable>
|
|
# feature, and set it when building shared libraries, but that's hard
|
|
# to implement and will increase target path length even more.
|
|
flags gcc.compile OPTIONS <link>shared : -fPIC ;
|
|
}
|
|
if [ os.name ] != NT
|
|
{
|
|
HAVE_SONAME = "" ;
|
|
|
|
if [ os.name ] = OSF
|
|
{
|
|
SONAME_OPTION = -soname ;
|
|
}
|
|
else
|
|
{
|
|
SONAME_OPTION = -h ;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
flags gcc.compile USER_OPTIONS <cflags> ;
|
|
flags gcc.compile.c++ USER_OPTIONS <cxxflags> ;
|
|
flags gcc.compile DEFINES <define> ;
|
|
flags gcc.compile INCLUDES <include> ;
|
|
|
|
rule compile.c++
|
|
{
|
|
# Some extensions are compiled as C++ by default. For others, we need
|
|
# to pass -x c++.
|
|
# We could always pass -x c++ but distcc does not work with it.
|
|
if ! $(>:S) in .cc .cp .cxx .cpp .c++ .C
|
|
{
|
|
LANG on $(<) = "-x c++" ;
|
|
}
|
|
}
|
|
|
|
|
|
actions compile.c++
|
|
{
|
|
"$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-100 $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
|
|
}
|
|
|
|
rule compile.c
|
|
{
|
|
# If we use the name g++ then default file suffix -> language mapping
|
|
# does not work. So have to pass -x option. Maybe, we can work around this
|
|
# by allowing the user to specify both C and C++ compiler names.
|
|
#if $(>:S) != .c
|
|
#{
|
|
LANG on $(<) = "-x c" ;
|
|
#}
|
|
}
|
|
|
|
|
|
actions compile.c
|
|
{
|
|
"$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
|
|
}
|
|
|
|
rule compile.asm
|
|
{
|
|
LANG on $(<) = "-x assembler-with-cpp" ;
|
|
}
|
|
|
|
actions compile.asm
|
|
{
|
|
"$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
|
|
}
|
|
|
|
# The class which check that we don't try to use
|
|
# the <runtime-link>static property while creating or using shared library,
|
|
# since it's not supported by gcc/libc.
|
|
class gcc-linking-generator : unix-linking-generator
|
|
{
|
|
rule generated-targets ( sources + : property-set : project name ? )
|
|
{
|
|
if <runtime-link>static in [ $(property-set).raw ]
|
|
{
|
|
local m ;
|
|
if [ id ] = "gcc.link.dll"
|
|
{
|
|
m = "on gcc, DLL can't be build with <runtime-link>static" ;
|
|
}
|
|
if ! $(m) {
|
|
for local s in $(sources)
|
|
{
|
|
local type = [ $(s).type ] ;
|
|
if $(type) && [ type.is-derived $(type) SHARED_LIB ]
|
|
{
|
|
m = "on gcc, using DLLS together with the <runtime-link>static options is not possible " ;
|
|
}
|
|
}
|
|
}
|
|
if $(m)
|
|
{
|
|
errors.user-error $(m) :
|
|
"it's suggested to use <runtime-link>static together with the <link>static" ;
|
|
}
|
|
|
|
}
|
|
|
|
return [ unix-linking-generator.generated-targets
|
|
$(sources) : $(property-set) : $(project) $(name) ] ;
|
|
}
|
|
}
|
|
|
|
generators.register [ new gcc-linking-generator gcc.link : LIB OBJ : EXE
|
|
: <toolset>gcc ] ;
|
|
|
|
generators.register [ new gcc-linking-generator gcc.link.dll : LIB OBJ : SHARED_LIB
|
|
: <toolset>gcc ] ;
|
|
|
|
|
|
# Declare flags for linking
|
|
# First, the common flags
|
|
flags gcc.link OPTIONS <debug-symbols>on : -g ;
|
|
flags gcc.link OPTIONS <profiling>on : -pg ;
|
|
flags gcc.link USER_OPTIONS <linkflags> ;
|
|
flags gcc.link LINKPATH <library-path> ;
|
|
flags gcc.link FINDLIBS-ST <find-static-library> ;
|
|
flags gcc.link FINDLIBS-SA <find-shared-library> ;
|
|
flags gcc.link LIBRARIES <library-file> ;
|
|
|
|
# For <runtime-link>static we made sure there are no dynamic libraries
|
|
# in the link
|
|
flags gcc.link OPTIONS <runtime-link>static : -static ;
|
|
|
|
# Now, the vendor specific flags
|
|
# The parameter linker can be either gnu or sun
|
|
rule init-link-flags ( toolset linker condition )
|
|
{
|
|
switch $(linker)
|
|
{
|
|
case gnu :
|
|
{
|
|
# Strip the binary when no debugging is needed.
|
|
# We use --strip-all flag as opposed to -s since icc
|
|
# (intel's compiler) is generally option-compatible with
|
|
# and inherits from gcc toolset, but does not support -s
|
|
flags $(toolset).link OPTIONS $(condition)/<debug-symbols>off : -Wl,--strip-all
|
|
: unchecked ;
|
|
flags $(toolset).link RPATH $(condition) : <dll-path> : unchecked ;
|
|
flags $(toolset).link RPATH_LINK $(condition) : <xdll-path> : unchecked ;
|
|
flags $(toolset).link START-GROUP $(condition) : -Wl,--start-group : unchecked ;
|
|
flags $(toolset).link END-GROUP $(condition) : -Wl,--end-group : unchecked ;
|
|
}
|
|
case darwin :
|
|
{
|
|
# we can't pass -s to ld unless we also pass -static
|
|
# so we removed -s completly from OPTIONS and add it
|
|
# to ST_OPTIONS
|
|
flags $(toolset).link ST_OPTIONS $(condition)/<debug-symbols>off : -s
|
|
: unchecked ;
|
|
flags $(toolset).link RPATH $(condition) : <dll-path> : unchecked ;
|
|
flags $(toolset).link RPATH_LINK $(condition) : <xdll-path> : unchecked ;
|
|
}
|
|
|
|
case osf :
|
|
{
|
|
# No --strip-all, just -s
|
|
flags $(toolset).link OPTIONS $(condition)/<debug-symbols>off : -Wl,-s
|
|
: unchecked ;
|
|
|
|
flags $(toolset).link RPATH $(condition) : <dll-path> : unchecked ;
|
|
# This does not supports -R
|
|
flags $(toolset).link RPATH_OPTION $(condition) : -rpath : unchecked ;
|
|
# -rpath-link is not supported at all.
|
|
}
|
|
|
|
|
|
case sun :
|
|
{
|
|
flags $(toolset).link OPTIONS $(condition)/<debug-symbols>off : -Wl,-s
|
|
: unchecked ;
|
|
flags $(toolset).link RPATH $(condition) : <dll-path> : unchecked ;
|
|
# Solaris linker does not have a separate -rpath-link, but
|
|
# allows to use -L for the same purpose.
|
|
flags $(toolset).link LINKPATH $(condition) : <xdll-path> : unchecked ;
|
|
|
|
# This permits shared libraries with non-PIC code on Solaris
|
|
# VP, 2004/09/07: Now that we have -fPIC hardcode in link.dll,
|
|
# the following is not needed. Whether -fPIC should be hardcoded,
|
|
# is a separate question.
|
|
# AH, 2004/10/16: it is still necessary because some tests link
|
|
# against static libraries that were compiled without PIC.
|
|
flags $(toolset).link OPTIONS $(condition)/<link>shared : -mimpure-text
|
|
: unchecked ;
|
|
}
|
|
case * :
|
|
{
|
|
errors.user-error
|
|
"$(toolset) initialization: invalid linker '$(linker)'" :
|
|
"The value '$(linker)' specified for <linker> is not recognized." :
|
|
"Possible values are 'sun', 'gnu'" ;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Declare actions for linking
|
|
rule link ( targets * : sources * : properties * )
|
|
{
|
|
SPACE on $(targets) = " " ;
|
|
# Serialize execution of the 'link' action, since
|
|
# running N links in parallel is just slower.
|
|
# For now, serialize only gcc links, it might be a good
|
|
# idea to serialize all links.
|
|
JAM_SEMAPHORE on $(targets) = <s>gcc-link-semaphore ;
|
|
}
|
|
|
|
actions link bind LIBRARIES
|
|
{
|
|
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,$(RPATH_OPTION:E=-R)$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" $(START-GROUP) "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(END-GROUP) $(OPTIONS) $(USER_OPTIONS)
|
|
}
|
|
|
|
|
|
flags gcc.archive AROPTIONS <archiveflags> ;
|
|
|
|
rule archive ( targets * : sources * : properties * )
|
|
{
|
|
# Always remove archive and start again. Here's rationale from
|
|
#
|
|
# Andre Hentz:
|
|
#
|
|
# I had a file, say a1.c, that was included into liba.a.
|
|
# I moved a1.c to a2.c, updated my Jamfiles and rebuilt.
|
|
# My program was crashing with absurd errors.
|
|
# After some debugging I traced it back to the fact that a1.o was *still*
|
|
# in liba.a
|
|
#
|
|
# Rene Rivera:
|
|
#
|
|
# Originally removing the archive was done by splicing an RM
|
|
# onto the archive action. That makes archives fail to build on NT
|
|
# when they have many files because it will no longer execute the
|
|
# action directly and blow the line length limit. Instead we
|
|
# remove the file in a different action, just before the building
|
|
# of the archive.
|
|
#
|
|
local clean.a = $(targets[1])(clean) ;
|
|
TEMPORARY $(clean.a) ;
|
|
NOCARE $(clean.a) ;
|
|
LOCATE on $(clean.a) = [ on $(targets[1]) return $(LOCATE) ] ;
|
|
DEPENDS $(clean.a) : $(sources) ;
|
|
DEPENDS $(targets) : $(clean.a) ;
|
|
common.RmTemps $(clean.a) : $(targets) ;
|
|
}
|
|
|
|
# Declare action for creating static libraries
|
|
# The 'r' letter means to add files to the archive with replacement
|
|
# Since we remove archive, we don't care about replacement, but
|
|
# there's no option "add without replacement".
|
|
# The 'c' letter means suppresses warning in case the archive
|
|
# does not exists yet. That warning is produced only on
|
|
# some platforms, for whatever reasons.
|
|
actions piecemeal archive
|
|
{
|
|
"$(.AR)" $(AROPTIONS) rc "$(<)" "$(>)"
|
|
}
|
|
|
|
|
|
rule link.dll ( targets * : sources * : properties * )
|
|
{
|
|
SPACE on $(targets) = " " ;
|
|
JAM_SEMAPHORE on $(targets) = <s>gcc-link-semaphore ;
|
|
}
|
|
|
|
# Differ from 'link' above only by -shared.
|
|
actions link.dll bind LIBRARIES
|
|
{
|
|
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,$(RPATH_OPTION:E=-R)$(SPACE)-Wl,"$(RPATH)" -o "$(<)" $(HAVE_SONAME)-Wl,$(SONAME_OPTION)$(SPACE)-Wl,$(<[1]:D=) -shared $(START-GROUP) "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(END-GROUP) $(OPTIONS) $(USER_OPTIONS)
|
|
}
|
|
|
|
# Set up threading support. It's somewhat contrived, so perform it at the end,
|
|
# to avoid cluttering other code.
|
|
|
|
if [ os.on-windows ]
|
|
{
|
|
flags gcc OPTIONS <threading>multi : -mthreads ;
|
|
}
|
|
else if [ modules.peek : UNIX ]
|
|
{
|
|
switch [ modules.peek : JAMUNAME ]
|
|
{
|
|
case SunOS* :
|
|
{
|
|
flags gcc OPTIONS <threading>multi : -pthreads ;
|
|
flags gcc FINDLIBS-SA <threading>multi : rt ;
|
|
}
|
|
case BeOS :
|
|
{
|
|
# BeOS has no threading options, don't set anything here.
|
|
}
|
|
case *BSD :
|
|
{
|
|
flags gcc OPTIONS <threading>multi : -pthread ;
|
|
# there is no -lrt on BSD
|
|
}
|
|
case DragonFly :
|
|
{
|
|
flags gcc OPTIONS <threading>multi : -pthread ;
|
|
# there is no -lrt on BSD - DragonFly is a FreeBSD variant,
|
|
# which anoyingly doesn't say it's a *BSD.
|
|
}
|
|
case IRIX :
|
|
{
|
|
# gcc on IRIX does not support multi-threading, don't set anything here.
|
|
}
|
|
case HP_UX :
|
|
{
|
|
# gcc on HP-UX does not support multi-threading, don't set anything here
|
|
}
|
|
case Darwin :
|
|
{
|
|
# Darwin has no threading options, don't set anything here.
|
|
}
|
|
case * :
|
|
{
|
|
flags gcc OPTIONS <threading>multi : -pthread ;
|
|
flags gcc FINDLIBS-SA <threading>multi : rt ;
|
|
}
|
|
}
|
|
}
|