scons: make building of GL stuff optional
[rofl0r-df-libgraphics.git] / g_src / SConscript
blob9f1f35b417b41d64553882800f06ef825e2a55e9
1 # -*- mode: python -*-
2 from sys import platform
3 import os
5 src_dll = ["basics.cpp","command_line.cpp","enabler.cpp","files.cpp",
6            "find_files_posix.cpp","graphics.cpp","init.cpp","interface.cpp",
7            "keybindings.cpp","music_and_sound_openal.cpp", "random.cpp",
8            "textlines.cpp","glew.c","enabler_input.cpp","ViewBase.cpp",
9            "KeybindingScreen.cpp", "win32_compat.cpp", "textures.cpp",
10            "resize++.cpp", "renderer_offscreen.cpp",
11            "ttf_manager.cpp"]
13 dll  = '#libs/libgraphics.so'
15 optimize = False
16 debug = True
17 profile = False
19 clang = False
21 libgraphics = True
22 tetris = False
24 M64 = False if libgraphics else True
26 # Propagate PATH. We'll just take our chances with non-repeatable builds.
27 env = Environment(ENV = {'PATH' : os.environ['PATH']})
29 if clang:
30    env["STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME"]=True
31    env['CC']="clang"
32    env['CXX']="clang++"
33    env['CXXCOM']="$CXX -o $TARGET -emit-llvm -pipe -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
34    env['CCCOM']="$CC -o $TARGET -emit-llvm -pipe -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
35    env['SHCCCOM']=env['CCCOM']
36    env['SHCXXCOM']=env['CXXCOM']
37    env["OBJSUFFIX"]=".bc"
38    env["SHOBJSUFFIX"]=".so.bc"
39    env["ARCOM"]="llvm-link $SOURCES -o $TARGET"
40    env["RANLIBCOM"]="true"
41    if optimize:
42       env["SHLINKCOM"]="llvm-link $SOURCES | opt -disable-internalize -std-link-opts | llc -O3 | g++ -shared -xassembler - -o $TARGET $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
43       env["LINKCOM"]="llvm-link $SOURCES | opt -disable-internalize -std-link-opts | llc -O3 | g++ -xassembler -o $TARGET - $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
44    else:
45       env["SHLINKCOM"]="llvm-link $SOURCES | llc | g++ -shared -xassembler -fPIC -o $TARGET - $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
46       env["LINKCOM"]="llvm-link $SOURCES | llc | g++ -xassembler -o $TARGET - $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
49 # Init variables, and make sure they're around for appending to
50 # These variables are the ones used by the actual compilation. We construct
51 # them from ccflags/libs in varying ways depending on which compiler is used,
52 # below.
53 env['CPPPATH']=["#g_src/fmodexinclude"]
54 env['CCFLAGS']=["-Dunix"]
55 env['CXXFLAGS'].append("-std=gnu++0x")
56 env['LIBS']=["SDL_image","z","SDL_ttf"]
57 # If there's a library in the libs folder it will get linked over a system one.
58 env['LIBPATH']=["#libs"]
59 if not M64:
60    env['LIBPATH'].append("/usr/lib32")
61 env['LINKFLAGS']=["-Wl,--as-needed"]
62 #env['LINKFLAGS'].append('-Wl,-rpath=\$$ORIGIN/libs')
64 # GLEW
65 env["CPPPATH"].append('#g_src/glext')
66 env["CCFLAGS"].append('-DGLEW_STATIC') # Should only be needed on windows, but can't hurt.
68 # Generic unix, including Linux
69 if not clang and not M64:
70    env['ASFLAGS']="--32"
71    env['LINKFLAGS'].append("-m32")
72    env["CCFLAGS"].append("-m32")
73 try:
74    env.ParseConfig('pkg-config gtk+-2.0 --cflags --libs')
75    env.Append(CPPFLAGS = '-DHAVE_GTK2')
76 except OSError,e:
77    print 'gtk+-2.0 not found!'
79 env.ParseConfig('pkg-config openal --cflags')
80 env.ParseConfig('pkg-config sndfile --cflags')
81 env.ParseConfig('pkg-config sdl --cflags --libs')
82 try:
83    env.ParseConfig('pkg-config glu --cflags --libs')
84    env.Append(CPPFLAGS = '-DWANT_GL')
85 except OSError,e:
86    print 'glu not found, disabling GL'
89 if profile:
90    env["CCFLAGS"].append("-pg")
91    env['LINKFLAGS'].append("-pg")
93 if optimize:
94    if not clang:
95       if not debug:
96          env["CCFLAGS"]+=["-fomit-frame-pointer"]
97       if not M64:
98          env["CCFLAGS"]+=["-O3","-march=pentium3","-mfpmath=sse"]
99       else:
100          env["CCFLAGS"]+=["-O3"]
101    else:
102       env["CCFLAGS"].append("-O2") # Only to reduce WPO time
104 if debug:
105    env["CCFLAGS"].append("-ggdb")
106    env["CCFLAGS"].append("-DDEBUG")
107    
108 # Finally, do the build
109 if libgraphics:
110    env.SharedLibrary(dll, src_dll)
112 if tetris:
113    env.Program("#tetris", src_dll + ["tetris.cpp"])