# vim:filetype=python import os import re from subprocess import * target = 'anaglym' DEBUG = False Default(target) if 'install_dir' in os.environ: install_dir = os.environ['install_dir'] else: install_dir = os.environ['HOME'] + '/local/' + target if os.sep == '\\': platform = 'PLATFORM_WINDOWS' else: platform = 'PLATFORM_LINUX' subdirs = ['WFObj', 'PhyObj', 'TextureCache', 'OdeWorld'] env = Environment() env.ParseConfig('pkg-config --cflags --libs lua5.1') env.ParseConfig('pkg-config --cflags --libs ftgl') env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('ode-config --cflags --libs') env.ParseConfig('smpeg-config --libs') if platform == 'PLATFORM_WINDOWS': env.Append(LIBS = ['opengl32', 'glu32', 'mingw32']) if platform == 'PLATFORM_LINUX': env.Append(LIBS = ['GL', 'GLU']) env.Append(CPPFLAGS = ['-D'+platform, '-I.']) env.Append(LIBS = ['SDL_image', 'SDL_sound', 'vorbisfile']) env.Append(CCFLAGS = ['-O2', '-Wall']) if DEBUG: env.Append(CCFLAGS = ['-g']) sources = [Glob('src/*.cc'), 'ag_lua.cc', 'sdl_keymap.cc'] for sd in subdirs: sources += [Glob(sd + '/*.c'), Glob(sd + '/*.cc')] def F2C(target, source, env): f = open(str(target[0]), 'w') for s in source: c_name = re.sub(r'\W', '_', str(s).split('/')[-1]) f.write('unsigned char %s[] = {' % c_name) src = open(str(s), 'r') s_len = 0 while 1: if s_len % 12 == 0: f.write('\n ') ch = src.read(1) if len(ch) < 1: break s_len += 1 f.write('0x%02x, ' % ord(ch)) f.write('0x00\n') src.close() f.write('};\n') f.write('unsigned int %s_len = %d;\n' % (c_name, s_len)) f.close() return None def SDLKeymap(target, source, env): Popen(['perl', str(source[0])]).wait() def bt(cmd): return Popen(cmd, shell = True, stdout = PIPE).communicate()[0] env.Append(BUILDERS = {'SDLKeymap' : Builder(action = SDLKeymap)}) env.Append(BUILDERS = {'F2C' : Builder(action = F2C)}) env.F2C('ag_lua.cc', 'src/ag.lua') env.SDLKeymap('sdl_keymap.cc', 'gen-sdl-keymap.pl') env.Program(target, sources) env.Install('dist', target) env.Install('dist', 'lib') env.Install('dist', 'doc') if platform == 'PLATFORM_WINDOWS': env.Install('dist', bt('which SDL.dll')) env.Install('dist', bt('which SDL.dll')) env.Install('dist', bt('which SDL_image.dll')) env.Install('dist', bt('which jpeg.dll')) env.Install('dist', bt('which libpng12-0.dll')) env.Install('dist', bt('which zlib1.dll')) env.Install('dist', bt('which libtiff-3.dll')) env.Install('dist', bt('which libftgl-2.dll')) env.Install('dist', bt('which lua5.1.dll')) env.Install('dist', bt('which freetype6.dll')) env.Install('dist', bt('which libogg-0.dll')) env.Install('dist', bt('which libvorbis-0.dll')) env.Install('dist', bt('which libvorbisfile-3.dll')) env.Clean('dist', 'dist')