-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSConstruct
137 lines (111 loc) · 3.95 KB
/
SConstruct
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
import os, glob, re
def detectCPUs():
import os
"""
Detects the number of CPUs on a system. Cribbed from pp.
"""
# Linux, Unix and MacOS:
if hasattr(os, "sysconf"):
if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix:
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(ncpus, int) and ncpus > 0:
return ncpus
else: # OSX:
return int(os.popen2("sysctl -n hw.ncpu")[1].read())
# Windows:
if "NUMBER_OF_PROCESSORS" in os.environ:
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
if ncpus > 0:
return ncpus
return 1 # Default
SetOption('num_jobs', detectCPUs())
debug = ARGUMENTS.get("debug", "")
static = ARGUMENTS.get("static", "")
def defaultEnvironment():
env = Environment(ENV = os.environ)
#env.Replace(CC = "clang")
env.Append(CCFLAGS = ['-g3', '-Wall'])
return env
def allegro_libname(name):
allegro_version = "5"
if static:
version = "static-" + allegro_version
else:
version = allegro_version
if debug:
return name + "-debug-" + version
else:
return name + "-" + version
def CheckPKGConfig(context, version):
context.Message( 'Checking for pkg-config... ' )
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
context.Result( ret )
return ret
def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result( ret )
return ret
class Cache:
def __init__(self):
self.allegro_libs = None
def get_env(self):
env = defaultEnvironment()
if self.allegro_libs is None:
self.allegro_libs = ["allegro", "allegro_primitives",
"allegro_image", "allegro_font", "allegro_audio",
"allegro_acodec"]
tests = {
"CheckPKGConfig": CheckPKGConfig,
"CheckPKG" : CheckPKG}
conf = Configure(env, tests)
if conf.CheckPKGConfig:
if conf.CheckPKG(allegro_libname("allegro_monolith")):
self.allegro_libs = ["allegro_monolith"]
env = conf.Finish()
options = " --libs"
if static:
options += " --static"
env.ParseConfig("pkg-config " + " ".join([allegro_libname(l)
for l in self.allegro_libs]) + options)
return env
cache = Cache()
def allegro4Environment():
env = cache.get_env()
env.Prepend(LIBS = [allegroLibrary(), 'm'])
# env.Prepend(LIBS = [allegroLibrary()])
env.Append(CPPPATH = ['#allegro4'])
return env
allegro_store = [None]
def allegroLibrary():
# Return the cached version
if allegro_store[0] != None:
return allegro_store[0]
env = defaultEnvironment()
library = SConscript('allegro4/SConscript', variant_dir = 'build/allegro', exports = ['env'], duplicate = False)
Alias('library', library)
#build = 'build-allegro'
#env.VariantDir(build, 'allegro4')
#source = Split("""allegro.c math3d.c math.c file.c unicode.c color.c clip3df.c""")
#library = env.StaticLibrary('%s/allegro4-to-5' % build, ['%s/%s' % (build, file) for file in source])
# Cache the allegro library so its not built each time allegroLibrary()
# is called
allegro_store[0] = library
return allegro_store[0]
def makeExample(source):
env = allegro4Environment()
env.VariantDir('build/examples', 'examples', duplicate = False)
return env.Program('build/examples/' + source)
def stars():
return makeExample('exstars.c')
def shade():
return makeExample('exshade.c')
def demos():
env = allegro4Environment()
SConscript('demos/SConscript', variant_dir = 'build/demos', exports = ['env'], duplicate = False)
examples = glob.glob("examples/*.c")
for example in examples:
name = re.sub(r"examples/(.*?)\.c", r"\1", example)
makeExample(name + ".c")
demos()