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
|
import os
import glob
import sys
import string
import subprocess
################################################################
# Set NetPanzer Version
################################################################
NPVERSION = '0.8.7'
SVERSION = ''
try:
FILE = open('RELEASE_VERSION', 'r')
NPVERSION = FILE.readline().strip(' \n\r')
FILE.close()
except:
pass
try:
SVERSION = os.popen('svnversion').read()[:-1]
SVERSION = SVERSION.split(':')[-1]
except:
pass
print("NPVERSION = " + NPVERSION)
print("SVERSION = " + SVERSION)
if NPVERSION == '' and SVERSION != '':
NPVERSION = 'svn-' + SVERSION;
thisplatform = sys.platform;
print('Building version ' + NPVERSION + ' in ' + thisplatform)
################################################################
# Fix compiling with long lines in windows
################################################################
class ourSpawn:
def ourspawn(self, sh, escape, cmd, args, env):
newargs = string.join(args[1:], ' ')
cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env)
data, err = proc.communicate()
rv = proc.wait()
if rv:
print("=====")
print(err)
print("=====")
return rv
def SetupSpawn( env ):
if sys.platform == 'win32':
buf = ourSpawn()
buf.ourenv = env
env['SPAWN'] = buf.ourspawn
################################################################
# Modified copy from BosWars of globSources
################################################################
def globSources(localenv, sourcePrefix, sourceDirs, pattern):
sources = []
sourceDirs = Split(sourceDirs)
for d in sourceDirs:
sources.append(sorted(glob.glob( sourcePrefix + '/' + d + '/' + pattern)))
sources = Flatten(sources)
targetsources = []
for s in sources:
targetsources.append(buildpath + s)
return targetsources
################################################################
# Make static libraries
################################################################
def MakeStaticLib(localenv, libname, libdirs, pattern):
sources = globSources(localenv, 'src/Lib', libdirs, pattern)
localenv.StaticLibrary( libpath + libname, sources)
################################################################
# Add options
################################################################
opts = Variables()
opts.AddVariables(
EnumVariable('mode', 'set compile mode', 'release', allowed_values=('debug', 'release')),
EnumVariable('cross','do a cross compilation','', allowed_values=('','mingw','linux')),
('datadir','define the extra directory where the netpanzer will look for data files, usefull for linux distributions, defaults to no extra directory',''),
('sdlconfig','sets the sdl-config full path, cross compilation sure needs this', 'sdl-config'),
('universal','builds universal app in Max OS X(default false, other value is true)', 'false'),
('compilerprefix', 'sets the prefix for the cross linux compiler, example: i686-pc-linux-gnu-', ''),
)
env = Environment(ENV = os.environ, options = opts)
Help(opts.GenerateHelpText(env))
env.Append( CCFLAGS = [ '-DPACKAGE_VERSION=\\"' + NPVERSION + '\\"' ] )
if env['datadir'] != '':
env.Append( CCFLAGS = [ '-DNP_DATADIR=\\"' + env['datadir'] + '\\"' ])
buildpath = 'build/'
if env['cross'] != '':
buildpath += env['cross'] + '/'
buildpath += env['mode'] + '/'
libpath = buildpath + 'libs/'
if env['cross'] != '':
binpath = buildpath
else:
binpath = './'
exeappend = ''
if 'CXXFLAGS' in os.environ:
env.Append(CCFLAGS = os.environ['CXXFLAGS'])
if 'CPPFLAGS' in os.environ:
env.Append(CCFLAGS = os.environ['CPPFLAGS'])
if 'LDFLAGS' in os.environ:
env.Append(LINKFLAGS = os.environ['LDFLAGS'])
if env['cross'] == 'mingw':
print('configuring for mingw cross compilation')
env.Tool('crossmingw', toolpath = ['.'])
env.Append( CCFLAGS = [ '-D_WIN32_WINNT=0x0501' ] )
env.Append( LDFLAGS = [ '-mwindows' ] )
env.Append( LIBS = [ 'ws2_32', 'mingw32' ] )
env['WINICON'] = env.RES( 'support/icon/npicon.rc' )
env.Append( LINKFLAGS = [ '-static-libgcc' ] )
if env['mode'] == 'debug':
env.Append(CCFLAGS = ['-g', '-O0'])
#exeappend = '-debug'
else:
if env['cross'] == 'mingw':
# it seems -O2 makes the mingw port to crash, use -O1
env.Append(CCFLAGS = '-O1')
else:
env.Append(CCFLAGS = '-O2')
env.Append(CCFLAGS = '-s')
# if needed to built static...
#env.Append( LINKFLAGS = [ '-static-libgcc', '-static-libstdc++' ] )
env.Append(CCFLAGS = ['-Wall'])
# keep for reference for when redoing the linux cross compilation
# crosslinuxenv= Environment(ENV = {'PATH' : os.environ['PATH']},tools = ['gcc','g++','ar','gnulink'], options=opts )
# crosslinuxenv.Replace( CXX = env['crosslinuxcompilerprefix'] + env['CXX'] )
# crosslinuxenv.Replace( CC = env['crosslinuxcompilerprefix'] + env['CC'] )
# crosslinuxenv.Replace( AR = env['crosslinuxcompilerprefix'] + env['AR'] )
# crosslinuxenv.Replace( RANLIB = env['crosslinuxcompilerprefix'] + env['RANLIB'] )
# crosslinuxenv.Append( LINKFLAGS = [ '-static-libgcc' ] )
# #crosslinuxenv.Prepend( _LIBFLAGS = [ '-static-libgcc' ] )
# #crosslinuxenv.Prepend( _LIBFLAGS = [ '-lstdc++' ] )
# #crosslinuxenv.Append( _LIBFLAGS = [ '`' + crosslinuxenv['CXX'] + ' -print-file-name=libstdc++.a`' ] )
# #crosslinuxenv.Prepend( _LIBFLAGS = [ '/usr/local/gcc/i686-linux/lib/gcc/i686-linux/4.2.4/../../../../i686-linux/lib/libstdc++.a' ] )
env.VariantDir(buildpath,'.',duplicate=0)
networkenv = env.Clone()
################################################################
# Configure Environments
################################################################
env.Append( CPPPATH = [ 'src/Lib', 'src/NetPanzer' ] )
# for this platform
if thisplatform == 'darwin':
env.Append( CPPPATH = ['/Library/Frameworks/SDL.framework/Headers',
'/Library/Frameworks/SDL_mixer.framework/Headers' ] )
networkenv.Append( CPPPATH = ['/Library/Frameworks/SDL.framework/Headers'] )
if env['universal'] != 'false':
env.Append( CCFLAGS = [ '-arch', 'ppc', '-arch', 'i386' ] )
networkenv.Append( CCFLAGS = [ '-arch', 'ppc', '-arch', 'i386' ] )
env.Append( LINKFLAGS = [ '-mmacosx-version-min=10.4', '-arch', 'ppc', '-arch', 'i386' ] )
else:
env.Append( CCFLAGS = [ '-arch', 'i386' ] )
networkenv.Append( CCFLAGS = [ '-arch', 'i386' ] )
env.Append( LINKFLAGS = [ '-arch', 'i386' ] )
env.AppendUnique(FRAMEWORKS=Split('SDL SDL_mixer Cocoa IOKit'))
env.Append( NPSOURCES = ['support/macosx/SDLMain.m'] )
elif thisplatform == 'win32':
env.Append( CPPPATH = [ 'C:/MinGW/include/SDL' ] )
networkenv.Append( CPPPATH = [ 'C:/MinGW/include/SDL' ] )
#env.Append( LIBPATH = [ 'C:/MinGW/lib' ] )
env.Append( LIBS = [ 'ws2_32', 'mingw32', 'SDLMain', 'SDL' ] )
env.Append( CCFLAGS = [ '-D_WIN32_WINNT=0x0501' ] )
networkenv.Append( CCFLAGS = [ '-D_WIN32_WINNT=0x0501' ] )
env.Append( _LIBFLAGS = [ '-mwindows' ] )
env.Prepend( _LIBFLAGS = [ 'C:/MinGW/lib/SDL_mixer.lib' ] )
env['WINICON'] = env.RES( 'support/icon/npicon.rc' )
SetupSpawn(env)
else:
networkenv.ParseConfig(env['sdlconfig'] + ' --cflags --libs')
env.ParseConfig(env['sdlconfig'] + ' --cflags --libs')
# note: for some magic reason, now doesn't need to put the full path for
# SDL_mixer when using mingw crosscompilation
env.Append( LIBS = ['SDL_mixer' ] )
################################################################
# Makes libs
################################################################
# BUILDS NETWORK
networkenv.Append( CPPPATH = [ 'src/Lib' ] )
MakeStaticLib( networkenv, 'npnetwork', 'Network', '*.cpp')
# BUILDS 2D
env.Append( CFLAGS = [ '-DZ_PREFIX=1' ] )
MakeStaticLib(env, 'np2d', '2D 2D/libpng', '*.c*')
# BUILDS REST OF LIBRARIES
MakeStaticLib(env, 'nplibs', 'ArrayUtil INIParser Types Util optionmm','*.cpp')
################################################################
# NetPanzer source dirs
################################################################
npdirs = """
Bot Classes Classes/AI Classes/Network Core Interfaces Network
Objectives Particles PowerUps Resources Scripts System Units Weapons
Views Views/Components Views/Game Views/MainMenu Views/MainMenu/Multi
Views/MainMenu/Multi/MasterServer Views/MainMenu/Options
"""
env.Append( NPSOURCES = globSources(env, 'src/NetPanzer', npdirs, "*.cpp") )
if env.has_key('WINICON'):
env.Append( NPSOURCES = env['WINICON'] )
env.Prepend( LIBS = ['np2d','lua5.1','npnetwork','nplibs','physfs'] )
env.Prepend( LIBPATH = libpath )
netpanzer = env.Program( binpath+'netpanzer'+exeappend, env['NPSOURCES'])
pak2bmp = env.Program( binpath+'pak2bmp'+exeappend, 'support/tools/pak2bmp.cpp')
Alias('pak2bmp',pak2bmp)
bmp2pak = env.Program( binpath+'bmp2pak'+exeappend, 'support/tools/bmp2pak.cpp')
Alias('bmp2pak',bmp2pak)
Default(netpanzer)
|