File: SConscript

package info (click to toggle)
pingus 0.7.6-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 31,636 kB
  • sloc: cpp: 42,076; xml: 2,319; lisp: 521; ruby: 455; ansic: 365; objc: 248; sh: 247; makefile: 143; python: 15
file content (279 lines) | stat: -rw-r--r-- 13,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
##  -*- python -*-
##  Pingus - A free Lemmings clone
##  Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>,
##                     Francois Beerten
##
##  This program is free software; you can redistribute it and/or
##  modify it under the terms of the GNU General Public License
##  as published by the Free Software Foundation; either version 2
##  of the License, or (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

import sys, os
import SCons.Util

Import('package_version')

def CheckSDLLib(context, sdllib):
    """
    On some platforms, SDL does this ugly redefine-main thing, that can
    interact badly with CheckLibWithHeader.
    """
    lib = "SDL_%s" % sdllib
    context.Message('Checking for %s...' % lib)
    text = """
#include "SDL.h"
#include "%s.h"
int main(int argc, char* argv[]) { return 0; }
""" % lib
    context.AppendLIBS(lib)
    if context.BuildProg(text, ".cpp"):
        context.Result("failed")
        return False
    else:
        context.Result("ok")
        return True

def CheckIconv(context):
    context.Message('Check how to call iconv...')
    text = """
#include <iconv.h>
int main() {
   %s char *foo;
   (void)iconv(static_cast<iconv_t>(0), &foo, static_cast<size_t*>(0), static_cast<char**>(0), static_cast<size_t*>(0));
   return 0;
}
"""
    # self.conf.CheckLibWithHeader(context, 'iconv', 'iconv.h', 'c++') # Ok to fail
    for i in ['', 'const']:
        if context.TryCompile(text % i, ".cpp"):
            context.Result("use '%s'" % i)
            return i
    context.Result("failed")
    return False

def CheckMyProgram(context, prgn):
    context.Message('Checking for %s...' % prgn)
    for i in context.env['ENV']['PATH'].split(":"):
        filename = os.path.join(i, prgn)
        if os.path.exists(filename):
            context.Result(filename)
            return True
    context.Result("failed")
    return False

