Debian Codegraph @

3rdparty/iaxclient/lib/portaudio/src/SConscript

raw
1 import os.path, copy, sys
2
3 def checkSymbol(conf, header, library=None, symbol=None, autoAdd=True, critical=False, pkgName=None):
4 """ Check for symbol in library, optionally look only for header.
5 @param conf: Configure instance.
6 @param header: The header file where the symbol is declared.
7 @param library: The library in which the symbol exists, if None it is taken to be the standard C library.
8 @param symbol: The symbol to look for, if None only the header will be looked up.
9 @param autoAdd: Automatically link with this library if check is positive.
10 @param critical: Raise on error?
11 @param pkgName: Optional name of pkg-config entry for library, to determine build parameters.
12 @return: True/False
13 """
14 origEnv = conf.env.Copy() # Copy unmodified environment so we can restore it upon error
15 env = conf.env
16 if library is None:
17 library = "c" # Standard library
18 autoAdd = False
19
20 if pkgName is not None:
21 origLibs = copy.copy(env.get("LIBS", None))
22
23 try: env.ParseConfig("pkg-config --silence-errors %s --cflags --libs" % pkgName)
24 except: pass
25 else:
26 # I see no other way of checking that the parsing succeeded, if it did add no more linking parameters
27 if env.get("LIBS", None) != origLibs:
28 autoAdd = False
29
30 try:
31 if not conf.CheckCHeader(header, include_quotes="<>"):
32 raise ConfigurationError("missing header %s" % header)
33 if symbol is not None and not conf.CheckLib(library, symbol, language="C", autoadd=autoAdd):
34 raise ConfigurationError("missing symbol %s in library %s" % (symbol, library))
35 except ConfigurationError:
36 conf.env = origEnv
37 if not critical:
38 return False
39 raise
40
41 return True
42
43 import SCons.Errors
44
45 # Import common variables
46
47 # Could use '#' to refer to top-level SConstruct directory, but looks like env.SConsignFile doesn't interpret this at least :(
48 sconsDir = os.path.abspath(os.path.join("build", "scons"))
49
50 try:
51 Import("Platform", "Posix", "ConfigurationError", "ApiVer")
52 except SCons.Errors.UserError:
53 # The common objects must be exported first
54 SConscript(os.path.join(sconsDir, "SConscript_common"))
55 Import("Platform", "Posix", "ConfigurationError", "ApiVer")
56
57 Import("env")
58
59 # This will be manipulated
60 env = env.Copy()
61
62 # We operate with a set of needed libraries and optional libraries, the latter stemming from host API implementations.
63 # For libraries of both types we record a set of values that is used to look for the library in question, during
64 # configuration. If the corresponding library for a host API implementation isn't found, the implementation is left out.
65 neededLibs = []
66 optionalImpls = {}
67 if Platform in Posix:
68 env.Append(CPPPATH=os.path.join("os", "unix"))
69 neededLibs += [("pthread", "pthread.h", "pthread_create"), ("m", "math.h", "sin")]
70 if env["useALSA"]:
71 optionalImpls["ALSA"] = ("asound", "alsa/asoundlib.h", "snd_pcm_open")
72 if env["useJACK"]:
73 optionalImpls["JACK"] = ("jack", "jack/jack.h", "jack_client_new")
74 if env["useOSS"]:
75 # TODO: It looks like the prefix for soundcard.h depends on the platform
76 optionalImpls["OSS"] = ("oss", "sys/soundcard.h", None)
77 else:
78 raise ConfigurationError("unknown platform %s" % Platform)
79
80 if Platform == "darwin":
81 env.Append(LINKFLAGS=["-framework CoreAudio", "-framework AudioToolBox"])
82 env.Append(CPPDEFINES=["PA_USE_COREAUDIO"])
83 elif Platform == "cygwin":
84 env.Append(LIBS=["winmm"])
85 elif Platform == "irix":
86 neededLibs += [("audio", "dmedia/audio.h", "alOpenPort"), ("dmedia", "dmedia/dmedia.h", "dmGetUST")]
87 env.Append(CPPDEFINES=["PA_USE_SGI"])
88
89 def CheckCTypeSize(context, tp):
90 """ Check size of C type.
91 @param context: A configuration context.
92 @param tp: The type to check.
93 @return: Size of type, in bytes.
94 """
95 context.Message("Checking the size of C type %s..." % tp)
96 ret = context.TryRun("""
97 #include <stdio.h>
98
99 int main() {
100 printf("%%d", sizeof(%s));
101 return 0;
102 }
103 """ % tp, ".c")
104 if not ret[0]:
105 context.Result(" Couldn't obtain size of type %s!" % tp)
106 return None
107
108 assert ret[1]
109 sz = int(ret[1])
110 context.Result("%d" % sz)
111 return sz
112
113 """
114 if sys.byteorder == "little":
115 env.Append(CPPDEFINES=["PA_LITTLE_ENDIAN"])
116 elif sys.byteorder == "big":
117 env.Append(CPPDEFINES=["PA_BIG_ENDIAN"])
118 else:
119 raise ConfigurationError("unknown byte order: %s" % sys.byteorder)
120 """
121 if env["enableDebugOutput"]:
122 env.Append(CPPDEFINES=["PA_ENABLE_DEBUG_OUTPUT"])
123
124 # Start configuration
125
126 # Use an absolute path for conf_dir, otherwise it gets created both relative to current directory and build directory
127 conf = env.Configure(log_file=os.path.join(sconsDir, "sconf.log"), custom_tests={"CheckCTypeSize": CheckCTypeSize},
128 conf_dir=os.path.join(sconsDir, ".sconf_temp"))
129 env.Append(CPPDEFINES=["SIZEOF_SHORT=%d" % conf.CheckCTypeSize("short")])
130 env.Append(CPPDEFINES=["SIZEOF_INT=%d" % conf.CheckCTypeSize("int")])
131 env.Append(CPPDEFINES=["SIZEOF_LONG=%d" % conf.CheckCTypeSize("long")])
132 if checkSymbol(conf, "time.h", "rt", "clock_gettime"):
133 env.Append(CPPDEFINES=["HAVE_CLOCK_GETTIME"])
134 if checkSymbol(conf, "time.h", symbol="nanosleep"):
135 env.Append(CPPDEFINES=["HAVE_NANOSLEEP"])
136
137 # Look for needed libraries and link with them
138 for lib, hdr, sym in neededLibs:
139 checkSymbol(conf, hdr, lib, sym, critical=True)
140 # Look for host API libraries, if a library isn't found disable corresponding host API implementation.
141 for name, val in optionalImpls.items():
142 lib, hdr, sym = val
143 if checkSymbol(conf, hdr, lib, sym, critical=False, pkgName=name.lower()):
144 env.Append(CPPDEFINES=["PA_USE_%s=1" % name.upper()])
145 else:
146 del optionalImpls[name]
147
148 # Configuration finished
149 env = conf.Finish()
150
151 # PA infrastructure
152 CommonSources = [os.path.join("common", f) for f in "pa_allocation.c pa_converters.c pa_cpuload.c pa_dither.c pa_front.c \
153 pa_process.c pa_skeleton.c pa_stream.c pa_trace.c".split()]
154
155 # Host API implementations
156 ImplSources = []
157 if Platform in Posix:
158 ImplSources += [os.path.join("os", "unix", f) for f in "pa_unix_hostapis.c pa_unix_util.c".split()]
159
160 if "ALSA" in optionalImpls:
161 ImplSources.append(os.path.join("hostapi", "alsa", "pa_linux_alsa.c"))
162 if "JACK" in optionalImpls:
163 ImplSources.append(os.path.join("hostapi", "jack", "pa_jack.c"))
164 if "OSS" in optionalImpls:
165 ImplSources.append(os.path.join("hostapi", "oss", "pa_unix_oss.c"))
166
167 sources = CommonSources + ImplSources
168
169 sharedLibEnv = env.Copy()
170 if Platform in Posix:
171 # Add soname to library, this is so a reference is made to the versioned library in programs linking against libportaudio.so
172 sharedLibEnv.AppendUnique(SHLINKFLAGS="-Wl,-soname=libportaudio.so.%d" % int(ApiVer.split(".")[0]))
173 sharedLib = sharedLibEnv.SharedLibrary(target="portaudio", source=sources)
174
175 staticLib = env.StaticLibrary(target="portaudio", source=sources)
176
177 if Platform in Posix:
178 prefix = env["prefix"]
179 includeDir = os.path.join(prefix, "include")
180 libDir = os.path.join(prefix, "lib")
181
182 testNames = ["patest_sine", "paqa_devs", "paqa_errs", "patest1", "patest_buffer", "patest_callbackstop", "patest_clip", \
183 "patest_dither", "patest_hang", "patest_in_overflow", "patest_latency", "patest_leftright", "patest_longsine", \
184 "patest_many", "patest_maxsines", "patest_multi_sine", "patest_out_underflow", "patest_pink", "patest_prime", \
185 "patest_read_record", "patest_record", "patest_ringmix", "patest_saw", "patest_sine8", "patest_sine", \
186 "patest_sine_time", "patest_start_stop", "patest_stop", "patest_sync", \
187 "patest_toomanysines", "patest_underflow", "patest_wire", "patest_write_sine", "pa_devs", "pa_fuzz", "pa_minlat"]
188
189 # The test directory ("bin") should be in the top-level PA directory
190 tests = [env.Program(target=os.path.join("#", "bin", name), source=[os.path.join("#", "test", name + ".c"),
191 staticLib]) for name in testNames]
192
193 Return("sources", "sharedLib", "staticLib", "tests", "env")