File: SConstruct

package info (click to toggle)
flightgear 1%3A2020.3.16%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 50,944 kB
  • sloc: cpp: 245,473; ansic: 181,318; sh: 13,686; perl: 4,475; python: 3,139; xml: 899; asm: 642; makefile: 349; java: 314
file content (147 lines) | stat: -rw-r--r-- 5,440 bytes parent folder | download | duplicates (13)
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
import sys, os.path

def rsplit(toSplit, sub, max=-1):
    """ str.rsplit seems to have been introduced in 2.4 :( """
    l = []
    i = 0
    while i != max:
        try: idx = toSplit.rindex(sub)
        except ValueError: break

        toSplit, splitOff = toSplit[:idx], toSplit[idx + len(sub):]
        l.insert(0, splitOff)
        i += 1

    l.insert(0, toSplit)
    return l

sconsDir = os.path.join("build", "scons")
SConscript(os.path.join(sconsDir, "SConscript_common"))
Import("Platform", "Posix", "ApiVer")

# SConscript_opts exports PortAudio options
optsDict = SConscript(os.path.join(sconsDir, "SConscript_opts"))
optionsCache = os.path.join(sconsDir, "options.cache")   # Save options between runs in this cache
options = Options(optionsCache, args=ARGUMENTS)
for k in ("Installation Dirs", "Build Targets", "Host APIs", "Build Parameters", "Bindings"):
    options.AddOptions(*optsDict[k])
# Propagate options into environment
env = Environment(options=options)
# Save options for next run
options.Save(optionsCache, env)
# Generate help text for options
env.Help(options.GenerateHelpText(env))

buildDir = os.path.join("#", sconsDir, env["PLATFORM"])

# Determine parameters to build tools
if Platform in Posix:
    baseLinkFlags = threadCFlags = "-pthread"
    baseCxxFlags = baseCFlags = "-Wall -pedantic -pipe " + threadCFlags
    debugCxxFlags = debugCFlags = "-g"
    optCxxFlags = optCFlags  = "-O2"
env["CCFLAGS"] = baseCFlags.split()
env["CXXFLAGS"] = baseCxxFlags.split()
env["LINKFLAGS"] = baseLinkFlags.split()
if env["enableDebug"]:
    env.AppendUnique(CCFLAGS=debugCFlags.split())
    env.AppendUnique(CXXFLAGS=debugCxxFlags.split())
if env["enableOptimize"]:
    env.AppendUnique(CCFLAGS=optCFlags.split())
    env.AppendUnique(CXXFLAGS=optCxxFlags.split())
if not env["enableAsserts"]:
    env.AppendUnique(CPPDEFINES=["-DNDEBUG"])
if env["customCFlags"]:
    env.Append(CCFLAGS=env["customCFlags"])
if env["customCxxFlags"]:
    env.Append(CXXFLAGS=env["customCxxFlags"])
if env["customLinkFlags"]:
    env.Append(LINKFLAGS=env["customLinkFlags"])

env.Append(CPPPATH=[os.path.join("#", "include"), "common"])

# Store all signatures in one file, otherwise .sconsign files will get installed along with our own files
env.SConsignFile(os.path.join(sconsDir, ".sconsign"))

env.SConscriptChdir(False)
sources, sharedLib, staticLib, tests, portEnv = env.SConscript(os.path.join("src", "SConscript"),
        build_dir=buildDir, duplicate=False, exports=["env"])

if Platform in Posix:
    prefix = env["prefix"]
    includeDir = os.path.join(prefix, "include")
    libDir = os.path.join(prefix, "lib")
    env.Alias("install", includeDir)
    env.Alias("install", libDir)

    # pkg-config

    def installPkgconfig(env, target, source):
        tgt = str(target[0])
        src = str(source[0])
        f = open(src)
        try: txt = f.read()
        finally: f.close()
        txt = txt.replace("@prefix@", prefix)
        txt = txt.replace("@exec_prefix@", prefix)
        txt = txt.replace("@libdir@", libDir)
        txt = txt.replace("@includedir@", includeDir)
        txt = txt.replace("@LIBS@", " ".join(["-l%s" % l for l in portEnv["LIBS"]]))
        txt = txt.replace("@THREAD_CFLAGS@", threadCFlags)

        f = open(tgt, "w")
        try: f.write(txt)
        finally: f.close()

    pkgconfigTgt = "portaudio-%d.0.pc" % int(ApiVer.split(".", 1)[0])
    env.Command(os.path.join(libDir, "pkgconfig", pkgconfigTgt),
        os.path.join("#", pkgconfigTgt + ".in"), installPkgconfig)

# Default to None, since if the user disables all targets and no Default is set, all targets
# are built by default
env.Default(None)
if env["enableTests"]:
    env.Default(tests)
if env["enableShared"]:
    env.Default(sharedLib)

    if Platform in Posix:
        def symlink(env, target, source):
            trgt = str(target[0])
            src = str(source[0])

            if os.path.islink(trgt) or os.path.exists(trgt):
                os.remove(trgt)
            os.symlink(os.path.basename(src), trgt)

        major, minor, micro = [int(c) for c in ApiVer.split(".")]
        
        soFile = "%s.%s" % (os.path.basename(str(sharedLib[0])), ApiVer)
        env.InstallAs(target=os.path.join(libDir, soFile), source=sharedLib)
        # Install symlinks
        symTrgt = os.path.join(libDir, soFile)
        env.Command(os.path.join(libDir, "libportaudio.so.%d.%d" % (major, minor)),
            symTrgt, symlink)
        symTrgt = rsplit(symTrgt, ".", 1)[0]
        env.Command(os.path.join(libDir, "libportaudio.so.%d" % major), symTrgt, symlink)
        symTrgt = rsplit(symTrgt, ".", 1)[0]
        env.Command(os.path.join(libDir, "libportaudio.so"), symTrgt, symlink)

if env["enableStatic"]:
    env.Default(staticLib)
    env.Install(libDir, staticLib)

env.Install(includeDir, os.path.join("include", "portaudio.h"))

if env["enableCxx"]:
    env.SConscriptChdir(True)
    cxxEnv = env.Copy()
    sharedLibs, staticLibs, headers = env.SConscript(os.path.join("bindings", "cpp", "SConscript"),
            exports={"env": cxxEnv, "buildDir": buildDir}, build_dir=os.path.join(buildDir, "portaudiocpp"), duplicate=False)
    if env["enableStatic"]:
        env.Default(staticLibs)
        env.Install(libDir, staticLibs)
    if env["enableShared"]:
        env.Default(sharedLibs)
        env.Install(libDir, sharedLibs)
    env.Install(os.path.join(includeDir, "portaudiocpp"), headers)