Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F134421
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
35 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/SConscript b/SConscript
index e2130b93..f6196a40 100644
--- a/SConscript
+++ b/SConscript
@@ -1,128 +1,126 @@
import os
import sys
Import('root')
sys.path.append(Dir('.').rel_path(Dir("#%s" % root)))
import scons_rtech1.utils
import scons_rtech1.checks
Import('env')
Import('build_dir_root')
build_type = 'release'
if scons_rtech1.utils.useAndroid():
build_type = 'armeabi-v7a'
if scons_rtech1.utils.useAndroidX64():
build_type = 'android-x64'
config = env.Configure(custom_tests = {'CheckAllegro5': scons_rtech1.checks.checkAllegro5(scons_rtech1.checks.debug()),
'CheckFreetype': scons_rtech1.checks.checkFreetype,
'ConfigChecks': scons_rtech1.checks.configChecks,
'CheckCXX11': scons_rtech1.checks.checkCXX11,})
if scons_rtech1.utils.useAndroidX64():
env['HAVE_ALLEGRO5'] = True
env.Append(CPPDEFINES = ['USE_ALLEGRO5'])
else:
config.CheckAllegro5()
config.CheckFreetype()
config.CheckCXX11()
config.ConfigChecks()
env = config.Finish()
-if not env['HAVE_ALLEGRO5']:
+if not env['HAVE_ALLEGRO5'] or not env['HAVE_CXX11']:
Exit(1)
if scons_rtech1.utils.useLLVM():
env['CXX'] = 'clang++'
env['CC'] = 'clang'
if scons_rtech1.checks.debug():
env.Append(CXXFLAGS = ['-g3','-ggdb'])
build_dir = '%s/%s' % (build_dir_root, build_type if not scons_rtech1.checks.debug() else 'debug')
options = {'networking': False,
'allegro5': True
}
def getLibName():
if scons_rtech1.utils.useAndroid():
return 'lib/r-tech1-arm'
if scons_rtech1.checks.debug():
return 'lib/r-tech1-debug'
return 'lib/r-tech1'
libname = getLibName()
env.Append(CPPPATH = [Dir('include', Dir('.').rel_path(Dir('#' + root)))])
env.VariantDir(build_dir, 'src')
libs = env.SConscript('src/SConscript', variant_dir=build_dir, exports=['env', 'options', 'root'])
rtech1 = env.StaticLibrary(libname, libs)
Alias('rtech1', rtech1)
-scons_rtech1.utils.cxx11_header(env,build_dir, True if 'HAS_CXX11' in env['CPPDEFINES'] else False)
-
tests_build_dir = os.path.join(build_dir, 'tests')
unit_tests = []
if not scons_rtech1.utils.useAndroid():
unit_tests = SConscript('tests/SConscript', variant_dir = tests_build_dir, exports = ['env', 'rtech1', 'root'], duplicate=0)
env.Depends(unit_tests, rtech1)
if os.access(env.installPrefix, os.W_OK):
installEnv = env.Clone(tools = ['textfile'])
# Install target and configuration
installEnv.Install('{0}/lib'.format(installEnv.installPrefix), rtech1)
header_prefix = '{0}/include/r-tech1'.format(installEnv.installPrefix)
include_dir = 'include/r-tech1'
for root, dirs, files in os.walk(include_dir):
for file in files:
installEnv.Install(header_prefix + root[len(include_dir):], os.path.join(root, file))
installEnv.Install(os.path.join(header_prefix, 'lz4'), 'src/libs/lz4/lz4.h')
# pkg-config file create
pc_mod, pc_install = scons_rtech1.utils.pc_install(installEnv, build_dir, scons_rtech1.checks.debug())
# Install pkg-config file
installEnv.Alias('install', [installEnv.installPrefix, pc_install])
installEnv.Depends([installEnv.installPrefix, pc_mod], rtech1)
# Uninstall target
installEnv.Command("uninstall", None, Delete(FindInstalledFiles()))
else:
def needsudo(target, source, env):
print 'No write priveleges to {0}, run target [{1}] as sudo'.format(env.installPrefix, target[0])
env.Command('install', None, needsudo)
env.Depends('install', ['rtech1', 'tests'])
env.Command('uninstall', None, needsudo)
env.Depends('uninstall', ['rtech1', 'tests'])
include_dir = 'include/r-tech1'
root_dir = Dir('include/r-tech1', Dir('#%s' % root)).abspath
for myroot, dirs, files in os.walk(root_dir):
for file in files:
source = os.path.join(myroot, file)
dir = myroot[len(root_dir) + 1:]
destination = Dir(dir, Dir('headers/r-tech1', Dir(build_dir))).abspath
env['RTECH1_HEADERS'] = [Dir('include', Dir('.').rel_path(Dir('#%s' % root))).abspath]
# Unit tests
env.Alias('tests', unit_tests)
for test in unit_tests:
orig = str(test).translate(None,'[]\'')
to = orig.replace('{0}/tests/'.format(build_dir), '')
#print orig, to
copy = Command('bin/{0}'.format(to), orig, Copy('$TARGET', '$SOURCE'))
env.Depends(copy, test)
env.AlwaysBuild(copy)
env.Alias('tests', copy, copy[0].abspath)
Return('rtech1')
diff --git a/scons_rtech1/checks.py b/scons_rtech1/checks.py
index f14ee798..215c03e6 100644
--- a/scons_rtech1/checks.py
+++ b/scons_rtech1/checks.py
@@ -1,626 +1,629 @@
import utils
rtti_counter = 0
def checkRTTI(context):
global rtti_counter
rtti_counter += 1
context.Message("Checking if we need rtti... ")
tmp = context.env.Clone()
env = context.env
env.Append(CXXFLAGS = ['-fno-rtti'])
ret = context.TryCompile("""
#include <exception>
int main(int argc, char ** argv){
extern void foo();
try{
foo();
} catch (const std::exception & e){
return 1;
}
return 0;
}
""", ".cpp")
s1 = context.lastTarget
ret = context.TryCompile("""
#include <exception>
void foo(){
throw std::exception();
}
""", ".cpp")
s2 = context.lastTarget
result = None
spawn = context.sconf.env['SPAWN']
try:
context.sconf.env['SPAWN'] = context.sconf.pspawn_wrapper
nodes = env.Program(context.sconf.confdir.File('rtti%d' % rtti_counter), [s1,s2])
result = context.sconf.BuildNodes(nodes)
except Exception:
result = False
context.sconf.env['SPAWN'] = spawn
foo = 0
if not result:
context.sconf.env = tmp
foo = 1
context.Result(utils.colorResult(foo))
return foo
def checkAllegro5(debug):
use_debug = [""]
if debug:
use_debug[0] = "-debug"
def make(context):
context.Message("Checking for Allegro 5 ... ")
tmp = context.env.Clone()
env = context.env
def find(version):
context.Message(str(version))
try:
def doParse(libs, env):
def make(name):
return '%s%s-%s' % (name, use_debug[0], version)
libraries = []
for lib in libs:
libraries.append(make(lib))
try:
utils.safeParseConfig(env, 'pkg-config %s --cflags --libs' % ' '.join(libraries))
env.Append(CPPDEFINES = ['USE_ALLEGRO5'])
context.Message('found version {0} [{1}]'.format(version, 'Monolithic' if len(libraries) == 1 else 'Non-monolithic'))
except Exception, e:
raise e
return libraries
libraries = []
try:
libs = ['allegro_monolith']
libraries = doParse(libs, env)
except Exception, e:
libs = ['allegro',
'allegro_ttf',
'allegro_memfile',
'allegro_image',
'allegro_primitives',
'allegro_audio',
'allegro_acodec'
]
libraries = doParse(libs, env)
#env.allegro5 = libraries
return True
except Exception, e:
print e
return False
failure = None
try:
ok = 0
if find(5):
ok = 1
else:
failure = "Install Allegro5 version 5.1 or greater. http://liballeg.org"
ok = 0
raise Exception()
ok = context.TryCompile("""
#include <allegro5/allegro.h>
#if defined(ALLEGRO_VERSION) && defined(ALLEGRO_SUB_VERSION) && ALLEGRO_VERSION == 5 && ALLEGRO_SUB_VERSION >= 1
#else
#error fail
#endif
int main(int argc, char ** argv){
}
""", ".cpp")
if ok == 0:
failure = "Allegro5 version is too old. Install 5.1 or greater"
raise Exception()
ok = 1
except:
context.sconf.env = tmp
context.Result(utils.colorResult(ok))
if failure != None:
context.sconf.env['HAVE_ALLEGRO5'] = False
print failure
else:
context.sconf.env['HAVE_ALLEGRO5'] = True
return ok
return make
def checkSDL(context):
context.Message("Checking for SDL ... ")
def build(x):
return context.TryLink("""
#include <SDL.h>
int main(int argc, char ** argv){
int %sok = SDL_INIT_VIDEO;
return SDL_Init(0);
}
""" % x, ".c")
def tryNormal():
tmp = context.env.Clone()
env = context.env
try:
utils.safeParseConfig(env, 'sdl-config --cflags --libs')
env.Append(CPPDEFINES = ['USE_SDL'])
if build('a'):
return True
else:
raise Exception()
except Exception:
context.sconf.env = tmp
return False
# Put any system libraries after SDL
def tryMoveLibs():
tmp = context.env.Clone()
env = context.env
try:
libs = []
try:
libs = env['LIBS']
except KeyError:
pass
env.Replace(LIBS = [])
utils.safeParseConfig(env, 'sdl-config --cflags --libs')
env.Append(LIBS = libs)
env.Append(CPPDEFINES = ['USE_SDL'])
m = build('b')
if m:
return True
else:
raise Exception("Couldn't build it")
except Exception, e:
# print "Moving libraries failed! because '%s'" % e
context.sconf.env = tmp
return False
def tryFramework():
tmp = context.env.Clone()
env = context.env
env.Append(FRAMEWORKS = ['SDL', 'Cocoa'])
env.Append(CPPDEFINES = ['USE_SDL'])
env.Append(CPPPATH = ['/Library/Frameworks/SDL.framework/Headers',
'/System/Library/Frameworks/Foundation.framework/Headers'])
main = env.StaticLibrary('src/util/graphics/sdl/SDLMain.m')
env.Append(LIBS = [main])
m = build('c')
if m:
return True
else:
context.sconf.env = tmp
return False
ok = int(tryNormal() or tryMoveLibs() or tryFramework())
context.Result(utils.colorResult(ok))
return ok
def checkSDLMain(context):
context.Message("Checking for SDL main... ")
tmp = context.env.Clone()
env = context.env
env['HAVE_SDL_MAIN'] = False
ok = False
if utils.useAndroid():
ok = True
else:
ok = context.TryLink("""
#include <SDL.h>
int SDL_main(int argc, char ** argv){
return 0;
}
""", ".c")
if not ok:
context.sconf.env = tmp
else:
env.Append(CPPDEFINES = ['USE_SDL_MAIN'])
env['HAVE_SDL_MAIN'] = True
context.Result(utils.colorResult(ok))
return ok
def checkStaticSDL(context):
context.Message("Checking for static SDL... ")
env = context.env
try:
utils.safeParseConfig(env, 'sdl-config --static-libs --cflags')
env.Append(CPPDEFINES = ['USE_SDL'])
except Exception:
context.Result(utils.colorResult(0))
return 0
if False:
sdl = env.Install('misc', readExec('sdl-config --prefix') + '/lib/libSDL.a')
env.Append(LIBS = [sdl])
utils.safeParseConfig(env, 'sdl-config --cflags')
env.Append(CPPDEFINES = ['USE_SDL'])
if isOSX() or isOSX104():
def framework(x):
return "-framework %s" % x
frameworks = Split("""
Cocoa
Carbon
IOKit
System
CoreAudio
AudioUnit
AudioToolbox
QuickTime
OpenGL
""")
# env.Append(LINKFLAGS = map(framework, frameworks))
env.Append(FRAMEWORKS = frameworks)
context.Result(utils.colorResult(1))
return 1
def checkMpg123(context):
context.Message("Checking for libmpg123... ")
tmp = context.env.Clone()
env = context.env
env['HAVE_MP3_MPG123'] = True
env.Append(CPPDEFINES = ['HAVE_MP3_MPG123'])
(ok, stuff) = context.TryAction(env.Action("pkg-config --version"))
if ok:
try:
utils.safeParseConfig(env,'pkg-config libmpg123 --libs --cflags')
except OSError:
context.sconf.env = tmp
context.Result(utils.colorResult(0))
return 0
ret = context.TryLink("""
#include <mpg123.h>
int main(int argc, char ** argv){
int err = mpg123_init();
if (err == MPG123_OK){
return 0;
}
return 1;
}
""", ".c")
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
# Alternatively use libmad if mpg123 is not available
def checkMad(context):
context.Message("Checking for libmad... ")
tmp = context.env.Clone()
env = context.env
env['HAVE_MP3_MAD'] = True
env.Append(CPPDEFINES = ['HAVE_MP3_MAD'])
def tryPkgConfig():
(ok, stuff) = context.TryAction(env.Action("pkg-config --version"))
if ok:
try:
utils.safeParseConfig(env, 'pkg-config mad --libs --cflags')
return True
except OSError:
# context.sconf.env = tmp
# context.Result(utils.colorResult(0))
return False
return False
def tryLib():
env.Append(LIBS = ['mad'])
tryPkgConfig() or tryLib()
ret = context.TryLink("""
#include <mad.h>
int main(int argc, char ** argv){
struct mad_stream stream;
mad_stream_init(&stream);
return 0;
}
""", ".c")
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
def checkPthreads(context):
context.Message("Checking for threads... ")
if utils.useAndroid() or utils.useAndroidX86():
context.Message(" android threads")
context.Result(utils.colorResult(1))
return 1
if utils.useAllegro():
env = context.env
env.Append(LIBS = ['pthread'])
context.Message(" pthreads")
context.Result(utils.colorResult(1))
return 1
if utils.useAllegro5():
env = context.env
env.Append(LIBS = ['pthread'])
context.Message(' pthreads')
context.Result(utils.colorResult(1))
return 1
if utils.useSDL():
# context.Message(" SDL threads")
env = context.env
env.Append(LIBS = ['pthread'])
context.Message(' pthreads')
context.Result(utils.colorResult(1))
return 1
context.Message(" defaulting to pthreads")
context.Result(utils.colorResult(1))
return 1
#if not useWii() and not useMinpspw():
# env.Append(LIBS = [ 'pthread' ])
def checkNativeOgg(context):
context.Message("Checking for ogg and vorbis... ")
tmp = context.env.Clone()
env = context.env
env['HAVE_OGG'] = True
env.Append(CPPDEFINES = ['HAVE_OGG'])
(ok, stuff) = context.TryAction(env.Action("pkg-config --version"))
if ok:
try:
utils.safeParseConfig(env, 'pkg-config vorbisfile --libs --cflags')
except OSError:
context.sconf.env = tmp
context.Result(utils.colorResult(0))
return 0
main = 'int main(int argc, char ** argv)'
try:
if env['HAVE_SDL_MAIN']:
main = 'int SDL_main(int argc, char ** argv)'
except KeyError:
pass
ret = context.TryLink("""
#include <vorbis/vorbisfile.h>
#include <stdio.h>
%(main)s {
OggVorbis_File ovf;
FILE * f;
ov_open_callbacks(f, &ovf, 0, 0, OV_CALLBACKS_DEFAULT);
return 0;
}
""" % {'main' : main}, ".c")
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
def checkPython(context):
import distutils.sysconfig
context.Message("Checking if python is embeddable... ")
include_path = distutils.sysconfig.get_config_var('INCLUDEPY')
link_stuff = distutils.sysconfig.get_config_var('LINKFORSHARED')
# libs = distutils.sysconfig.get_config_var('LDLIBRARY')
libs = distutils.sysconfig.get_config_var('LIBRARY')
lib_path = distutils.sysconfig.get_config_var('LIBP')
# hacks for windows because distutils is broken
if libs == None and utils.isWindows():
libs = ['python26']
if lib_path == None and utils.isWindows():
import os
lib_path = os.path.join(os.path.dirname(include_path),'libs')
# hacks for osx because distutils doesn't quote things
if utils.isOSX() or utils.isOSX104():
import re
f = re.compile('(-framework System Python.framework/Versions/.*/Python)')
link_stuff = re.sub(f, r"'\1'", link_stuff)
tmp = context.env.Clone()
env = context.env
if include_path != None:
env.Append(CPPPATH = [include_path])
if link_stuff != None:
env.Append(LINKFLAGS = link_stuff.split(' '))
if lib_path != None:
env.Append(LIBPATH = [lib_path])
new_libs = []
if libs != None:
new_libs = libs
old_libs = env['LIBS']
env.Replace(LIBS = [new_libs])
env.Append(CPPDEFINES = ['HAVE_PYTHON'])
ret = context.TryLink("""
#include <Python.h>
int main(int argc, char *argv[]) {
Py_Initialize();
return 0;
}
""", ".c");
env.Append(LIBS = old_libs)
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
def rubyConfigVariable(var):
# gets the ruby configuration stuff and expands config variables
import subprocess
code = """
require 'mkmf'
def replace(str)
str.gsub(/\$\(\w+\)/){|x| replace(CONFIG[x[/\w+/]]) }
end
puts replace(CONFIG['%s'])
""" % var
try:
p = subprocess.Popen(["ruby", "-e", code], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
return p.stdout.readline().strip()
except Exception:
return ""
def rubyDir():
return rubyConfigVariable('archdir')
def rubyLib():
return rubyConfigVariable('RUBY_SO_NAME')
def rubyStaticLib():
return rubyConfigVariable('LIBRUBY_A')
def checkRuby(context):
context.Message("Checking if ruby is embeddable... ")
if not canRunRuby(context):
context.Result(utils.colorResult(0))
return 0
tmp = context.env.Clone()
env = context.env
env.Append(CPPDEFINES = ['HAVE_RUBY'])
env.Append(CPPPATH = [rubyDir()])
old_libs = env['LIBS']
env.Replace(LIBS = [rubyLib()])
ret = context.TryLink("""
#include <ruby.h>
int main(int argc, char ** argv){
ruby_init();
return 0;
}
""", ".c")
env.Replace(LIBS = old_libs + [rubyLib()])
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
def checkStaticRuby(context):
context.Message("Checking if ruby is statically embeddable... ")
if not canRunRuby(context):
context.Result(utils.colorResult(0))
return 0
tmp = context.env.Clone()
env = context.env
env.Append(CPPDEFINES = ['HAVE_RUBY'])
env.Append(CPPPATH = [rubyDir()])
old_libs = env['LIBS']
env.Replace(LIBS = [rubyStaticLib(), 'crypt', 'pthread', 'm', 'dl'])
ret = context.TryLink("""
#include <ruby.h>
int main(int argc, char ** argv){
ruby_init();
return 0;
}
""", ".c")
env.Replace(LIBS = old_libs + [rubyLib()])
if not ret:
context.sconf.env = tmp
context.Result(utils.colorResult(ret))
return ret
def canRunRuby(context):
(ok, stuff) = context.TryAction(Action("ruby -v"))
return ok == 1
def checkRunRuby(context):
# just fail for now
context.Result(utils.colorResult(0))
return 0
context.Message("Checking if we can run ruby... ")
(ok, stuff) = context.TryAction(Action("ruby -v"))
context.Result(utils.colorResult(ok))
return ok
def checkFreetype(context):
context.Message('Checking for freetype2 ... ')
ok = False
try:
env = context.env
utils.safeParseConfig(env, 'freetype-config --libs --cflags')
context.Message('found')
ok = True
except Exception, ex:
context.Message('Not found, install libfreetype2')
context.Result(utils.colorResult(ok))
return ok
def debug():
try:
import os
return int(os.environ[ 'DEBUG' ])
except KeyError:
return 0
def configChecks(context):
def prefix(env):
# Check install prefix
context.Message('Checking if install prefix set ... ')
ok = False
try:
import os
if os.environ['PREFIX'] == '':
raise KeyError
elif os.environ['PREFIX']:
env.installPrefix = os.environ['PREFIX']
context.Message('set to [{0}]'.format(env.installPrefix))
ok = True
except KeyError:
env.installPrefix = '/usr/local'
context.Message('defaulting to [{0}]'.format(env.installPrefix))
context.Result(utils.colorResult(ok))
env = context.env
prefix(env)
return True
def checkCXX11(context):
context.Message("Checking if cxx11 is supported by the compiler...")
tmp = context.env.Clone()
env = context.env
env.Append(CPPDEFINES = ['HAVE_CXX11'])
env.Append(CXXFLAGS = ['-std=c++11'])
ret = context.TryLink("""
#if __cplusplus <= 199711L
#error Not supported
#endif
int main(int argc, char ** argv){
return 0;
}
""", '.cpp')
if not ret:
+ context.sconf.env['HAVE_CXX11'] = False
context.sconf.env = tmp
+ else:
+ context.sconf.env['HAVE_CXX11'] = True
context.Result(utils.colorResult(ret))
return ret
diff --git a/scons_rtech1/utils.py b/scons_rtech1/utils.py
index 65a90886..855494bf 100644
--- a/scons_rtech1/utils.py
+++ b/scons_rtech1/utils.py
@@ -1,347 +1,337 @@
from SCons.Script import ARGUMENTS, Command, Copy
import os
def noColors():
try:
return int(ARGUMENTS['colors']) == 0
except KeyError:
return False
def xterm_color(string, color):
colors = {'none': "0",
'black': "0;30",
'red': "0;31",
'green': "0;32",
'brown': "0;33",
'blue': "0;34",
'purple': "0;35",
'cyan': "0;36",
'light-gray': "0;37",
'dark-gray': "1:30",
'light-red': "1;31",
'light-green': "1;32",
'yellow': "1;33",
'light-blue': "1;34",
'light-purple': "1;35",
'light-cyan': "1;36",
'white': "1;37"}
return "\033[%sm%s\033[0m" % (colors[color], string)
def isPlatform(platform):
import sys
return platform in sys.platform
def isWindows():
return isPlatform("win32")
def isLinux():
return isPlatform("linux")
def isOSX104():
import platform
return isPlatform("darwin") and platform.processor() == 'powerpc'
# Assume 10.6 and up
def isOSX():
return isPlatform("darwin") and not isOSX104()
# todo: figure out when we are on an xterm
def isXterm():
# assume linux and osx are ok
return not isWindows()
def colorize(string, color):
if noColors():
return string
if isXterm():
return xterm_color(string, color)
return string
def colorResult(what):
if what != 0:
return colorize('yes', 'light-green')
else:
return colorize('no', 'light-red')
def peg_to_cpp(target, source, env):
import sys
sys.path.append("src/mugen/parser")
sys.path.append(".")
import peg, re, cpp_generator
name = source[0].name
parser = peg.make_peg_parser(re.sub('\..*', '', name))
fout = open(target[0].path, 'w')
fout.write(cpp_generator.generate(parser(source[0].path)))
fout.write('\n')
fout.close()
# Build a cpp file from a peg definition
def pegBuilder(environment):
from SCons.Builder import Builder
from SCons.Action import Action
return Builder(action = Action(peg_to_cpp, environment['PEG_MAKE']),
suffix = '.cpp',
src_suffix = '.peg')
def readExec(program):
import os
try:
return os.popen(program).readline().replace("\n",'')
except OSError:
return ""
# Try to execute a script that will produce some compiler flags but fail
# gracefully if the script dies or can't be found
def safeParseConfig(environment, config):
# redirects stderr, not super safe
def version1():
import sys
out = open('fail.log', 'w')
old_stderr = sys.stderr
try:
sys.stderr = out
environment.ParseConfig(config)
out.close()
sys.stderr = old_stderr
except Exception, e:
out.close()
sys.stderr = old_stderr
raise e
# use the subprocess module to pass the output of stdout directly
# to mergeflags and trash stderr
# Not done yet!! This requires python 2.4
def version2():
import subprocess
process = subprocess.Popen(config.split(' '), stdout = subprocess.PIPE)
# p = subprocess.Popen(["ruby", "-e", code], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out = p.stdout.readline().strip()
environment.MergeFlags(out)
version1()
# Create a function that pulls out some key from the shell environment
def makeUseEnvironment(key, default):
def use():
import os
try:
return int(os.environ[key]) == 1
except KeyError:
return default
return use
def makeUseArgument(key, default):
def use():
try:
return int(ARGUMENTS[key]) == 1
except KeyError:
return default
return use
useGch = makeUseArgument('gch', True)
usePrx = makeUseEnvironment('prx', False)
isVerbose = makeUseArgument('verbose', False)
useIntel = makeUseEnvironment('intel', False)
useMinpspw = makeUseEnvironment('minpspw', False)
useAndroid = makeUseEnvironment('android', False)
useAndroidX86 = makeUseEnvironment('androidx86', False)
useAndroidX64 = makeUseEnvironment('androidx64', False)
useIos = makeUseEnvironment('ios', False)
usePs3 = makeUseEnvironment('ps3', False)
useNDS = makeUseEnvironment('nds', False)
useDingoo = makeUseEnvironment('dingoo', False)
useXenon = makeUseEnvironment('xenon', False)
usePandora = makeUseEnvironment('pandora', False)
useWii = makeUseEnvironment('wii', False)
useNacl = makeUseEnvironment('nacl', False)
useMpg123 = makeUseEnvironment('mpg123', False)
useMad = makeUseEnvironment('mad', False)
useGCW = makeUseEnvironment('gcw', False)
nativeCompile = makeUseEnvironment('native', False)
enableProfiled = makeUseEnvironment('PROFILE', False)
showTiming = makeUseEnvironment('timing', False)
useAllegro4 = makeUseEnvironment('allegro4', False)
useWii = makeUseEnvironment('wii', False)
def useLLVM():
return makeUseEnvironment('llvm', False)
def useAllegro():
def byEnv():
try:
return os.environ['ALLEGRO'] == '1'
except KeyError:
return False
def byArgument():
try:
return int(ARGUMENTS['allegro']) == 1
except KeyError:
return False
return byEnv() or byArgument()
def useAllegro5():
def byEnv():
try:
return os.environ['ALLEGRO5'] == '1'
except KeyError:
return False
def byArgument():
try:
return int(ARGUMENTS['allegro5']) == 1
except KeyError:
return False
# FIXME: hack to specify android here
return byEnv() or byArgument() or useAndroid() or useAndroidX86()
def useSDL():
print "[rtech1] Allegro ", useAllegro(), " Allegro5", useAllegro5()
return not useAllegro() and not useAllegro5()
# Replace standard tool invocations with nice colored text
def lessVerbose(env):
link_color = 'light-red'
ar_color = 'yellow'
ranlib_color = 'light-purple'
peg_color = 'light-cyan'
env['CCCOMSTR'] = "%s %s" % (colorize('Compiling c file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['SHCCCOMSTR'] = "%s %s" % (colorize('Compiling c file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['CXXCOMSTR'] = "%s %s" % (colorize('Compiling c++ file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['SHCXXCOMSTR'] = "%s %s" % (colorize('Compiling c++ file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['LINKCOMSTR'] = "%s %s" % (colorize('Linking', link_color), colorize('$TARGET', 'light-blue'))
env['SHLINKCOMSTR'] = "%s %s" % (colorize('Linking', link_color), colorize('$TARGET', 'light-blue'))
env['ARCOMSTR'] = "%s %s" % (colorize('Building library', ar_color), colorize('$TARGET', 'light-blue'))
env['RANLIBCOMSTR'] = "%s %s" % (colorize('Indexing library', ranlib_color), colorize('$TARGET', 'light-blue'))
env['PEG_MAKE'] = "%s %s" % (colorize('Creating peg parser', peg_color), colorize('$TARGET', 'light-blue'))
return env
def configure_backend(environment, backends, custom_tests):
config = environment.Configure(custom_tests = custom_tests)
if not config.CheckCompiler():
config.Finish()
raise Exception("No c++ compiler found. Install gcc or clang")
class OkBackend(Exception):
pass
class NoBackend(Exception):
pass
try:
for backend in backends:
if backend == 'SDL' and config.CheckSDL():
environment.Append(CPPDEFINES = ['USE_SDL'])
environment['PAINTOWN_BACKEND'] = 'sdl'
environment.Append(PAINTOWN_PLATFORM = ['sdl'])
raise OkBackend()
if backend == 'Allegro4' and config.CheckAllegro4():
environment.Append(CPPDEFINES = ['USE_ALLEGRO'])
environment['PAINTOWN_BACKEND'] = 'allegro4'
environment.Append(PAINTOWN_PLATFORM = ['allegro4'])
raise OkBackend()
if backend == 'Allegro5' and config.CheckAllegro5():
environment.Append(CPPDEFINES = ['USE_ALLEGRO5'])
environment['PAINTOWN_BACKEND'] = 'allegro5'
environment.Append(PAINTOWN_PLATFORM = ['allegro5'])
raise OkBackend()
config.Finish()
raise NoBackend()
except OkBackend:
pass
return config.Finish()
def checkCompiler(context):
context.Message("Checking for a compiler (%s) ... " % context.env['CXX'])
ok = context.TryCompile("""
int main(int argc, char ** argv){
return 0;
}
""", ".cpp")
context.Result(colorResult(ok))
return ok
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
def less_verbose(env):
link_color = 'light-red'
ar_color = 'yellow'
ranlib_color = 'light-purple'
peg_color = 'light-cyan'
env['CCCOMSTR'] = "%s %s" % (colorize('Compiling c file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['SHCCCOMSTR'] = "%s %s" % (colorize('Compiling c file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['CXXCOMSTR'] = "%s %s" % (colorize('Compiling c++ file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['SHCXXCOMSTR'] = "%s %s" % (colorize('Compiling c++ file', 'light-green'), colorize('$SOURCE', 'light-blue'))
env['LINKCOMSTR'] = "%s %s" % (colorize('Linking', link_color), colorize('$TARGET', 'light-blue'))
env['SHLINKCOMSTR'] = "%s %s" % (colorize('Linking', link_color), colorize('$TARGET', 'light-blue'))
env['ARCOMSTR'] = "%s %s" % (colorize('Building library', ar_color), colorize('$TARGET', 'light-blue'))
env['RANLIBCOMSTR'] = "%s %s" % (colorize('Indexing library', ranlib_color), colorize('$TARGET', 'light-blue'))
env['PEG_MAKE'] = "%s %s" % (colorize('Creating peg parser', peg_color), colorize('$TARGET', 'light-blue'))
return env
-def cxx11_header(env, build_dir, has_cxx11):
-# definitions = {
-# '%has_cxx11%': '1' if has_cxx11 else '0'
-# }
-# copy = env.Command(build_dir + '/include/r-tech1/defines.h', 'misc/defines.h.in', Copy('$TARGET', '$SOURCE'))
-# defines = env.Substfile(build_dir + '/include/r-tech1/defines.h', SUBST_DICT = definitions)
-# env.AlwaysBuild(copy)
-# env.Depends(copy, 'rtech1')
- pass
-
def pc_install(installEnv, build_dir, debug):
# allegro 5 libs
def libs(debug):
libs = ['allegro',
'allegro_ttf',
'allegro_memfile',
'allegro_image',
'allegro_primitives',
'allegro_audio',
'allegro_acodec'
]
return ['{0}{1}-5'.format(lib, '-debug' if debug else '', ) for lib in libs]
# PC script
replacelist = {
'%lib%': 'r-tech1' if not debug else 'r-tech1-debug',
'%prefix%': installEnv.installPrefix,
'%rtech1_version%': '1',
'%libs%': ' '.join(libs(debug)) + ' freetype2 zlib',
}
def script(name):
pc_install = '{0}/lib/pkgconfig/{1}.pc'.format(installEnv.installPrefix, name)
pc_copied = Command(build_dir + '/temp.pc.in', 'misc/r-tech1.pc.in'.format(name), Copy('$TARGET', '$SOURCE'))
print installEnv
pc_script = installEnv.Substfile(build_dir + '/temp.pc.in', SUBST_DICT = replacelist)
installEnv.Depends(pc_script, pc_copied)
pc_mod = Command(build_dir + '/{0}.pc'.format(name), build_dir + '/temp.pc', Copy('$TARGET', '$SOURCE'))
installEnv.Depends(pc_mod, pc_script)
installEnv.InstallAs(pc_install, pc_mod)
return pc_mod, pc_install
return script('r-tech1') if not debug else script('r-tech1-debug')
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:31 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72314
Default Alt Text
(35 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline