Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # The LLVM Compiler Infrastructure |
| 4 | # |
| 5 | # This file is distributed under the University of Illinois Open Source |
| 6 | # License. See LICENSE.TXT for details. |
| 7 | # |
| 8 | ##===----------------------------------------------------------------------===## |
| 9 | # |
| 10 | # This script attempts to be a drop-in replacement for gcc. |
| 11 | # |
| 12 | ##===----------------------------------------------------------------------===## |
| 13 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 14 | import os |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 15 | import sys |
Anders Carlsson | dac2b54 | 2008-02-06 19:03:27 +0000 | [diff] [blame] | 16 | import subprocess |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 17 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 18 | def checkenv(name, alternate=None): |
| 19 | """checkenv(var, alternate=None) - Return the given environment var, |
| 20 | or alternate if it is undefined or empty.""" |
| 21 | v = os.getenv(name) |
| 22 | if v and v.strip(): |
| 23 | return v.strip() |
| 24 | return alternate |
| 25 | |
Daniel Dunbar | 1bf3f73 | 2008-10-01 01:10:22 +0000 | [diff] [blame] | 26 | def checkbool(name, default=False): |
| 27 | v = os.getenv(name) |
| 28 | if v: |
| 29 | try: |
| 30 | return bool(int(v)) |
| 31 | except: |
| 32 | pass |
| 33 | return default |
| 34 | |
| 35 | CCC_ECHO = checkbool('CCC_ECHO') |
| 36 | CCC_NATIVE = checkbool('CCC_NATIVE','1') |
| 37 | CCC_FALLBACK = checkbool('CCC_FALLBACK') |
Nuno Lopes | 24653e8 | 2008-09-02 10:27:37 +0000 | [diff] [blame] | 38 | CCC_LANGUAGES = checkenv('CCC_LANGUAGES','c,c++,c-cpp-output,objective-c,objective-c++,objective-c-cpp-output') |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 39 | if CCC_LANGUAGES: |
| 40 | CCC_LANGUAGES = set([s.strip() for s in CCC_LANGUAGES.split(',')]) |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 41 | |
| 42 | # We want to support use as CC or LD, so we need different defines. |
| 43 | CLANG = checkenv('CLANG', 'clang') |
| 44 | LLC = checkenv('LLC', 'llc') |
| 45 | AS = checkenv('AS', 'as') |
| 46 | CC = checkenv('CCC_CC', 'cc') |
| 47 | LD = checkenv('CCC_LD', 'c++') |
| 48 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 49 | def error(message): |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 50 | print >> sys.stderr, 'ccc: ' + message |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 51 | sys.exit(1) |
| 52 | |
Seo Sanghyeon | d389465 | 2008-04-04 11:02:21 +0000 | [diff] [blame] | 53 | def quote(arg): |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 54 | if '"' in arg or ' ' in arg: |
Seo Sanghyeon | d389465 | 2008-04-04 11:02:21 +0000 | [diff] [blame] | 55 | return repr(arg) |
| 56 | return arg |
| 57 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 58 | def stripoutput(args): |
| 59 | """stripoutput(args) -> (output_name, newargs) |
| 60 | |
| 61 | Remove the -o argument from the arg list and return the output |
| 62 | filename and a new argument list. Assumes there will be at most |
| 63 | one -o option. If no output argument is found the result is (None, |
| 64 | args).""" |
| 65 | for i,a in enumerate(args): |
| 66 | if a.startswith('-o'): |
| 67 | if a=='-o': |
| 68 | if i+1<len(args): |
| 69 | return args[i+1],args[:i]+args[i+2:] |
| 70 | elif a.startswith('-o='): |
| 71 | opt,arg = a.split('=',1) |
| 72 | return arg,args[:i]+args[i+1:] |
| 73 | return None,args |
| 74 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 75 | def run(args): |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 76 | if CCC_ECHO: |
| 77 | print ' '.join(map(quote, args)) |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 78 | sys.stdout.flush() |
Anders Carlsson | dac2b54 | 2008-02-06 19:03:27 +0000 | [diff] [blame] | 79 | code = subprocess.call(args) |
Bill Wendling | 550ce0f | 2008-02-03 21:27:46 +0000 | [diff] [blame] | 80 | if code > 255: |
| 81 | code = 1 |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 82 | if code: |
| 83 | sys.exit(code) |
| 84 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 85 | def remove(path): |
| 86 | """remove(path) -> bool - Attempt to remove the file at path (if any). |
| 87 | |
| 88 | The result indicates if the remove was successful. A warning is |
| 89 | printed if there is an error removing the file.""" |
| 90 | if os.path.exists(path): |
| 91 | try: |
| 92 | os.remove(path) |
| 93 | except: |
| 94 | print >>sys.stderr, 'WARNING: Unable to remove temp "%s"'%(path,) |
| 95 | return False |
| 96 | return True |
| 97 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 98 | def preprocess(args): |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 99 | command = [CLANG,'-E'] |
Anders Carlsson | dac2b54 | 2008-02-06 19:03:27 +0000 | [diff] [blame] | 100 | run(command + args) |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 101 | |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 102 | def compile_fallback(args): |
| 103 | command = [CC,'-c'] |
| 104 | run(command + args) |
| 105 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 106 | def compile(args, native, save_temps=False): |
| 107 | if native: |
| 108 | output,args = stripoutput(args) |
| 109 | if not output: |
| 110 | raise ValueError,'Expected to always have explicit -o in compile()' |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 111 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 112 | # I prefer suffixing these to changing the extension, which is |
| 113 | # more likely to overwrite other things. We could of course |
| 114 | # use temp files. |
| 115 | bc_output = output + '.bc' |
| 116 | s_output = output + '.s' |
| 117 | command = [CLANG,'-emit-llvm-bc'] |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 118 | try: |
| 119 | run(command + args + ['-o', bc_output]) |
| 120 | # FIXME: What controls relocation model? |
| 121 | run([LLC, '-relocation-model=pic', '-f', '-o', s_output, bc_output]) |
| 122 | run([AS, '-o', output, s_output]) |
| 123 | finally: |
| 124 | if not save_temps: |
| 125 | remove(bc_output) |
| 126 | remove(s_output) |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 127 | else: |
| 128 | command = [CLANG,'-emit-llvm-bc'] |
| 129 | run(command + args) |
| 130 | |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 131 | def checked_compile(args, native, language, save_temps): |
| 132 | if CCC_LANGUAGES and language and language not in CCC_LANGUAGES: |
| 133 | print >>sys.stderr, 'NOTE: ccc: Using fallback compiler for: %s'%(' '.join(map(quote, args)),) |
| 134 | compile_fallback(args) |
| 135 | elif CCC_FALLBACK: |
| 136 | try: |
| 137 | compile(args, native, save_temps) |
| 138 | except: |
| 139 | print >>sys.stderr, 'WARNING: ccc: Using fallback compiler for: %s'%(' '.join(map(quote, args)),) |
| 140 | compile_fallback(args) |
| 141 | else: |
| 142 | compile(args, native, save_temps) |
| 143 | |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 144 | def link(args, native): |
| 145 | if native: |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 146 | run([LD] + args) |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 147 | else: |
| 148 | command = ['llvm-ld', '-native', '-disable-internalize'] |
| 149 | run(command + args) |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 150 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 151 | def extension(path): |
Seo Sanghyeon | 795aaed | 2008-02-03 03:40:41 +0000 | [diff] [blame] | 152 | return path.split(".")[-1] |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 153 | |
| 154 | def changeextension(path, newext): |
Seo Sanghyeon | 795aaed | 2008-02-03 03:40:41 +0000 | [diff] [blame] | 155 | i = path.rfind('.') |
| 156 | if i < 0: |
| 157 | return path |
Bill Wendling | 550ce0f | 2008-02-03 21:27:46 +0000 | [diff] [blame] | 158 | j = path.rfind('/', 0, i) |
Bill Wendling | 550ce0f | 2008-02-03 21:27:46 +0000 | [diff] [blame] | 159 | if j < 0: |
| 160 | return path[:i] + "." + newext |
| 161 | return path[j+1:i] + "." + newext |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 162 | |
| 163 | def inferlanguage(extension): |
| 164 | if extension == "c": |
| 165 | return "c" |
Lauro Ramos Venancio | 279876b | 2008-02-15 22:35:25 +0000 | [diff] [blame] | 166 | elif extension in ["cpp", "cc"]: |
| 167 | return "c++" |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 168 | elif extension == "i": |
| 169 | return "c-cpp-output" |
| 170 | elif extension == "m": |
| 171 | return "objective-c" |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 172 | elif extension == "mm": |
| 173 | return "objective-c++" |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 174 | elif extension == "mi": |
| 175 | return "objective-c-cpp-output" |
Nuno Lopes | 24653e8 | 2008-09-02 10:27:37 +0000 | [diff] [blame] | 176 | elif extension == "s": |
| 177 | return "assembler" |
| 178 | elif extension == "S": |
| 179 | return "assembler-with-cpp" |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 180 | else: |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 181 | return "" |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 182 | |
Daniel Dunbar | 869f8b6 | 2008-09-30 21:20:51 +0000 | [diff] [blame] | 183 | def inferaction(args): |
| 184 | if '-E' in args: |
| 185 | return 'preprocess' |
| 186 | if '-c' in args: |
| 187 | return 'compile' |
| 188 | for arg in args: |
| 189 | if arg.startswith('-print-prog-name'): |
| 190 | return 'pring-prog-name' |
| 191 | return 'link' |
| 192 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 193 | def main(args): |
Daniel Dunbar | 869f8b6 | 2008-09-30 21:20:51 +0000 | [diff] [blame] | 194 | action = inferaction(args) |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 195 | output = '' |
Seo Sanghyeon | 96b99f7 | 2008-01-25 14:57:54 +0000 | [diff] [blame] | 196 | compile_opts = [] |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 197 | link_opts = [] |
| 198 | files = [] |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 199 | save_temps = 0 |
| 200 | language = '' |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 201 | native = CCC_NATIVE |
| 202 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 203 | i = 0 |
| 204 | while i < len(args): |
| 205 | arg = args[i] |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 206 | |
Daniel Dunbar | 319e792 | 2008-09-30 22:54:22 +0000 | [diff] [blame] | 207 | if '=' in arg: |
| 208 | argkey,argvalue = arg.split('=',1) |
| 209 | else: |
| 210 | argkey,argvalue = arg,None |
| 211 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 212 | # Modes ccc supports |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 213 | if arg == '-save-temps': |
| 214 | save_temps = 1 |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 215 | if arg == '-emit-llvm' or arg == '--emit-llvm': |
| 216 | native = False |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 217 | |
| 218 | # Options with no arguments that should pass through |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 219 | if arg in ['-v', '-fobjc-gc', '-fobjc-gc-only', '-fnext-runtime', |
| 220 | '-fgnu-runtime']: |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 221 | compile_opts.append(arg) |
| 222 | link_opts.append(arg) |
| 223 | |
| 224 | # Options with one argument that should be ignored |
Ted Kremenek | d0eef02 | 2008-04-21 20:28:01 +0000 | [diff] [blame] | 225 | if arg in ['--param', '-u']: |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 226 | i += 1 |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 227 | |
Ted Kremenek | 1683360 | 2008-07-24 03:49:15 +0000 | [diff] [blame] | 228 | # Preprocessor options with one argument that should be ignored |
| 229 | if arg in ['-MT', '-MF']: |
| 230 | i += 1 |
| 231 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 232 | # Prefix matches for the compile mode |
| 233 | if arg[:2] in ['-D', '-I', '-U', '-F']: |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 234 | if not arg[2:]: |
| 235 | arg += args[i+1] |
| 236 | i += 1 |
| 237 | compile_opts.append(arg) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 238 | if arg[:5] in ['-std=']: |
| 239 | compile_opts.append(arg) |
Daniel Dunbar | 8e45f73 | 2008-10-02 17:26:37 +0000 | [diff] [blame^] | 240 | if argkey in ('-std', '-mmacosx-version-min'): |
| 241 | compile_opts.append(arg) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 242 | |
Nuno Lopes | e5d12e8 | 2008-06-17 17:23:14 +0000 | [diff] [blame] | 243 | # Options with one argument that should pass through to compiler |
Daniel Dunbar | 8e45f73 | 2008-10-02 17:26:37 +0000 | [diff] [blame^] | 244 | if arg in [ '-include', '-idirafter', '-iprefix', |
Daniel Dunbar | 319e792 | 2008-09-30 22:54:22 +0000 | [diff] [blame] | 245 | '-iquote', '-isystem', '-iwithprefix', |
Daniel Dunbar | 8e45f73 | 2008-10-02 17:26:37 +0000 | [diff] [blame^] | 246 | '-iwithprefixbefore']: |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 247 | compile_opts.append(arg) |
| 248 | compile_opts.append(args[i+1]) |
| 249 | i += 1 |
| 250 | |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 251 | # Options with no arguments that should pass through |
Daniel Dunbar | 1bf3f73 | 2008-10-01 01:10:22 +0000 | [diff] [blame] | 252 | if (arg in ('-dynamiclib', '-bundle', '-headerpad_max_install_names') or |
| 253 | arg.startswith('-Wl,')): |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 254 | link_opts.append(arg) |
| 255 | |
Nuno Lopes | e5d12e8 | 2008-06-17 17:23:14 +0000 | [diff] [blame] | 256 | # Options with one argument that should pass through |
Daniel Dunbar | 75e0571 | 2008-09-12 19:42:28 +0000 | [diff] [blame] | 257 | if arg in ('-framework', '-multiply_defined', '-bundle_loader', |
Daniel Dunbar | 319e792 | 2008-09-30 22:54:22 +0000 | [diff] [blame] | 258 | '-e', '-install_name', |
| 259 | '-unexported_symbols_list', '-exported_symbols_list', |
| 260 | '-compatibility_version', '-current_version', '-init', |
| 261 | '-seg1addr', '-dylib_file'): |
Nuno Lopes | e5d12e8 | 2008-06-17 17:23:14 +0000 | [diff] [blame] | 262 | link_opts.append(arg) |
| 263 | link_opts.append(args[i+1]) |
| 264 | i += 1 |
| 265 | |
| 266 | # Options with one argument that should pass through to both |
| 267 | if arg in ['-isysroot', '-arch']: |
| 268 | compile_opts.append(arg) |
| 269 | compile_opts.append(args[i+1]) |
| 270 | link_opts.append(arg) |
| 271 | link_opts.append(args[i+1]) |
| 272 | i += 1 |
Daniel Dunbar | 75e0571 | 2008-09-12 19:42:28 +0000 | [diff] [blame] | 273 | |
| 274 | # Options with three arguments that should pass through |
| 275 | if arg in ('-sectorder',): |
| 276 | link_opts.extend(args[i:i+4]) |
| 277 | i += 3 |
Nuno Lopes | e5d12e8 | 2008-06-17 17:23:14 +0000 | [diff] [blame] | 278 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 279 | # Prefix matches for the link mode |
Nuno Lopes | 9a18448 | 2008-08-10 21:58:01 +0000 | [diff] [blame] | 280 | if arg[:2] in ['-l', '-L', '-F', '-R']: |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 281 | link_opts.append(arg) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 282 | |
Chris Lattner | cf719b7 | 2008-06-21 17:46:11 +0000 | [diff] [blame] | 283 | # Enable threads |
| 284 | if arg == '-pthread': |
| 285 | link_opts.append('-lpthread') |
| 286 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 287 | # Input files |
| 288 | if arg == '-filelist': |
| 289 | f = open(args[i+1]) |
| 290 | for line in f: |
| 291 | files.append(line.strip()) |
| 292 | f.close() |
| 293 | i += 1 |
| 294 | if arg == '-x': |
| 295 | language = args[i+1] |
| 296 | i += 1 |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 297 | if arg[0] != '-': |
| 298 | files.append(arg) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 299 | |
| 300 | # Output file |
| 301 | if arg == '-o': |
| 302 | output = args[i+1] |
| 303 | i += 1 |
| 304 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 305 | i += 1 |
Daniel Dunbar | 869f8b6 | 2008-09-30 21:20:51 +0000 | [diff] [blame] | 306 | |
Seo Sanghyeon | 96b99f7 | 2008-01-25 14:57:54 +0000 | [diff] [blame] | 307 | if action == 'print-prog-name': |
| 308 | # assume we can handle everything |
| 309 | print sys.argv[0] |
| 310 | return |
| 311 | |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 312 | if not files: |
| 313 | error('no input files') |
| 314 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 315 | if action == 'preprocess' or save_temps: |
| 316 | for i, file in enumerate(files): |
| 317 | if not language: |
| 318 | language = inferlanguage(extension(file)) |
| 319 | if save_temps and action != 'preprocess': |
| 320 | # Need a temporary output file |
| 321 | if language == 'c': |
| 322 | poutput = changeextension(file, "i"); |
| 323 | elif language == 'objective-c': |
| 324 | poutput = changeextension(file, "mi"); |
| 325 | else: |
| 326 | poutput = changeextension(file, "tmp." + extension(file)) |
| 327 | files[i] = poutput |
| 328 | else: |
| 329 | poutput = output |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 330 | args = [] |
| 331 | if language: |
| 332 | args.extend(['-x', language]) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 333 | if poutput: |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 334 | args += ['-o', poutput, file] + compile_opts |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 335 | else: |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 336 | args += [file] + compile_opts |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 337 | preprocess(args) |
| 338 | # Discard the explicit language after used once |
| 339 | language = '' |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 340 | |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 341 | if action == 'compile' or save_temps: |
| 342 | for i, file in enumerate(files): |
| 343 | if not language: |
| 344 | language = inferlanguage(extension(file)) |
| 345 | if save_temps and action != "compile": |
| 346 | # Need a temporary output file |
| 347 | coutput = changeextension(file, "o"); |
| 348 | files[i] = coutput |
| 349 | elif not output: |
| 350 | coutput = changeextension(file, "o") |
| 351 | else: |
| 352 | coutput = output |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 353 | args = [] |
| 354 | if language: |
| 355 | args.extend(['-x', language]) |
| 356 | args += ['-o', coutput, file] + compile_opts |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 357 | checked_compile(args, native, language, save_temps) |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 358 | language = '' |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 359 | |
| 360 | if action == 'link': |
| 361 | for i, file in enumerate(files): |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 362 | if not language: |
| 363 | language = inferlanguage(extension(file)) |
Anders Carlsson | c720d9b | 2008-01-31 23:48:19 +0000 | [diff] [blame] | 364 | ext = extension(file) |
Nuno Lopes | c46cf49 | 2008-08-10 22:17:57 +0000 | [diff] [blame] | 365 | if ext != "o" and ext != "a" and ext != "so": |
Anders Carlsson | d125bb1 | 2008-01-29 07:21:34 +0000 | [diff] [blame] | 366 | out = changeextension(file, "o") |
Daniel Dunbar | 7000bf8 | 2008-09-30 16:18:31 +0000 | [diff] [blame] | 367 | args = [] |
| 368 | if language: |
| 369 | args.extend(['-x', language]) |
| 370 | args = ['-o', out, file] + compile_opts |
Daniel Dunbar | d3d8141 | 2008-08-29 21:03:27 +0000 | [diff] [blame] | 371 | checked_compile(args, native, language, save_temps) |
| 372 | language = '' |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 373 | files[i] = out |
| 374 | if not output: |
| 375 | output = 'a.out' |
| 376 | args = ['-o', output] + link_opts + files |
Daniel Dunbar | 4b5c4f2 | 2008-08-23 22:15:15 +0000 | [diff] [blame] | 377 | link(args, native) |
Seo Sanghyeon | 2bfa533 | 2008-01-10 01:43:47 +0000 | [diff] [blame] | 378 | |
| 379 | if __name__ == '__main__': |
| 380 | main(sys.argv[1:]) |