2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-16 13:22:11 +00:00
Files
build/v2/tools/gcc.jam
Vladimir Prus 0ec36774c0 Move 'OPTION' to the end of link action for unix toolset.
In particular, this allows to explicitly link statically to some
libs, using <linkflags> feature. In static libs are specified at
the beginning of the command line, we'll just get link errors.


[SVN r25548]
2004-10-04 07:29:49 +00:00

262 lines
8.2 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 ;
feature.extend toolset : gcc ;
toolset.inherit gcc : unix ;
# 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 ;
# Initializes the gcc toolset
# The name parameter specifies the name used to invoke the compiler, and
# can be absolute.
rule init ( version ? : command * : compiler-options * : linker-options * )
{
local condition = [ common.check-init-parameters gcc : version $(version) ] ;
local command = [ common.get-invocation-command gcc : g++ : $(command) ] ;
flags gcc CONFIG_COMMAND $(condition) : $(command) ;
flags gcc.compile OPTIONS $(condition) : $(compiler-options) ;
flags gcc.link OPTIONS $(condition) : $(linker-options) ;
}
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 ;
# 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 <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
{
flags gcc.compile OPTIONS <link>shared/<main-target-type>LIB : -fPIC ;
}
if [ os.name ] != NT
{
HAVE_SONAME = "" ;
}
flags gcc.compile OPTIONS <cflags> ;
flags gcc.compile.c++ 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) -Wall -ftemplate-depth-100 $(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) -Wall $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
}
# The class which check that we don't try to use
# the <link-runtime>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 <link-runtime>static in [ $(property-set).raw ]
{
local m ;
if [ id ] = "gcc.link.dll"
{
m = "on gcc, DLL can't be build with <link-runtime>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 <link-runtime>static options is not possible " ;
}
}
}
if $(m)
{
errors.user-error $(m) :
"it's suggested to use <link-runtime>static together with the <link>static" ;
}
}
return [ unix-linking-generator.generated-targets
$(sources) : $(property-set) : $(property-set) $(name) ] ;
}
}
# Declare flags and action for linking
flags gcc.link OPTIONS <debug-symbols>on : -g ;
# 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 gcc.link OPTIONS <debug-symbols>off : -Wl,--strip-all ;
flags gcc.link OPTIONS <profiling>on : -pg ;
flags gcc.link 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 <link-runtime>static we made sure there are no dynamic libraries
# in the link
flags gcc.link OPTIONS <link-runtime>static : -static ;
flags gcc.link RPATH <dll-path> ;
flags gcc.link RPATH_LINK <xdll-path> ;
# 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.
#if [ os.name ] = SOLARIS
#{
# flags gcc.link OPTIONS <link>shared : -mimpure-text ;
#}
rule link ( targets * : sources * : properties * )
{
SPACE on $(targets) = " " ;
}
actions link bind LIBRARIES
{
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(OPTIONS)
}
# Declare action for creating static libraries
# The 'r' letter means to replace files in the archive
# The 'u' letter means only outdated files in the archive
# should be replaced.
# 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 ruc "$(<)" "$(>)"
}
rule link.dll ( targets * : sources * : properties * )
{
SPACE on $(targets) = " " ;
}
# Differ from 'link' above only by -shared.
actions link.dll bind LIBRARIES
{
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -o "$(<)" $(HAVE_SONAME)-Wl,-h$(SPACE)-Wl,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(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 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 * :
{
flags gcc OPTIONS <threading>multi : -pthread ;
flags gcc FINDLIBS-SA <threading>multi : rt ;
}
}
}