📄 gcc.jam
字号:
# Copyright 2001 David Abrahams.# Copyright 2002-2006 Rene Rivera.# Copyright 2002-2003 Vladimir Prus.# Copyright (c) 2005 Reece H. Dunn.# Copyright 2006 Ilya Sokolov.# Copyright 2007 Roland Schwarz# Copyright 2007 Boris Gubenko.## Distributed under the Boost Software License, Version 1.0.# (See accompanying file LICENSE_1_0.txt or copy at# http://www.boost.org/LICENSE_1_0.txt)import "class" : new ;import common ;import errors ;import feature ;import generators ;import os ;import pch ;import property ;import property-set ;import toolset ;import type ;import rc ;import regex ;import set ;import unix ;if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]{ .debug-configuration = true ;}feature.extend toolset : gcc ;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 ;# Target naming is determined by types/lib.jam and the settings below this# comment.## On *nix:# libxxx.a static library# libxxx.so shared library## On windows (mingw):# libxxx.lib static library# xxx.dll DLL# xxx.lib import library## On windows (cygwin) i.e. <target-os>cygwin# libxxx.a static library# xxx.dll DLL# libxxx.dll.a import library## Implementation notes:# * User can always override this by using the <tag>@rule.# * These settings have been chosen so that mingw is in line with msvc naming# conventions.# * For cygwin the cygwin naming convention has been chosen.# Make gcc toolset object files use the "o" suffix on all platforms.type.set-generated-target-suffix OBJ : <toolset>gcc : o ;type.set-generated-target-suffix OBJ : <toolset>gcc <target-os>windows : o ;type.set-generated-target-suffix OBJ : <toolset>gcc <target-os>cygwin : o ;type.set-generated-target-suffix STATIC_LIB : <toolset>gcc <target-os>cygwin : a ;type.set-generated-target-suffix IMPORT_LIB : <toolset>gcc <target-os>cygwin : dll.a ;type.set-generated-target-prefix IMPORT_LIB : <toolset>gcc <target-os>cygwin : lib ;# 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 specified as# <option-name>option-value. Valid option names are: cxxflags, linkflags and# linker-type. Accepted linker-type values are aix, darwin, gnu, hpux, osf or# sun and the default value will be selected based on the current OS.# Example:# using gcc : 3.4 : : <cxxflags>foo <linkflags>bar <linker-type>sun ;#rule init ( version ? : command * : options * ){ # Information about the gcc command... # The command. local command = [ common.get-invocation-command gcc : g++ : $(command) ] ; # The root directory of the tool install. local root = [ feature.get-values <root> : $(options) ] ; # The bin directory where to find the command to execute. local bin ; # The flavor of compiler. local flavor = [ feature.get-values <flavor> : $(options) ] ; # Autodetect the root and bin dir if not given. if $(command) { bin ?= [ common.get-absolute-tool-path $(command[-1]) ] ; root ?= $(bin:D) ; } # Autodetect the version and flavor if not given. if $(command) { # The 'command' variable can have multiple elements. When calling # the SHELL builtin we need a single string. local command-string = $(command:J=" ") ; local machine = [ MATCH "^([^ ]+)" : [ SHELL "$(command-string) -dumpmachine" ] ] ; version ?= [ MATCH "^([0-9.]+)" : [ SHELL "$(command-string) -dumpversion" ] ] ; switch $(machine:L) { case *mingw* : flavor ?= mingw ; } } local condition ; if $(flavor) { condition = [ common.check-init-parameters gcc : version $(version) : flavor $(flavor) ] ; } else { condition = [ common.check-init-parameters gcc : version $(version) ] ; } common.handle-options gcc : $(condition) : $(command) : $(options) ; local linker = [ feature.get-values <linker-type> : $(options) ] ; if ! $(linker) { if [ os.name ] = OSF { linker = osf ; } else if [ os.name ] = HPUX { linker = hpux ; } else if [ os.name ] = AIX { linker = aix ; } else { linker = gnu ; } } init-link-flags gcc $(linker) $(condition) ; # 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)/bin $(root)/lib $(root)/lib32 $(root)/lib64 ; if $(.debug-configuration) { ECHO notice: using gcc libraries :: $(condition) :: $(lib_path) ; } toolset.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 ] ; toolset.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-nodefault 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. 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 ;# pch support# The compiler looks for a precompiled header in each directory just before it# looks for the include file in that directory. The name searched for is the# name specified in the #include directive with ".gch" suffix appended. The# logic in gcc-pch-generator will make sure that BASE_PCH suffix is appended to# full name of the header.type.set-generated-target-suffix PCH : <toolset>gcc : gch ;# GCC-specific pch generator.class gcc-pch-generator : pch-generator{ import project ; import property-set ; import type ; rule run-pch ( project name ? : property-set : sources + ) { # Find the header in sources. Ignore any CPP sources. local header ; for local s in $(sources) { if [ type.is-derived [ $(s).type ] H ] { header = $(s) ; } } # Error handling: Base header file name should be the same as the base # precompiled header name. local header-name = [ $(header).name ] ; local header-basename = $(header-name:B) ; if $(header-basename) != $(name) { local location = [ $(project).project-module ] ; errors.user-error "in" $(location)": pch target name `"$(name)"' should be the same as the base name of header file `"$(header-name)"'" ; } local pch-file = [ generator.run $(project) $(name) : $(property-set) : $(header) ] ; # return result of base class and pch-file property as usage-requirements return [ property-set.create <pch-file>$(pch-file) <cflags>-Winvalid-pch ] $(pch-file) ; } # Calls the base version specifying source's name as the name of the created # target. As result, the PCH will be named whatever.hpp.gch, and not # whatever.gch. rule generated-targets ( sources + : property-set : project name ? ) { name = [ $(sources[1]).name ] ; return [ generator.generated-targets $(sources) : $(property-set) : $(project) $(name) ] ; }}# Note: the 'H' source type will catch both '.h' header and '.hpp' header. The# latter have HPP type, but HPP type is derived from H. The type of compilation# is determined entirely by the destination type.generators.register [ new gcc-pch-generator gcc.compile.c.pch : H : C_PCH : <pch>on <toolset>gcc ] ;generators.register [ new gcc-pch-generator gcc.compile.c++.pch : H : CPP_PCH : <pch>on <toolset>gcc ] ;# Override default do-nothing generators.generators.override gcc.compile.c.pch : pch.default-c-pch-generator ;generators.override gcc.compile.c++.pch : pch.default-cpp-pch-generator ;toolset.flags gcc.compile PCH_FILE <pch>on : <pch-file> ;# Declare flags and action for compilation.toolset.flags gcc.compile OPTIONS <optimization>off : -O0 ;toolset.flags gcc.compile OPTIONS <optimization>speed : -O3 ;toolset.flags gcc.compile OPTIONS <optimization>space : -Os ;toolset.flags gcc.compile OPTIONS <inlining>off : -fno-inline ;toolset.flags gcc.compile OPTIONS <inlining>on : -Wno-inline ;toolset.flags gcc.compile OPTIONS <inlining>full : -finline-functions -Wno-inline ;toolset.flags gcc.compile OPTIONS <warnings>off : -w ;toolset.flags gcc.compile OPTIONS <warnings>on : -Wall ;toolset.flags gcc.compile OPTIONS <warnings>all : -Wall -pedantic ;toolset.flags gcc.compile OPTIONS <warnings-as-errors>on : -Werror ;toolset.flags gcc.compile OPTIONS <debug-symbols>on : -g ;toolset.flags gcc.compile OPTIONS <profiling>on : -pg ;toolset.flags gcc.compile OPTIONS <rtti>off : -fno-rtti ;rule setup-fpic ( targets * : sources * : properties * ){ local link = [ feature.get-values link : $(properties) ] ; if $(link) = shared { local target = [ feature.get-values target-os : $(properties) ] ; # This logic will add -fPIC for all compilations:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -