-
Notifications
You must be signed in to change notification settings - Fork 6
/
SConsExternCommon.py
107 lines (83 loc) · 3.37 KB
/
SConsExternCommon.py
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
from SCons.Util import flatten
# create script header with various exports for compiler and flags.
# returns list of script lines.
#
# env: Environment to fins parameters in
# deps: List of parent targets to depend on.
# cppflags: Optional list of manual cpp flags
# linkflags: Optional list of manual link flags
def createScriptHeader(env, deps=[], cflags=[], cppflags=[], cxxflags=[], linkflags=[], pkgconfig=[], nosan=False):
script = []
# append all known compiler declarations if present
exportCommand = 'export'
if env['HostOSWindows']:
exportCommand = 'SET'
for x in ['CC', 'CXX', 'LD', 'AS', 'AR', 'STRIP', 'MAKE', 'RC', 'RANLIB', 'NM', 'NASM']:
if x in env:
script.append('{} {}="{}"'.format(exportCommand, x, env.subst(env[x])))
# combine all flags into one array to later write out to the script
combinedCFlags = []
combinedCPPFlags = []
combinedCXXFlags = []
combinedLinkFlags = []
combinedPkgConfig = []
# append the cross compiler flags if present
if 'CROSSCOMPILE_CFLAGS' in env:
combinedCFlags.extend( env[ 'CROSSCOMPILE_CFLAGS' ] )
if 'CROSSCOMPILE_CXXFLAGS' in env:
combinedCXXFlags.extend( env[ 'CROSSCOMPILE_CXXFLAGS' ] )
if nosan:
if 'CROSSCOMPILE_NOSAN_CPPFLAGS' in env:
combinedCPPFlags.extend( env[ 'CROSSCOMPILE_NOSAN_CPPFLAGS' ] )
if 'CROSSCOMPILE_NOSAN_LINKFLAGS' in env:
combinedLinkFlags.extend( env[ 'CROSSCOMPILE_NOSAN_LINKFLAGS' ] )
else:
if 'CROSSCOMPILE_CPPFLAGS' in env:
combinedCPPFlags.extend( env[ 'CROSSCOMPILE_CPPFLAGS' ] )
if 'CROSSCOMPILE_LINKFLAGS' in env:
combinedLinkFlags.extend( env[ 'CROSSCOMPILE_LINKFLAGS' ] )
if 'CROSSCOMPILE_PKGCONFIG' in env:
combinedPkgConfig.extend( env[ 'CROSSCOMPILE_PKGCONFIG' ] )
# append manual flags
combinedCFlags.extend( cflags )
combinedCPPFlags.extend( cppflags )
combinedCXXFlags.extend( cxxflags )
combinedLinkFlags.extend( linkflags )
combinedPkgConfig.extend(pkgconfig)
# append required flags for dependencies
for dep in deps:
if 'cflags' in dep:
combinedCFlags.extend( dep[ 'cflags' ] )
if 'cppflags' in dep:
combinedCPPFlags.extend( dep[ 'cppflags' ] )
if 'cxxflags' in dep:
combinedCXXFlags.extend( dep[ 'cxxflags' ] )
if 'cpppath' in dep:
for path in dep[ 'cpppath' ]:
combinedCPPFlags.append( '-I{}'.format(
env.Dir( '#{}'.format( path ) ).abspath ) )
if 'libpath' in dep:
for path in dep[ 'libpath' ]:
combinedLinkFlags.append( '-L{}'.format(
env.Dir( '#{}'.format( path ) ).abspath ) )
if 'pkgconfig' in dep:
for path in dep['pkgconfig']:
combinedPkgConfig.append(env.Dir('#{}'.format(path)).abspath)
# write flags to script
if combinedCFlags:
script.append( 'export CFLAGS="{}"'.format( ' '.join(
[ env.subst( x ) for x in flatten( combinedCFlags ) ] ) ) )
if combinedCPPFlags:
script.append( 'export CPPFLAGS="{}"'.format( ' '.join(
[ env.subst( x ) for x in flatten( combinedCPPFlags ) ] ) ) )
if combinedCXXFlags:
script.append( 'export CXXFLAGS="{}"'.format( ' '.join(
[ env.subst( x ) for x in flatten( combinedCXXFlags ) ] ) ) )
if combinedLinkFlags:
script.append( 'export LDFLAGS="{}"'.format( ' '.join(
[ env.subst( x ) for x in flatten( combinedLinkFlags ) ] ) ) )
if combinedPkgConfig:
script.append('export PKG_CONFIG_PATH="{}"'.format(':'.join(
[env.subst(x) for x in flatten(combinedPkgConfig)])))
# return finished script lines
return script