José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 1 | ####################################################################### |
| 2 | # Common SCons code |
| 3 | |
| 4 | import os |
| 5 | import os.path |
| 6 | import sys |
| 7 | import platform as _platform |
| 8 | |
| 9 | |
| 10 | ####################################################################### |
| 11 | # Defaults |
| 12 | |
| 13 | _platform_map = { |
| 14 | 'linux2': 'linux', |
| 15 | 'win32': 'winddk', |
| 16 | } |
| 17 | |
| 18 | default_platform = sys.platform |
| 19 | default_platform = _platform_map.get(default_platform, default_platform) |
| 20 | |
| 21 | _machine_map = { |
| 22 | 'x86': 'x86', |
| 23 | 'i386': 'x86', |
| 24 | 'i486': 'x86', |
| 25 | 'i586': 'x86', |
| 26 | 'i686': 'x86', |
| 27 | 'x86_64': 'x86_64', |
| 28 | } |
| 29 | if 'PROCESSOR_ARCHITECTURE' in os.environ: |
| 30 | default_machine = os.environ['PROCESSOR_ARCHITECTURE'] |
| 31 | else: |
| 32 | default_machine = _platform.machine() |
| 33 | default_machine = _machine_map.get(default_machine, 'generic') |
| 34 | |
| 35 | if default_platform in ('linux', 'freebsd', 'darwin'): |
| 36 | default_dri = 'yes' |
| 37 | elif default_platform in ('winddk',): |
| 38 | default_dri = 'no' |
| 39 | else: |
| 40 | default_dri = 'no' |
| 41 | |
| 42 | |
| 43 | ####################################################################### |
| 44 | # Common options |
| 45 | |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 46 | def AddOptions(opts): |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 47 | from SCons.Options.BoolOption import BoolOption |
| 48 | from SCons.Options.EnumOption import EnumOption |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 49 | opts.Add(BoolOption('debug', 'build debug version', 'no')) |
José Fonseca | 5aa1082 | 2008-03-04 14:29:27 +0100 | [diff] [blame] | 50 | #opts.Add(BoolOption('quiet', 'quiet command lines', 'no')) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 51 | opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, |
| 52 | allowed_values=('generic', 'x86', 'x86_64'))) |
| 53 | opts.Add(EnumOption('platform', 'target platform', default_platform, |
| 54 | allowed_values=('linux', 'cell', 'winddk'))) |
| 55 | opts.Add(BoolOption('llvm', 'use LLVM', 'no')) |
| 56 | opts.Add(BoolOption('dri', 'build DRI drivers', default_dri)) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 57 | |
| 58 | |
| 59 | ####################################################################### |
José Fonseca | 5aa1082 | 2008-03-04 14:29:27 +0100 | [diff] [blame] | 60 | # Quiet command lines |
| 61 | # |
| 62 | # See also http://www.scons.org/wiki/HidingCommandLinesInOutput |
| 63 | |
| 64 | def quietCommandLines(env): |
| 65 | env['CCCOMSTR'] = "Compiling $SOURCE ..." |
| 66 | env['CXXCOMSTR'] = "Compiling $SOURCE ..." |
| 67 | env['ARCOMSTR'] = "Archiving $TARGET ..." |
| 68 | env['RANLIBCOMSTR'] = "" |
| 69 | env['LINKCOMSTR'] = "Linking $TARGET ..." |
| 70 | |
| 71 | |
| 72 | ####################################################################### |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 73 | # Convenience Library Builder |
| 74 | # based on the stock StaticLibrary and SharedLibrary builders |
| 75 | |
| 76 | import SCons.Action |
| 77 | import SCons.Builder |
| 78 | |
| 79 | def createConvenienceLibBuilder(env): |
| 80 | """This is a utility function that creates the ConvenienceLibrary |
| 81 | Builder in an Environment if it is not there already. |
| 82 | |
| 83 | If it is already there, we return the existing one. |
| 84 | """ |
| 85 | |
| 86 | try: |
| 87 | convenience_lib = env['BUILDERS']['ConvenienceLibrary'] |
| 88 | except KeyError: |
| 89 | action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ] |
| 90 | if env.Detect('ranlib'): |
| 91 | ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR") |
| 92 | action_list.append(ranlib_action) |
| 93 | |
| 94 | convenience_lib = SCons.Builder.Builder(action = action_list, |
| 95 | emitter = '$LIBEMITTER', |
| 96 | prefix = '$LIBPREFIX', |
| 97 | suffix = '$LIBSUFFIX', |
| 98 | src_suffix = '$SHOBJSUFFIX', |
| 99 | src_builder = 'SharedObject') |
| 100 | env['BUILDERS']['ConvenienceLibrary'] = convenience_lib |
| 101 | env['BUILDERS']['Library'] = convenience_lib |
| 102 | |
| 103 | return convenience_lib |
| 104 | |
| 105 | |
| 106 | ####################################################################### |
| 107 | # Build |
| 108 | |
| 109 | def make_build_dir(env): |
| 110 | # Put build output in a separate dir, which depends on the current configuration |
| 111 | # See also http://www.scons.org/wiki/AdvancedBuildExample |
| 112 | build_topdir = 'build' |
| 113 | build_subdir = env['platform'] |
| 114 | if env['dri']: |
| 115 | build_subdir += "-dri" |
| 116 | if env['llvm']: |
| 117 | build_subdir += "-llvm" |
| 118 | if env['machine'] != 'generic': |
| 119 | build_subdir += '-' + env['machine'] |
| 120 | if env['debug']: |
| 121 | build_subdir += "-debug" |
| 122 | build_dir = os.path.join(build_topdir, build_subdir) |
José Fonseca | 7a67855 | 2008-02-27 20:13:16 +0900 | [diff] [blame] | 123 | # Place the .sconsign file on the builddir too, to avoid issues with different scons |
| 124 | # versions building the same source file |
| 125 | env.SConsignFile(os.path.join(build_dir, '.sconsign')) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 126 | return build_dir |
| 127 | |
José Fonseca | 5aa1082 | 2008-03-04 14:29:27 +0100 | [diff] [blame] | 128 | |
| 129 | ####################################################################### |
| 130 | # Common environment generation code |
| 131 | |
| 132 | def generate(env): |
| 133 | # FIXME: this is already too late |
| 134 | #if env.get('quiet', False): |
| 135 | # quietCommandLines(env) |
| 136 | createConvenienceLibBuilder(env) |
| 137 | |
| 138 | # for debugging |
| 139 | #print env.Dump() |
| 140 | |