class Project:
    def configure(self):
        self.configure_begin()
        self.configure_opengl()
        self.configure_linuxevdev()
        self.configure_wiimote()
        self.configure_xinput()
        self.configure_boost()
        self.configure_png()
        self.configure_sdl()
        self.configure_iconv()
        self.configure_end()

    def configure_begin(self):
        self.opts = Variables("custom.py", ARGUMENTS)
        self.opts.Add('BUILD', 'Set the build type', "default")
        self.opts.Add('CC', 'C Compiler', 'gcc')
        self.opts.Add('CXX', 'C++ Compiler', 'g++')
    #   self.opts.Add('debug', 'Build with debugging options', 0)
    #   self.opts.Add('profile', 'Build with profiling support', 0)
    
        self.opts.Add('CPPPATH',    'Additional preprocessor paths', [])
        self.opts.Add('LIBPATH',    'Additional library paths',      [])
        self.opts.Add('CPPFLAGS',   'Additional preprocessor flags', [])
        self.opts.Add('CPPDEFINES', 'defined constants', [])
        self.opts.Add('LIBS',       'Additional libraries', [])
        self.opts.Add('CCFLAGS',    'C Compiler flags', [])
        self.opts.Add('CXXFLAGS',   'C++ Compiler flags', ["-O2", "-s"], converter=SCons.Util.CLVar)
        self.opts.Add('LINKFLAGS',  'Linker Compiler flags', [])

        self.opts.Add(BoolVariable('with_opengl',        'Build with OpenGL support', True))
        self.opts.Add(BoolVariable('with_xinput',        'Build with Xinput support', False))
        self.opts.Add(BoolVariable('with_linuxevdev',    'Build with Linux evdev support',  sys.platform == "linux2"))
        self.opts.Add(BoolVariable('with_wiimote',       'Build with Wiimote support', False))
        self.opts.Add(BoolVariable('ignore_errors',      'Ignore any fatal configuration errors', False))
        self.opts.Add('optional_sources', 'Additional source files', [])

        self.env = Environment(options = self.opts, ENV=os.environ)
        self.env.Append(CXXFLAGS = ["-std=c++0x"])
        self.env.Append(CPPDEFINES = [('VERSION', '"\\"%s\\""' % package_version)])
        self.env.Append(CPPPATH = ['src/'])
        
        Help(self.opts.GenerateHelpText(self.env))
                

        self.conf = self.env.Configure(custom_tests = {
            'CheckMyProgram' : CheckMyProgram,
            'CheckSDLLib': CheckSDLLib,
            'CheckIconv': CheckIconv,
            })
        self.fatal_error = ""
        self.reports = ""

    def configure_end(self):
        self.env = self.conf.Finish()

        print ("Reports:")
        print (self.reports)

        if not self.fatal_error == "":
            print ("Fatal Errors:")
            print (self.fatal_error)
            Exit(1)

    def configure_gxx(self): 
        # FIXME: Seems to require a rather new version of SCons
        ret = self.conf.CheckBuilder(context, None, "C++")
        if ret != "":
            self.reports += "  * C++ Compiler missing: " + ret

    def configure_opengl(self):
        if not self.env['with_opengl']:
            self.reports += "  * OpenGL support: disabled\n"
        else:
            self.reports += "  * OpenGL support: enabled\n"           
            self.conf.env.Append(optional_sources = ['src/engine/display/opengl/opengl_framebuffer_surface_impl.cpp', 
                                                     'src/engine/display/opengl/opengl_framebuffer.cpp' ],
                                 CPPDEFINES = [('HAVE_OPENGL', 1)])
            if sys.platform == "darwin":
                self.conf.env.Append(LINKFLAGS = [ '-framework', 'OpenGL' ])
            else:
                self.conf.env.Append(LIBS = ['GL'])

    def configure_linuxevdev(self):
        if not self.env['with_linuxevdev']:
            self.reports += "  * Linux evdev support: disabled\n"
        else:
            self.reports += "  * Linux evdev support: ok\n"
            self.conf.env.Append(CPPDEFINES = [('HAVE_LINUXEVDEV', 1)])
            self.conf.env.Append(optional_sources = ['src/engine/input/evdev/evdev_driver.cpp',
                                                     'src/engine/input/evdev/evdev_device.cpp'])

    def configure_wiimote(self):
        if not self.env['with_wiimote']:
            self.reports += "  * Wiimote support: disabled\n"        
        elif self.conf.CheckLibWithHeader('cwiid', 'cwiid.h', 'c++'):
            self.reports += "  * Wiimote support: yes\n"
            self.conf.env.Append(CPPDEFINES = [('HAVE_CWIID', 1)])
            self.conf.env.Append(LIBS = ['cwiid'])
            self.conf.env.Append(optional_sources = ['src/engine/input/wiimote/wiimote_driver.cpp',
                                                     'src/engine/input/wiimote/wiimote.cpp'])
        else:
            self.reports += "  * Wiimote support: no (libcwiid or cwiid.h not found)\n"

    def configure_xinput(self):
        if not self.env['with_xinput']:
            self.reports += "  * XInput support: disabled\n"
        elif not self.conf.CheckLibWithHeader('Xi', 'X11/extensions/XInput.h', 'c++'):
            self.reports += "  * XInput support: no (library Xi not found)\n" ## FIXME: Need to set a define
        else:
            self.reports += "  * XInput support: yes\n"
            self.conf.env.Append(CPPDEFINES = [('HAVE_XINPUT', 1)])
            self.conf.env.Append(LIBS = ['Xi'])
            self.conf.env.Append(optional_sources = ['src/engine/input/xinput/xinput_driver.cpp',
                                                     'src/engine/input/xinput/xinput_device.cpp'])
            
    def configure_boost(self):
        if not self.conf.CheckHeader('boost/signals2.hpp', '<>', 'c++'):
            self.fatal_error += "  * library 'boost_signals2' not found\n"

    def configure_png(self):
        if self.conf.CheckMyProgram('pkg-config'):
            self.conf.env.ParseConfig("pkg-config  --cflags --libs libpng | sed 's/-I/-isystem/g'")
        else:
            if not self.conf.CheckLibWithHeader('png', 'png.h', 'c++'):
                self.fatal_error += "  * library 'png' not found\n"

    def configure_sdl(self):
        if self.conf.CheckMyProgram('sdl-config'):
            self.conf.env.ParseConfig("sdl-config  --cflags --libs | sed 's/-I/-isystem/g'")
            for sdllib in ['image', 'mixer']:
                if not self.conf.CheckSDLLib(sdllib):
                    self.fatal_error += "  * SDL library '%s' not found\n" % sdllib
        else:
            if sys.platform == 'darwin':
                # self.conf.env.StaticLibrary("sdlmain", ["src/macosx/SDLmain.m"], [ 'SDL' ])
                self.conf.env.Append(optional_sources = [ "src/macosx/SDLmain.m" ])
                self.conf.env.Append(LINKFLAGS = [ '-framework', 'SDL',
                                                   '-framework', 'Cocoa' ],
                                     CPPPATH   = ['/Library/Frameworks/SDL.framework/Headers/'])
                self.conf.env.Append(LINKFLAGS = [ '-framework', 'SDL_image' ],
                                     LIBS = [ 'jpeg' ],
                                     CPPPATH = ['/Library/Frameworks/SDL_image.framework/Headers/'])
                self.conf.env.Append(LINKFLAGS = [ '-framework', 'SDL_mixer',
                                                   # see http://forums.libsdl.org/viewtopic.php?t=5176&sid=72ad0db5b3f2ae62cfb0314adb517d42
                                                   '-dylib_file', '@loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:/Library/Frameworks/SDL_mixer.framework/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod',
                                                   '-dylib_file', '@loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:/Library/Frameworks/SDL_mixer.framework/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg' ],
                                     CPPPATH = ['/Library/Frameworks/SDL_mixer.framework/Headers/'])
            else:
                self.fatal_error += "  * couldn't find sdl-config, SDL missing\n"
                
    def configure_iconv(self):
        iconv_const = self.conf.CheckIconv()
        if iconv_const == False:
            self.fatal_error += "  * can't call iconv\n"
        else:
            self.conf.env.Append(CPPDEFINES = [ 'HAVE_ICONV_CONST', ('ICONV_CONST', iconv_const) ])
        self.conf.CheckLib('iconv')

    def build(self):
        self.env.Append(CPPPATH = ['.', 'src/', 'external/tinygettext/'])

        libpingus = self.env.StaticLibrary('pingus',
                                           Glob('external/tinygettext/tinygettext/*.cpp') + \
                                           Glob('src/editor/*.cpp') + \
                                           Glob('src/engine/display/*.cpp') + \
                                           Glob('src/engine/display/delta/*.cpp') + \
                                           Glob('src/engine/gui/*.cpp') + \
                                           Glob('src/engine/input/*.cpp') + \
                                           Glob('src/engine/resource/*.cpp') + \
                                           Glob('src/engine/screen/*.cpp') + \
                                           Glob('src/engine/sound/*.cpp') + \
                                           Glob('src/engine/system/*.cpp') + \
                                           Glob('src/lisp/*.cpp') + \
                                           Glob('src/math/*.cpp') + \
                                           Glob('src/pingus/*.cpp') + \
                                           Glob('src/pingus/actions/*.cpp') + \
                                           Glob('src/pingus/colliders/*.cpp') + \
                                           Glob('src/pingus/components/*.cpp') + \
                                           Glob('src/pingus/movers/*.cpp') + \
                                           Glob('src/pingus/particles/*.cpp') + \
                                           Glob('src/pingus/screens/*.cpp') + \
                                           Glob('src/pingus/worldmap/*.cpp') + \
                                           Glob('src/pingus/worldobjs/*.cpp') + \
                                           Glob('src/util/*.cpp') + \
                                           self.env['optional_sources'])

        #if sys.platform == "darwin":
        #    self.env.StaticLibrary("sdlmain", ["src/macosx/SDLmain.m"], [ 'SDL' ])

        self.env.Default(self.env.Program('pingus', ['src/main.cpp', libpingus]))

        # build test and utils
        for filename in Glob("test/*_test.cpp", strings=True):
            self.env.Alias('test', self.env.Program(filename[:-4], [filename, libpingus]))
        for filename in Glob("test/*_util.cpp", strings=True):
            self.env.Alias('test', self.env.Program(filename[:-4], [filename, libpingus]))

        # build extra stuff
        for filename in Glob("extra/*.cpp", strings=True):
            self.env.Alias('extra', self.env.Program(filename[:-4], [filename, libpingus]))

project = Project()
project.configure()
project.build()

## EOF ##