From 17ca9f15bd95aadba1c06571087ffcc8fda49e05 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 3 Mar 2013 00:53:35 +0000 Subject: [PATCH] Move compiler flags/selection into a base class above DXXProgram --- SConstruct | 174 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 64 deletions(-) diff --git a/SConstruct b/SConstruct index f3a3e8132..4e407eb66 100644 --- a/SConstruct +++ b/SConstruct @@ -23,26 +23,13 @@ def checkEndian(): return "big" return "unknown" -class DXXProgram: +class DXXCommon: __endian = checkEndian() - # version number - VERSION_MAJOR = 0 - VERSION_MINOR = 57 - VERSION_MICRO = 3 - common_sources = [] - editor_sources = [] class UserSettings: - def __init__(self,ARGUMENTS,target): - # installation path - PREFIX = str(ARGUMENTS.get('prefix', '/usr/local')) - self.BIN_DIR = PREFIX + '/bin' - self.DATA_DIR = PREFIX + '/share/games/' + target - + def __init__(self,ARGUMENTS): # Paths for the Videocore libs/includes on the Raspberry Pi self.RPI_DEFAULT_VC_PATH='/opt/vc' - # command-line parms - self.sharepath = str(ARGUMENTS.get('sharepath', self.DATA_DIR)) self.debug = int(ARGUMENTS.get('debug', 0)) self.profiler = int(ARGUMENTS.get('profiler', 0)) self.opengl = int(ARGUMENTS.get('opengl', 1)) @@ -95,23 +82,15 @@ class DXXProgram: class Win32PlatformSettings(_PlatformSettings): tools = ['mingw'] def __init__(self,user_settings): - DXXProgram._PlatformSettings.__init__(self) + DXXCommon._PlatformSettings.__init__(self) self.osdef = '_WIN32' self.osasmdef = 'win32' - user_settings.sharepath = '' - self.lflags = '-mwindows' - self.libs = ['glu32', 'wsock32', 'ws2_32', 'winmm', 'mingw32', 'SDLmain', 'SDL'] def adjust_environment(self,program,env): - env.RES('arch/win32/%s.rc' % program.target) env.Append(CPPDEFINES = ['_WIN32', 'HAVE_STRUCT_TIMEVAL']) - env.Append(CPPPATH = [os.path.join(self.srcdir, 'arch/win32/include')]) - self.platform_sources = [os.path.join(program.srcdir, 'arch/win32/messagebox.c')] - # Settings to apply to Apple builds class DarwinPlatformSettings(_PlatformSettings): def __init__(self,user_settings): - DXXProgram._PlatformSettings.__init__(self) + DXXCommon._PlatformSettings.__init__(self) self.osdef = '__APPLE__' - user_settings.sharepath = '' user_settings.asm = 0 self.lflags = os.environ["LDFLAGS"] if os.environ.has_key('LDFLAGS') else '' def adjust_environment(self,program,env): @@ -122,7 +101,6 @@ class DXXProgram: env['VERSION_NAME'] = program.PROGRAM_NAME + ' v' + VERSION env.Append(CPPDEFINES = ['HAVE_STRUCT_TIMESPEC', 'HAVE_STRUCT_TIMEVAL', '__unix__']) env.Append(CPPPATH = [os.path.join(program.srcdir, '../physfs'), os.path.join(os.getenv("HOME"), 'Library/Frameworks/SDL.framework/Headers'), '/Library/Frameworks/SDL.framework/Headers']) - self.platform_sources = [os.path.join(program.srcdir, f) for f in ['arch/cocoa/SDLMain.m', 'arch/carbon/messagebox.c']] env.Append(FRAMEWORKS = ['ApplicationServices', 'Carbon', 'Cocoa', 'SDL']) env.Append(FRAMEWORKPATH = [os.path.join(os.getenv("HOME"), 'Library/Frameworks'), '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks']) self.libs = [''] @@ -130,32 +108,21 @@ class DXXProgram: # Settings to apply to Linux builds class LinuxPlatformSettings(_PlatformSettings): def __init__(self,user_settings): - DXXProgram._PlatformSettings.__init__(self) + DXXCommon._PlatformSettings.__init__(self) self.osdef = '__LINUX__' self.osasmdef = 'elf' if (user_settings.opengles == 1): self.ogllibs = [ user_settings.opengles_lib, 'EGL'] else: self.ogllibs = ['GL', 'GLU'] - self.lflags = os.environ["LDFLAGS"] if os.environ.has_key('LDFLAGS') else '' def adjust_environment(self,program,env): env.Append(CPPDEFINES = ['__LINUX__', 'HAVE_STRUCT_TIMESPEC', 'HAVE_STRUCT_TIMEVAL']) env.ParseConfig('pkg-config --cflags --libs sdl') - self.libs = env['LIBS'] - env.Append(CPPPATH = [os.path.join(program.srcdir, 'arch/linux/include')]) def __init__(self): - self.user_settings = self.UserSettings(self.ARGUMENTS, self.target) - self.check_platform() - self.prepare_environment() - self.banner() - self.check_endian() - self.process_user_settings() - self.register_program() + pass def prepare_environment(self): - self.VERSION_STRING = ' v' + str(self.VERSION_MAJOR) + '.' + str(self.VERSION_MINOR) + '.' + str(self.VERSION_MICRO) - self.env.Append(CPPDEFINES = [('PROGRAM_NAME', '\\"' + str(self.PROGRAM_NAME) + '\\"'), ('DXX_VERSION_MAJORi', str(self.VERSION_MAJOR)), ('DXX_VERSION_MINORi', str(self.VERSION_MINOR)), ('DXX_VERSION_MICROi', str(self.VERSION_MICRO))]) if self.user_settings.builddir != '': self.env.VariantDir(self.user_settings.builddir, '.', duplicate=0) @@ -167,6 +134,9 @@ class DXXProgram: self.env["ARCOMSTR"] = "Archiving $TARGET ..." self.env["RANLIBCOMSTR"] = "Indexing $TARGET ..." + self.env.Append(CCFLAGS = ['-Wall', '-funsigned-char', '-Werror=implicit-int', '-Werror=implicit-function-declaration', '-pthread']) + self.env.Append(CFLAGS = ['-std=gnu99']) + self.env.Append(CPPDEFINES = ['NETWORK']) # Get traditional compiler environment variables for cc in ['CC', 'CXX']: if os.environ.has_key(cc): @@ -175,15 +145,12 @@ class DXXProgram: if os.environ.has_key(flags): self.env[flags] += SCons.Util.CLVar(os.environ[flags]) - def banner(self): - print '\n===== ' + self.PROGRAM_NAME + self.VERSION_STRING + ' =====\n' - def check_endian(self): # set endianess if (self.__endian == "big"): print "%s: BigEndian machine detected" % self.PROGRAM_NAME self.asm = 0 - env.Append(CPPDEFINES = ['WORDS_BIGENDIAN']) + self.env.Append(CPPDEFINES = ['WORDS_BIGENDIAN']) elif (self.__endian == "little"): print "%s: LittleEndian machine detected" % self.PROGRAM_NAME @@ -198,7 +165,6 @@ class DXXProgram: else: print "%s: compiling on *NIX" % self.PROGRAM_NAME platform = self.LinuxPlatformSettings - self.user_settings.sharepath += '/' self.platform_settings = platform(self.user_settings) # Acquire environment object... self.env = Environment(ENV = os.environ, tools = platform.tools) @@ -216,14 +182,6 @@ class DXXProgram: else: print "%s: building with OpenGL" % self.PROGRAM_NAME env.Append(CPPDEFINES = ['OGL']) - self.common_sources += self.arch_ogl_sources - if (sys.platform != 'darwin'): - self.platform_settings.libs += self.platform_settings.ogllibs - else: - env.Append(FRAMEWORKS = ['OpenGL']) - else: - print "%s: building with Software Renderer" % self.PROGRAM_NAME - self.common_sources += self.arch_sdl_sources # assembler code? if (self.user_settings.asm == 1) and (self.user_settings.opengl == 0): @@ -238,11 +196,6 @@ class DXXProgram: if (self.user_settings.sdlmixer == 1): print "%s: including SDL_mixer" % self.PROGRAM_NAME env.Append(CPPDEFINES = ['USE_SDLMIXER']) - self.common_sources += self.arch_sdlmixer - if (sys.platform != 'darwin'): - self.platform_settings.libs += ['SDL_mixer'] - else: - env.Append(FRAMEWORKS = ['SDL_mixer']) # debug? if (self.user_settings.debug == 1): @@ -255,12 +208,10 @@ class DXXProgram: # profiler? if (self.user_settings.profiler == 1): env.Append(CPPFLAGS = ['-pg']) - self.platform_settings.lflags += ' -pg' #editor build? if (self.user_settings.editor == 1): env.Append(CPPDEFINES = ['EDITOR']) - env.Append(CPPPATH = [os.path.join(self.srcdir, 'include/editor')]) self.common_sources += self.editor_sources # IPv6 compability? @@ -270,11 +221,109 @@ class DXXProgram: # UDP support? if (self.user_settings.use_udp == 1): env.Append(CPPDEFINES = ['USE_UDP']) - self.common_sources += self.sources_use_udp # Tracker support? (Relies on UDP) if( self.user_settings.use_tracker == 1 ): env.Append( CPPDEFINES = [ 'USE_TRACKER' ] ) - print '\n' + +class DXXProgram(DXXCommon): + # version number + VERSION_MAJOR = 0 + VERSION_MINOR = 57 + VERSION_MICRO = 3 + class UserSettings(DXXCommon.UserSettings): + def __init__(self,ARGUMENTS,target): + DXXCommon.UserSettings.__init__(self, ARGUMENTS.ARGUMENTS) + # installation path + PREFIX = str(ARGUMENTS.get('prefix', '/usr/local')) + self.BIN_DIR = PREFIX + '/bin' + self.DATA_DIR = PREFIX + '/share/games/' + target + # command-line parms + self.sharepath = str(ARGUMENTS.get('sharepath', self.DATA_DIR)) + # Settings to apply to mingw32 builds + class Win32PlatformSettings(DXXCommon.Win32PlatformSettings): + def __init__(self,user_settings): + DXXCommon.Win32PlatformSettings.__init__(self,user_settings) + user_settings.sharepath = '' + self.lflags = '-mwindows' + self.libs = ['glu32', 'wsock32', 'ws2_32', 'winmm', 'mingw32', 'SDLmain', 'SDL'] + def adjust_environment(self,program,env): + DXXCommon.Win32PlatformSettings.adjust_environment(self, program, env) + env.RES('arch/win32/%s.rc' % program.target) + env.Append(CPPPATH = [os.path.join(self.srcdir, 'arch/win32/include')]) + self.platform_sources = [os.path.join(program.srcdir, 'arch/win32/messagebox.c')] + # Settings to apply to Apple builds + # This appears to be unused. The reference to sdl_only fails to + # execute. + class DarwinPlatformSettings(DXXCommon.DarwinPlatformSettings): + def __init__(self,user_settings): + DXXCommon.DarwinPlatformSettings.__init__(self) + user_settings.sharepath = '' + def adjust_environment(self,program,env): + DXXCommon.DarwinPlatformSettings.adjust_environment(self, program, env) + self.platform_sources = [os.path.join(program.srcdir, f) for f in ['arch/cocoa/SDLMain.m', 'arch/carbon/messagebox.c']] + # Settings to apply to Linux builds + class LinuxPlatformSettings(DXXCommon.LinuxPlatformSettings): + def __init__(self,user_settings): + DXXCommon.LinuxPlatformSettings.__init__(self,user_settings) + user_settings.sharepath += '/' + self.lflags = os.environ["LDFLAGS"] if os.environ.has_key('LDFLAGS') else '' + def adjust_environment(self,program,env): + DXXCommon.LinuxPlatformSettings.adjust_environment(self, program, env) + self.libs = env['LIBS'] + env.Append(CPPPATH = [os.path.join(program.srcdir, 'arch/linux/include')]) + + def __init__(self): + DXXCommon.__init__(self) + self.user_settings = self.UserSettings(self.ARGUMENTS, self.target) + self.check_platform() + self.prepare_environment() + self.banner() + self.check_endian() + self.process_user_settings() + self.register_program() + + def prepare_environment(self): + DXXCommon.prepare_environment(self) + self.VERSION_STRING = ' v' + str(self.VERSION_MAJOR) + '.' + str(self.VERSION_MINOR) + '.' + str(self.VERSION_MICRO) + self.env.Append(CPPDEFINES = [('PROGRAM_NAME', '\\"' + str(self.PROGRAM_NAME) + '\\"'), ('DXX_VERSION_MAJORi', str(self.VERSION_MAJOR)), ('DXX_VERSION_MINORi', str(self.VERSION_MINOR)), ('DXX_VERSION_MICROi', str(self.VERSION_MICRO))]) + + def banner(self): + print '\n===== ' + self.PROGRAM_NAME + self.VERSION_STRING + ' =====\n' + + def process_user_settings(self): + DXXCommon.process_user_settings(self) + env = self.env + # opengl or software renderer? + if (self.user_settings.opengl == 1) or (self.user_settings.opengles == 1): + self.common_sources += self.arch_ogl_sources + if (sys.platform != 'darwin'): + self.platform_settings.libs += self.platform_settings.ogllibs + else: + env.Append(FRAMEWORKS = ['OpenGL']) + else: + print "%s: building with Software Renderer" % self.PROGRAM_NAME + self.common_sources += self.arch_sdl_sources + + # SDL_mixer support? + if (self.user_settings.sdlmixer == 1): + self.common_sources += self.arch_sdlmixer + if (sys.platform != 'darwin'): + self.platform_settings.libs += ['SDL_mixer'] + else: + env.Append(FRAMEWORKS = ['SDL_mixer']) + + # profiler? + if (self.user_settings.profiler == 1): + self.platform_settings.lflags += ' -pg' + + #editor build? + if (self.user_settings.editor == 1): + env.Append(CPPPATH = [os.path.join(self.srcdir, 'include/editor')]) + + # UDP support? + if (self.user_settings.use_udp == 1): + self.common_sources += self.sources_use_udp + env.Append(CPPDEFINES = [('SHAREPATH', '\\"' + str(self.user_settings.sharepath) + '\\"')]) class D1XProgram(DXXProgram): @@ -285,9 +334,6 @@ class D1XProgram(DXXProgram): def prepare_environment(self): DXXProgram.prepare_environment(self) # Flags and stuff for all platforms... - self.env.Append(CCFLAGS = ['-Wall', '-funsigned-char', '-Werror=implicit-int', '-Werror=implicit-function-declaration', '-pthread']) - self.env.Append(CFLAGS = ['-std=gnu99']) - self.env.Append(CPPDEFINES = ['NETWORK']) self.env.Append(CPPPATH = [os.path.join(self.srcdir, f) for f in ['include', 'main', 'arch/include']]) def __init__(self):