/
sdl.py
144 lines (134 loc) · 4.6 KB
/
sdl.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
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
# vi: syntax=python:et:ts=4
import os
from SCons.Script import *
from config_check_utils import *
def CheckSDL(context, sdl_lib = "SDL", require_version = None, header_file = None):
if require_version:
version = require_version.split(".", 2)
major_version = int(version[0])
minor_version = int(version[1])
try:
patchlevel = int(version[2])
except (ValueError, IndexError):
patch_level = 0
if header_file:
sdl_header = header_file
else:
sdl_header = sdl_lib
backup = backup_env(context.env, ["CPPPATH", "LIBPATH", "LIBS"])
sdldir = context.env.get("sdldir", "")
if sdl_lib == "SDL":
if require_version:
context.Message("Checking for Simple DirectMedia Layer library version >= %d.%d.%d... " % (major_version, minor_version, patchlevel))
else:
context.Message("Checking for Simple DirectMedia Layer library... ")
if major_version == 2:
sdl_config_name = "sdl2-config"
sdl_include_dir = "include/SDL2"
sdl_lib_name = "SDL2"
sdl_lib_name_pkgconfig = "sdl2"
sdlmain_name = "SDL2main"
else:
sdl_config_name = "sdl-config"
sdl_include_dir = "include/SDL"
sdl_lib_name = "SDL"
sdl_lib_name_pkgconfig = "sdl"
sdlmain_name = "SDLmain"
env = context.env
if sdldir:
env.AppendUnique(CPPPATH = [os.path.join(sdldir, sdl_include_dir)], LIBPATH = [os.path.join(sdldir, "lib")])
else:
for foo_config in [
"pkg-config --cflags --libs %s" % sdl_lib_name_pkgconfig,
"%s --cflags --libs" % sdl_config_name
]:
try:
env.ParseConfig(foo_config)
except OSError:
pass
else:
break
if env["PLATFORM"] == "win32":
env.AppendUnique(CCFLAGS = ["-D_GNU_SOURCE"])
env.AppendUnique(LIBS = Split("mingw32 %s %s" % (sdlmain_name, sdl_lib_name)))
env.AppendUnique(LINKFLAGS = ["-mwindows"])
else:
if require_version:
context.Message("Checking for %s library version >= %d.%d.%d... " % (sdl_lib, major_version, minor_version, patchlevel))
else:
context.Message("Checking for %s library... " % sdl_lib)
context.env.AppendUnique(LIBS = [sdl_lib])
test_program = """
#include <%s.h>
\n""" % sdl_header
if require_version:
test_program += "#if SDL_VERSIONNUM(%s, %s, %s) < SDL_VERSIONNUM(%d, %d, %d)\n#error Library is too old!\n#endif\n" % \
(sdl_lib.upper() + "_MAJOR_VERSION", \
sdl_lib.upper() + "_MINOR_VERSION", \
sdl_lib.upper() + "_PATCHLEVEL", \
major_version, minor_version, patchlevel)
test_program += """
int main(int argc, char** argv)
{
}
\n"""
if context.TryLink(test_program, ".c"):
context.Result("yes")
return True
else:
context.Result("no")
restore_env(context.env, backup)
return False
def CheckOgg(context):
test_program = '''
#include <SDL_mixer.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
Mix_Music* music = Mix_LoadMUS("data/core/music/main_menu.ogg");
if (music == NULL) {
exit(1);
}
exit(0);
}
\n
'''
#context.env.AppendUnique(LIBS = "SDL_mixer")
context.Message("Checking for Ogg Vorbis support in SDL... ")
if context.env["host"]:
context.Result("n/a (cross-compile)")
return True
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
def CheckPNG(context):
test_program = '''
#include <SDL_image.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
SDL_RWops *src;
char *testimage = "images/buttons/button_normal/button_H22-pressed.png";
src = SDL_RWFromFile(testimage, "rb");
if (src == NULL) {
exit(2);
}
exit(!IMG_isPNG(src));
}
\n
'''
context.Message("Checking for PNG support in SDL... ")
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
config_checks = { 'CheckSDL' : CheckSDL,
'CheckOgg' : CheckOgg,
'CheckPNG' : CheckPNG }