3
def rsplit(toSplit, sub, max=-1):
4
""" str.rsplit seems to have been introduced in 2.4 :( """
8
try: idx = toSplit.rindex(sub)
9
except ValueError: break
11
toSplit, splitOff = toSplit[:idx], toSplit[idx + len(sub):]
18
sconsDir = os.path.join("build", "scons")
19
SConscript(os.path.join(sconsDir, "SConscript_common"))
20
Import("Platform", "Posix", "ApiVer")
22
# SConscript_opts exports PortAudio options
23
optsDict = SConscript(os.path.join(sconsDir, "SConscript_opts"))
24
optionsCache = os.path.join(sconsDir, "options.cache") # Save options between runs in this cache
25
options = Options(optionsCache, args=ARGUMENTS)
26
for k in ("Installation Dirs", "Build Targets", "Host APIs", "Build Parameters", "Bindings"):
27
options.AddOptions(*optsDict[k])
28
# Propagate options into environment
29
env = Environment(options=options)
30
# Save options for next run
31
options.Save(optionsCache, env)
32
# Generate help text for options
33
env.Help(options.GenerateHelpText(env))
35
buildDir = os.path.join("#", sconsDir, env["PLATFORM"])
37
# Determine parameters to build tools
40
if Platform != 'darwin':
41
threadCFlags = "-pthread "
42
baseLinkFlags = threadCFlags
43
baseCxxFlags = baseCFlags = "-Wall -pedantic -pipe " + threadCFlags
44
debugCxxFlags = debugCFlags = "-g"
45
optCxxFlags = optCFlags = "-O2"
46
env.Append(CCFLAGS = baseCFlags)
47
env.Append(CXXFLAGS = baseCxxFlags)
48
env.Append(LINKFLAGS = baseLinkFlags)
49
if env["enableDebug"]:
50
env.AppendUnique(CCFLAGS=debugCFlags.split())
51
env.AppendUnique(CXXFLAGS=debugCxxFlags.split())
52
if env["enableOptimize"]:
53
env.AppendUnique(CCFLAGS=optCFlags.split())
54
env.AppendUnique(CXXFLAGS=optCxxFlags.split())
55
if not env["enableAsserts"]:
56
env.AppendUnique(CPPDEFINES=["-DNDEBUG"])
57
if env["customCFlags"]:
58
env.Append(CCFLAGS=Split(env["customCFlags"]))
59
if env["customCxxFlags"]:
60
env.Append(CXXFLAGS=Split(env["customCxxFlags"]))
61
if env["customLinkFlags"]:
62
env.Append(LINKFLAGS=Split(env["customLinkFlags"]))
64
env.Append(CPPPATH=[os.path.join("#", "include"), "common"])
66
# Store all signatures in one file, otherwise .sconsign files will get installed along with our own files
67
env.SConsignFile(os.path.join(sconsDir, ".sconsign"))
69
env.SConscriptChdir(False)
70
sources, sharedLib, staticLib, tests, portEnv, hostApis = env.SConscript(os.path.join("src", "SConscript"),
71
build_dir=buildDir, duplicate=False, exports=["env"])
74
prefix = env["prefix"]
75
includeDir = os.path.join(prefix, "include")
76
libDir = os.path.join(prefix, "lib")
77
env.Alias("install", includeDir)
78
env.Alias("install", libDir)
82
def installPkgconfig(env, target, source):
88
txt = txt.replace("@prefix@", prefix)
89
txt = txt.replace("@exec_prefix@", prefix)
90
txt = txt.replace("@libdir@", libDir)
91
txt = txt.replace("@includedir@", includeDir)
92
txt = txt.replace("@LIBS@", " ".join(["-l%s" % l for l in portEnv["LIBS"]]))
93
txt = txt.replace("@THREAD_CFLAGS@", threadCFlags)
99
pkgconfigTgt = "portaudio-%d.0.pc" % int(ApiVer.split(".", 1)[0])
100
env.Command(os.path.join(libDir, "pkgconfig", pkgconfigTgt),
101
os.path.join("#", pkgconfigTgt + ".in"), installPkgconfig)
103
# Default to None, since if the user disables all targets and no Default is set, all targets
104
# are built by default
106
if env["enableTests"]:
108
if env["enableShared"]:
109
env.Default(sharedLib)
111
if Platform in Posix:
112
def symlink(env, target, source):
113
trgt = str(target[0])
116
if os.path.islink(trgt) or os.path.exists(trgt):
118
os.symlink(os.path.basename(src), trgt)
120
major, minor, micro = [int(c) for c in ApiVer.split(".")]
122
soFile = "%s.%s" % (os.path.basename(str(sharedLib[0])), ApiVer)
123
env.InstallAs(target=os.path.join(libDir, soFile), source=sharedLib)
125
symTrgt = os.path.join(libDir, soFile)
126
env.Command(os.path.join(libDir, "libportaudio.so.%d.%d" % (major, minor)),
128
symTrgt = rsplit(symTrgt, ".", 1)[0]
129
env.Command(os.path.join(libDir, "libportaudio.so.%d" % major), symTrgt, symlink)
130
symTrgt = rsplit(symTrgt, ".", 1)[0]
131
env.Command(os.path.join(libDir, "libportaudio.so"), symTrgt, symlink)
133
if env["enableStatic"]:
134
env.Default(staticLib)
135
env.Install(libDir, staticLib)
137
env.Install(includeDir, os.path.join("include", "portaudio.h"))
141
env.SConscriptChdir(True)
143
sharedLibs, staticLibs, headers = env.SConscript(os.path.join("bindings", "cpp", "SConscript"),
144
exports={"env": cxxEnv, "buildDir": buildDir}, build_dir=os.path.join(buildDir, "portaudiocpp"), duplicate=False)
145
if env["enableStatic"]:
146
env.Default(staticLibs)
147
env.Install(libDir, staticLibs)
148
if env["enableShared"]:
149
env.Default(sharedLibs)
150
env.Install(libDir, sharedLibs)
151
env.Install(os.path.join(includeDir, "portaudiocpp"), headers)
153
# Generate portaudio_config.h header with compile-time definitions of which PA
154
# back-ends are available, and which includes back-end extension headers
156
# Host-specific headers
157
hostApiHeaders = {"ALSA": "pa_linux_alsa.h",
159
"COREAUDIO": "pa_mac_core.h",
161
"WMME": "pa_winwmme.h",
164
def buildConfigH(target, source, env):
165
"""builder for portaudio_config.h"""
166
global hostApiHeaders, hostApis
168
for hostApi in hostApis:
169
out += "#define PA_HAVE_%s\n" % hostApi
171
hostApiSpecificHeader = hostApiHeaders.get(hostApi, None)
172
if hostApiSpecificHeader:
173
out += "#include \"%s\"\n" % hostApiSpecificHeader
176
# Strip the last newline
177
if out and out[-1] == "\n":
180
f = file(str(target[0]), 'w')
185
# Define the builder for the config header
186
env.Append(BUILDERS={"portaudioConfig": env.Builder(
187
action=Action(buildConfigH), target_factory=env.fs.File)})
189
confH = env.portaudioConfig(File("portaudio_config.h", "include"),
190
File("portaudio.h", "include"))
192
env.Install(os.path.join(includeDir, "portaudio"), confH)
195
if api in hostApiHeaders:
196
env.Install(os.path.join(includeDir, "portaudio"),
197
File(hostApiHeaders[api], "include"))