1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#! /usr/bin/env python
# encoding: utf-8
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006 (ita)
# Ralf Habacker, 2006 (rh)
import os, optparse, sys
import Params, Configure
import ccroot, ar
def find_cxx(conf):
v = conf.env
cc = None
if v['CXX']: cc = v['CXX']
elif 'CXX' in os.environ: cc = os.environ['CXX']
if not cc: cc = conf.find_program('g++', var='CXX')
if not cc: cc = conf.find_program('c++', var='CXX')
if not cc: conf.fatal('g++ was not found')
v['CXX'] = cc
def common_flags(conf):
v = conf.env
# CPPFLAGS CXXDEFINES _CXXINCFLAGS _CXXDEFFLAGS _LIBDIRFLAGS _LIBFLAGS
v['CXX_SRC_F'] = ''
v['CXX_TGT_F'] = '-c -o '
v['CPPPATH_ST'] = '-I%s' # template for adding include paths
# linker
if not v['LINK_CXX']: v['LINK_CXX'] = v['CXX']
v['CXXLNK_SRC_F'] = ''
v['CXXLNK_TGT_F'] = '-o '
v['LIB_ST'] = '-l%s' # template for adding libs
v['LIBPATH_ST'] = '-L%s' # template for adding libpaths
v['STATICLIB_ST'] = '-l%s'
v['STATICLIBPATH_ST'] = '-L%s'
v['CXXDEFINES_ST'] = '-D%s'
v['SHLIB_MARKER'] = '-Wl,-Bdynamic'
v['STATICLIB_MARKER'] = '-Wl,-Bstatic'
# program
v['program_PATTERN'] = '%s'
# shared library
v['shlib_CXXFLAGS'] = ['-fPIC', '-DPIC']
v['shlib_LINKFLAGS'] = ['-shared']
v['shlib_PATTERN'] = 'lib%s.so'
# static lib
v['staticlib_LINKFLAGS'] = ['-Wl,-Bstatic']
v['staticlib_PATTERN'] = 'lib%s.a'
def modifier_win32(conf):
v = conf.env
v['program_PATTERN'] = '%s.exe'
v['shlib_PATTERN'] = 'lib%s.dll'
v['shlib_CXXFLAGS'] = ['']
v['staticlib_LINKFLAGS'] = ['']
def modifier_cygwin(conf):
v = conf.env
v['program_PATTERN'] = '%s.exe'
v['shlib_PATTERN'] = 'lib%s.dll'
v['shlib_CXXFLAGS'] = ['']
v['staticlib_LINKFLAGS'] = ['']
def modifier_darwin(conf):
v = conf.env
v['shlib_CXXFLAGS'] = ['-fPIC']
v['shlib_LINKFLAGS'] = ['-dynamiclib']
v['shlib_PATTERN'] = 'lib%s.dylib'
v['staticlib_LINKFLAGS'] = ['']
v['SHLIB_MARKER'] = ''
v['STATICLIB_MARKER'] = ''
def modifier_aix5(conf):
v = conf.env
v['program_LINKFLAGS'] = ['-Wl,-brtl']
v['shlib_LINKFLAGS'] = ['-shared','-Wl,-brtl,-bexpfull']
v['SHLIB_MARKER'] = ''
def modifier_plugin(conf):
v = conf.env
# TODO this will disappear somehow
# plugins. We handle them exactly as shlibs
# everywhere except on osx, where we do bundles
if sys.platform == 'darwin':
v['plugin_LINKFLAGS'] = ['-bundle', '-undefined dynamic_lookup']
v['plugin_CXXFLAGS'] = ['-fPIC']
v['plugin_PATTERN'] = '%s.bundle'
else:
v['plugin_CXXFLAGS'] = v['shlib_CXXFLAGS']
v['plugin_LINKFLAGS'] = v['shlib_LINKFLAGS']
v['plugin_PATTERN'] = v['shlib_PATTERN']
def modifier_debug(conf):
v = conf.env
# compiler debug levels
if conf.check_flags('-O2'):
v['CXXFLAGS_OPTIMIZED'] = ['-O2']
v['CXXFLAGS_RELEASE'] = ['-O2']
if conf.check_flags('-g -DDEBUG'):
v['CXXFLAGS_DEBUG'] = ['-g', '-DDEBUG']
if conf.check_flags('-g3 -O0 -DDEBUG'):
v['CXXFLAGS_ULTRADEBUG'] = ['-g3', '-O0', '-DDEBUG']
if conf.check_flags('-Wall'):
for x in 'OPTIMIZED RELEASE DEBUG ULTRADEBUG'.split(): v.append_unique('CXXFLAGS_'+x, '-Wall')
try:
debug_level = Params.g_options.debug_level.upper()
except AttributeError:
debug_level = ccroot.DEBUG_LEVELS.CUSTOM
v.append_value('CXXFLAGS', v['CXXFLAGS_'+debug_level])
def detect(conf):
find_cxx(conf)
ar.find_cpp(conf)
ar.find_ar(conf)
conf.check_tool('cxx')
common_flags(conf)
if sys.platform == 'win32': modifier_win32(conf)
elif sys.platform == 'cygwin': modifier_cygwin(conf)
elif sys.platform == 'darwin': modifier_darwin(conf)
elif sys.platform == 'aix5': modifier_aix5(conf)
modifier_plugin(conf)
conf.check_tool('checks')
conf.check_features(kind='cpp')
modifier_debug(conf)
conf.add_os_flags('CXXFLAGS')
conf.add_os_flags('CPPFLAGS')
conf.add_os_flags('LINKFLAGS')
def set_options(opt):
try:
opt.add_option('-d', '--debug-level',
action = 'store',
default = ccroot.DEBUG_LEVELS.RELEASE,
help = "Specify the debug level, does nothing if CXXFLAGS is set in the environment. [Allowed Values: '%s']" % "', '".join(ccroot.DEBUG_LEVELS.ALL),
choices = ccroot.DEBUG_LEVELS.ALL,
dest = 'debug_level')
except optparse.OptionConflictError:
# the gcc tool might have added that option already
pass
|