Bug 456: Avoid hurting Tux in a ravine.
[supertux.git] / SConscript
1 #  SuperTux
2 #  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
3 #
4 #  This program is free software: you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation, either version 3 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program.  If not, see <http:#www.gnu.org/licenses/>.
16
17
18 development_cxx_flags =["-O2", "-g3",
19                         "-ansi",
20                         "-pedantic",
21                         "-Wall",
22                         "-Wextra",
23                         "-Wnon-virtual-dtor",
24                         "-Weffc++",
25                         # "-Wconversion",
26                         "-Werror",
27                         # "-Wshadow",
28                         "-Wcast-qual",
29                         "-Winit-self", # only works with >= -O1
30                         "-Wno-unused-parameter"]
31
32 class Project:
33     def __init__(self):
34         self.build_squirrel()
35         self.build_tinygettext()
36         self.build_binreloc()
37         self.build_findlocale()
38         self.build_miniswig()
39         self.build_supertux()
40         self.build_tests()
41         
42     def build_tinygettext(self):
43         env = Environment(CPPPATH=[".", "src"])
44         env.ParseConfig("sdl-config --libs --cflags")
45         self.libtinygettext = env.StaticLibrary("tinygettext", Glob("external/tinygettext/tinygettext/*.cpp"))
46
47     def build_binreloc(self):
48         env = Environment(CPPPATH=["external/binreloc/", "."])
49         self.libbinreloc = env.StaticLibrary("binreloc", "external/binreloc/binreloc.c")
50
51     def build_findlocale(self):
52         env = Environment(CPPPATH=["external/findlocale/", "."])
53         self.libfindlocale = env.StaticLibrary("findlocale", "external/findlocale/findlocale.c")
54
55     def build_squirrel(self):
56         env = Environment(CPPPATH=["external/squirrel/include/"])
57         self.libsquirrel = env.StaticLibrary("squirrel",
58                                              Glob("external/squirrel/squirrel/*.cpp") +
59                                              Glob("external/squirrel/sqstdlib/*.cpp") +
60                                              Glob("external/squirrel/sqstdlib/*.c"))
61
62     def build_miniswig(self):
63         cxx_flags = development_cxx_flags[:]
64         cxx_flags.remove("-Werror")
65         env = Environment(CXXFLAGS=cxx_flags, CPPPATH=[".", "tools/miniswig/"])
66         miniswig_bin = env.Program('miniswig',
67                                    ['tools/miniswig/parser.yy',
68                                     'tools/miniswig/lexer.ll',
69                                     'tools/miniswig/create_docu.cpp',
70                                     'tools/miniswig/xmlwriter.cpp',
71                                     'tools/miniswig/create_wrapper.cpp',
72                                     'tools/miniswig/main.cpp',
73                                     'tools/miniswig/tree.cpp'])
74
75         env.Append(MINISWIG=miniswig_bin)
76         env.Depends(env.Command('src/scripting/miniswig.tmp',
77                                 'src/scripting/wrapper.interface.hpp',
78                                 ["$CXX -E -Isrc/ -x c -CC $SOURCE -o $TARGET -DSCRIPTING_API"]),
79                     [])
80         
81         env.Depends(env.Command(['src/scripting/wrapper.cpp', 'src/scripting/wrapper.hpp'],
82                                 'src/scripting/miniswig.tmp',
83                                 ["$MINISWIG " +
84                                  "--input $SOURCE " +
85                                  "--output-cpp ${TARGETS[0]} " +
86                                  "--output-hpp ${TARGETS[1]} " +
87                                  "--module supertux " +
88                                  "--select-namespace scripting"]),
89                      miniswig_bin)
90         
91         # g++ -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o miniswig.tmp -Isrc
92         # tools/miniswig/miniswig --input miniswig.tmp \
93         #                         --output-cpp src/scripting/wrapper.cpp \
94         #                         --output-hpp src/scripting/wrapper.hpp \
95         #                         --module supertux \
96         #                         --select-namespace scripting
97         
98     def build_supertux(self):
99         self.env = Environment(CPPPATH=["external/squirrel/include/",
100                                         "external/findlocale/",
101                                         "external/binreloc/",
102                                         "external/obstack/",
103                                         "external/tinygettext/",
104                                         "src/",
105                                         "/usr/include/AL/", # yuck
106                                         "."],
107                                CXXFLAGS=development_cxx_flags)
108
109         # Add libraries
110         self.env.ParseConfig("sdl-config --libs --cflags")
111         self.env.ParseConfig("pkg-config --libs --cflags openal")
112         self.env.ParseConfig("pkg-config --libs --cflags vorbis vorbisfile ogg")
113         self.env.Append(LIBS=[self.libsquirrel, self.libbinreloc, self.libtinygettext, self.libfindlocale])
114         self.env.Append(LIBS=["SDL_image", "curl", "GL", "GLEW", "physfs"])
115
116         # Create config.h
117         self.iconv_const = 0
118         config_h = open('config.h', 'w')
119         config_h.write('#define PACKAGE_NAME "supertux2"\n')
120         config_h.write('#define PACKAGE_VERSION "Milestone 2"\n')
121         config_h.write('#define ENABLE_BINRELOC 1\n')
122         config_h.write('#define INSTALL_SUBDIR_BIN "games/"\n')
123         config_h.write('#define INSTALL_SUBDIR_SHARE "share/games/supertux2/"\n')
124         config_h.write('#define HAVE_LIBCURL 1\n')
125         config_h.write('#define HAVE_OPENGL 1\n')
126         config_h.write('#define ICONV_CONST %s\n' % self.iconv_const)
127         config_h.close()
128
129         version_h = open('version.h', 'w')
130         version_h.close()
131
132         # base source
133         supertux_sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/supertux/menu/*.cpp")
134
135         # optional video drivers
136         supertux_sources += Glob("src/video/gl/*.cpp")
137         supertux_sources += Glob("src/video/sdl/*.cpp")
138
139         self.libsupertux = self.env.StaticLibrary("supertux", supertux_sources)
140         self.env.Program("supertux", ["src/main.cpp", self.libsupertux])
141
142     def build_tests(self):
143         for filename in Glob("test/*_test.cpp", strings=True):
144             self.env.Program(filename[:-4], [filename, self.libsupertux])
145
146 project = Project()
147
148 # EOF #