add flag to disable debug mode
[rofl0r-df-libgraphics.git] / g_src / SConscript
blob4e24e4ecaedc6783476623cf7078e2b87664ebf4
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 profile = False
18 clang = False
20 libgraphics = True
21 tetris = False
23 M64 = False if libgraphics else True
25 # Propagate PATH. We'll just take our chances with non-repeatable builds.
26 env = Environment(ENV = {'PATH' : os.environ['PATH']})
27 env['LINKFLAGS'] = []
28 env['CCFLAGS'] = []
29 env['CPPPATH'] = []
30 env['LIBPATH'] = []
31 env['LIBS'] = []
33 if clang:
34    env["STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME"]=True
35    env['CC']="clang"
36    env['CXX']="clang++"
37    env['CXXCOM']="$CXX -o $TARGET -emit-llvm -pipe -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
38    env['CCCOM']="$CC -o $TARGET -emit-llvm -pipe -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
39    env['SHCCCOM']=env['CCCOM']
40    env['SHCXXCOM']=env['CXXCOM']
41    env["OBJSUFFIX"]=".bc"
42    env["SHOBJSUFFIX"]=".so.bc"
43    env["ARCOM"]="llvm-link $SOURCES -o $TARGET"
44    env["RANLIBCOM"]="true"
45    if optimize:
46       env["SHLINKCOM"]="llvm-link $SOURCES | opt -disable-internalize -std-link-opts | llc -O3 | g++ -shared -xassembler - -o $TARGET $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
47       env["LINKCOM"]="llvm-link $SOURCES | opt -disable-internalize -std-link-opts | llc -O3 | g++ -xassembler -o $TARGET - $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
48    else:
49       env["SHLINKCOM"]="llvm-link $SOURCES | llc | g++ -shared -xassembler -fPIC -o $TARGET - $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
50       env["LINKCOM"]="llvm-link $SOURCES | llc | g++ -xassembler -o $TARGET - $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS"
51 else:
52    env.Replace(CXX = os.environ.get("CXX") or "g++")
54 conf = Configure(env)
55 if not conf.CheckCXX():
56         print('error: no working C++ compiler detected.')
57         Exit(1)
59 disabledebug = ARGUMENTS.get('disable-debug', 0)
60 if int(disabledebug):
61     debug = False
62 else:
63     debug = True
66 disablegtk = ARGUMENTS.get('disable-gtk', 0)
67 if not int(disablegtk):
68    try:
69       conf.env.ParseConfig('pkg-config gtk+-2.0 --cflags --libs')
70       env['CCFLAGS'].append('-DHAVE_GTK2')
71    except OSError,e:
72       print 'gtk+-2.0 not found!'
74 disablecurses = ARGUMENTS.get('disable-curses', 0)
75 if not int(disablecurses):
76    # ncurses has a plethora of different configs, but does not offer pkg-config support
77    have_ncursesw =  conf.CheckLib('ncursesw')
78    have_ncursesw_curses_h = conf.CheckCHeader('ncursesw/curses.h')
79    have_ncurses = conf.CheckCHeader('ncurses.h') and conf.CheckLib('ncurses')
80    if have_ncurses or have_ncursesw:
81       conf.env['CCFLAGS'].append('-DCURSES')
82    else:
83       print('ncurses not found')
84    if have_ncursesw:
85       env['LINKFLAGS'].append('-lncursesw')
86       env['CCFLAGS'].append('-DHAVE_NCURSESW')
87    elif have_ncurses:
88       env['LINKFLAGS'].append('-lncurses')
89    if have_ncursesw_curses_h:
90       env['CCFLAGS'].append('-DHAVE_NCURSESW_CURSES_H')
92 disablegl = ARGUMENTS.get('disable-gl', 0)
93 if not int(disablegl):
94    try:
95       env.ParseConfig('pkg-config glu --cflags --libs')
96       env["CCFLAGS"].append('-DWANT_GL')
97    except OSError,e:
98       print 'glu not found, disabling GL'
100 #env = conf.Finish()
101 conf.Finish()
103 # Init variables, and make sure they're around for appending to
104 # These variables are the ones used by the actual compilation. We construct
105 # them from ccflags/libs in varying ways depending on which compiler is used,
106 # below.
107 env['CPPPATH'].append(["#g_src/fmodexinclude"])
108 env['CCFLAGS'].append("-Dunix")
109 env['CXXFLAGS'].append("-std=gnu++0x")
110 env['LIBS'].append(["SDL_image","z","SDL_ttf"])
111 # If there's a library in the libs folder it will get linked over a system one.
112 env['LIBPATH'].append(["#libs"])
113 if not M64:
114    env['LIBPATH'].append("/usr/lib32")
115 env['LINKFLAGS'].append("-Wl,--as-needed")
116 #env['LINKFLAGS'].append('-Wl,-rpath=\$$ORIGIN/libs')
118 # GLEW
119 env["CPPPATH"].append('#g_src/glext')
120 env["CCFLAGS"].append('-DGLEW_STATIC') # Should only be needed on windows, but can't hurt.
122 # Generic unix, including Linux
123 if not clang and not M64:
124    env['ASFLAGS']="--32"
125    env['LINKFLAGS'].append("-m32")
126    env["CCFLAGS"].append("-m32")
128 env.ParseConfig('pkg-config openal --cflags')
129 env.ParseConfig('pkg-config sndfile --cflags')
130 env.ParseConfig('pkg-config sdl --cflags --libs')
132 ldflags=Split(os.environ.get("LDFLAGS"))
133 env['LINKFLAGS'].append(ldflags)
135 if profile:
136    env["CCFLAGS"].append("-pg")
137    env['LINKFLAGS'].append("-pg")
139 if optimize:
140    if not clang:
141       if not debug:
142          env["CCFLAGS"]+=["-fomit-frame-pointer"]
143       if not M64:
144          env["CCFLAGS"]+=["-O3","-march=pentium3","-mfpmath=sse"]
145       else:
146          env["CCFLAGS"]+=["-O3"]
147    else:
148       env["CCFLAGS"].append("-O2") # Only to reduce WPO time
150 if debug:
151    env["CCFLAGS"].append("-ggdb")
152    env["CCFLAGS"].append("-DDEBUG")
153    
154 # Finally, do the build
155 if libgraphics:
156    env.SharedLibrary(dll, src_dll)
158 if tetris:
159    env.Program("#tetris", src_dll + ["tetris.cpp"])