1 # 2 # Copyright (C) 2011 The Android Open Source Project 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 COMMON_CFLAGS = ['-Wall', '-Werror', '-D__HOST__'] 18 COMMON_CXXFLAGS = ['-Wall', '-Werror', '-fno-exceptions', '-D__HOST__'] 19 20 configs = { 21 'debug': { 22 'CFLAGS': COMMON_CFLAGS + ['-g'], 23 'CXXFLAGS': COMMON_CXXFLAGS + ['-g'] 24 }, 25 26 'release': { 27 'CFLAGS': COMMON_CFLAGS + ['-O2'], 28 'CXXFLAGS': COMMON_CXXFLAGS + ['-O2'] 29 }, 30 } 31 32 toolsets = { 33 'gcc': { 34 'CC': 'gcc', 35 'CXX': 'g++', 36 }, 37 38 'mips-gcc': { 39 'CC': 'mips-linux-gnu-gcc', 40 'CXX': 'mips-linux-gnu-g++', 41 }, 42 43 'clang': { 44 'CC': 'clang', 45 'CXX': 'clang++', 46 }, 47 } 48 49 toolset_configs = { 50 'gcc': { 'CFLAGS': [], 'CXXFLAGS': [], 'LDFLAGS': [] }, 51 'clang': { 'CFLAGS': [], 'CXXFLAGS': [], 'LDFLAGS': [] }, 52 'mips-gcc': { 'CFLAGS': ['-EL', '-mips32r2'], 53 'CXXFLAGS': ['-EL', '-mips32r2'], 54 'LDFLAGS': ['-EL', '-mips32r2'] } 55 } 56 57 mode = ARGUMENTS.get('mode', 'release') 58 toolset = ARGUMENTS.get('toolset', 'gcc') 59 60 if not mode in configs: 61 print 'ERROR: Unknown building mode:', mode 62 Exit(1) 63 64 if not toolset in toolsets: 65 print 'ERROR: Unknown toolset:', toolset 66 Exit(1) 67 68 build_config = configs[mode] 69 build_toolset = toolsets[toolset] 70 build_toolset_config = toolset_configs[toolset] 71 72 print '===> BUILDING IN', mode.upper(), 'MODE ...' 73 74 import os 75 76 cflags = build_config['CFLAGS'] + build_toolset_config['CFLAGS'] 77 cxxflags = build_config['CXXFLAGS'] + build_toolset_config['CXXFLAGS'] 78 linkflags = build_toolset_config['LDFLAGS'] 79 80 env = Environment(CC=build_toolset['CC'], 81 CXX=build_toolset['CXX'], 82 CFLAGS=cflags, 83 CXXFLAGS=cxxflags, 84 LINKFLAGS=linkflags, 85 CPPPATH=['.', 'include'], 86 ENV={'PATH': os.environ['PATH']}) 87 88 env.ParseConfig('llvm-config --cxxflags --ldflags --libs support') 89 90 env.Program('rsloader', 91 source=['lib/ELFHeader.cpp', 92 'lib/ELFSectionHeader.cpp', 93 'lib/ELFSymbol.cpp', 94 'lib/ELFTypes.cpp', 95 'lib/MemChunk.cpp', 96 'lib/StubLayout.cpp', 97 'lib/GOT.cpp', 98 'utils/helper.cpp', 99 'utils/raw_ostream.cpp', 100 'utils/rsl_assert.cpp', 101 'main.cpp']) 102