mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-20 19:40:13 +00:00

This should accomodate everyone, unless they are trying to do out- of-tree builds and also have unicode in their file paths. Works for me anyways.
200 lines
6.6 KiB
Python
200 lines
6.6 KiB
Python
# 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("$TESTFILE");
|
|
if (music == NULL) {
|
|
exit(1);
|
|
}
|
|
exit(0);
|
|
}
|
|
\n
|
|
'''
|
|
test_program1 = context.env.Clone(TESTFILE = File("data/core/music/main_menu.ogg").rfile().abspath).subst(test_program)
|
|
#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_program1, ".c")
|
|
if result:
|
|
context.Result("yes")
|
|
return True
|
|
else:
|
|
test_program2 = context.env.Clone(TESTFILE = "data/core/music/main_menu.ogg").subst(test_program)
|
|
(result, output) = context.TryRun(test_program2, ".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 = "$TESTFILE";
|
|
|
|
src = SDL_RWFromFile(testimage, "rb");
|
|
if (src == NULL) {
|
|
exit(2);
|
|
}
|
|
exit(!IMG_isPNG(src));
|
|
}
|
|
\n
|
|
'''
|
|
test_program1 = context.env.Clone(TESTFILE = File("images/buttons/button_normal/button_H22-pressed.png").rfile().abspath).subst(test_program)
|
|
context.Message("Checking for PNG support in SDL... ")
|
|
if context.env["host"]:
|
|
context.Result("n/a (cross-compile)")
|
|
return True
|
|
(result, output) = context.TryRun(test_program1, ".c")
|
|
if result:
|
|
context.Result("yes")
|
|
return True
|
|
else:
|
|
test_program2 = context.env.Clone(TESTFILE = "images/buttons/button_normal/button_H22-pressed.png").subst(test_program)
|
|
(result, output) = context.TryRun(test_program2, ".c")
|
|
if result:
|
|
context.Result("yes")
|
|
return True
|
|
else:
|
|
context.Result("no")
|
|
return False
|
|
|
|
def CheckJPG(context):
|
|
test_program = '''
|
|
#include <SDL_image.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
SDL_RWops *src;
|
|
char *testimage = "$TESTFILE";
|
|
|
|
src = SDL_RWFromFile(testimage, "rb");
|
|
if (src == NULL) {
|
|
exit(2);
|
|
}
|
|
exit(!IMG_isJPG(src));
|
|
}
|
|
\n
|
|
'''
|
|
test_program1 = context.env.Clone(TESTFILE = File("data/core/images/maps/background.jpg").rfile().abspath).subst(test_program)
|
|
context.Message("Checking for JPG support in SDL... ")
|
|
if context.env["host"]:
|
|
context.Result("n/a (cross-compile)")
|
|
return True
|
|
(result, output) = context.TryRun(test_program1, ".c")
|
|
if result:
|
|
context.Result("yes")
|
|
return True
|
|
else:
|
|
test_program2 = context.env.Clone(TESTFILE = "data/core/images/maps/background.jpg").subst(test_program)
|
|
(result, output) = context.TryRun(test_program2, ".c")
|
|
if result:
|
|
context.Result("yes")
|
|
return True
|
|
else:
|
|
context.Result("no")
|
|
return False
|
|
|
|
config_checks = { 'CheckSDL' : CheckSDL,
|
|
'CheckOgg' : CheckOgg,
|
|
'CheckPNG' : CheckPNG,
|
|
'CheckJPG' : CheckJPG }
|