ocarina/Sconstruct

115 lines
3.1 KiB
Python

#!/usr/bin/python
import os, sys
MAJOR = 5
MINOR = 6
BUG = 1
EXTRA = ""
DEBUG = False
PREFIX = "/usr"
POSTFIX = ""
DESTDIR = ""
for argv in sys.argv:
split = argv.split("=")
if split[0] == "DESTDIR":
DESTDIR = split[1] + "/"
FLAGS = ["-O2"]
if DEBUG == True:
FLAGS = ["-Wall", "-Werror", "-g", "-DDEBUG"]
POSTFIX = "-debug"
env = Environment(CCFLAGS = FLAGS)
if ARGUMENTS.get('VERBOSE') != "1":
env.Append(CXXCOMSTR = "CXX $TARGET")
env.Append(LINKCOMSTR = "Linking $TARGET")
env.Append(CPPPATH = "include")
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
env.ParseConfig('pkg-config --cflags --libs gstreamer-0.10')
env.ParseConfig('pkg-config --cflags --libs gstreamer-interfaces-0.10')
env.ParseConfig('pkg-config --cflags --libs taglib')
def version_h(target, source, env):
f = open("include/version.h", "w")
for line in open("include/version.tmpl", "r"):
line = line.replace("__MAJOR__", str(MAJOR))
line = line.replace("__MINOR__", str(MINOR))
line = line.replace("__BUG__", str(BUG))
line = line.replace("__EXTRA__", str(EXTRA))
f.write(line)
f.close()
def list_dirs(directory):
import os
dirs = [x[0] for x in os.walk(directory)]
return [Glob(dir + "/*.cpp") for dir in dirs]
# Note: a version.h file is not created in this directory,
# so the command will always run.
version_h=env.Command("version.h", None, version_h)
ocarina=env.Program('ocarina.bin', list_dirs('libsaria') + list_dirs('ocarina'))
Default([version_h, ocarina])
tests=os.listdir("tests/")
test_list = []
for test in tests:
if test[0] == ".":
continue;
split = test.rsplit(".", 1);
src = "tests/" + test
dst = "test_" + split[0]
test_list.append(env.Program(dst, list_dirs('libsaria') + [src]))
env.Alias("tests", [version_h] + [test_list]);
# Install Ocarina
scripts = os.listdir("scripts/")
baselib = PREFIX + "/lib/ocarina" + POSTFIX
lib = DESTDIR + baselib
bin = DESTDIR + PREFIX + "/bin/"
images = lib + "/images"
env.Install(lib, ocarina)
env.Alias("install", [lib, images, bin])
env.Command(images, "./images/", [Copy(images, "./images")])
def process_script(target, source, env):
f = open(target[0].rfile().abspath, "w")
ocarina="ocarina"
saria="saria"
if DEBUG == True:
ocarina = ocarina + "-debug"
saria = saria + "-debug"
for line in open(source[0].rfile().abspath):
line = line.replace("%%BIN%%", baselib + "/ocarina.bin")
line = line.replace("%%OCARINA%%", ocarina)
line = line.replace("%%SARIA%%", saria)
f.write(line)
f.close()
for script in scripts:
if script[0] == ".":
continue
src = "scripts/" + script
dst = bin + script.replace("ocarina", "ocarina" + POSTFIX)
env.Command(dst, src, [process_script, Chmod(dst, 0755)])
# Clean up the build directory
Clean(ocarina, ["include/version.h"])
# Create a tarball
def git_archive(target, source, env):
import os
version = "%s.%s" % (MAJOR, MINOR)
if BUG != 0:
version += ".%s" % BUG
if EXTRA != "":
version += "-%s" % EXTRA
if DEBUG == True:
version += "-debug"
ocarina="ocarina-%s" % version
os.popen("git archive --prefix=%s/ -o %s.tar.gz HEAD" % (ocarina, ocarina))
print "md5sum:", os.popen("md5sum %s.tar.gz" % ocarina).read()
env.Command("archive", None, [git_archive])