comparison gen/toobj.cpp @ 1299:847b767b2d0b

Factor out the code to find gcc, and add a command-line option to override the default executable name. This should help cross-compilation by allowing a cross-gcc to be specified from the configuration file instead of only through the CC environment variable.
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 04 May 2009 13:32:16 +0200
parents 00a307a393f2
children 681dd955c53b
comparison
equal deleted inserted replaced
1298:7e303f9f16c7 1299:847b767b2d0b
16 #include "llvm/Module.h" 16 #include "llvm/Module.h"
17 #include "llvm/ModuleProvider.h" 17 #include "llvm/ModuleProvider.h"
18 #include "llvm/PassManager.h" 18 #include "llvm/PassManager.h"
19 #include "llvm/LinkAllPasses.h" 19 #include "llvm/LinkAllPasses.h"
20 #include "llvm/System/Program.h" 20 #include "llvm/System/Program.h"
21 #include "llvm/System/Path.h"
22 #include "llvm/Support/raw_ostream.h" 21 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Target/TargetMachine.h" 23 #include "llvm/Target/TargetMachine.h"
25 24
26 #include "mars.h" 25 #include "mars.h"
49 #include "gen/runtime.h" 48 #include "gen/runtime.h"
50 #include "gen/abi.h" 49 #include "gen/abi.h"
51 #include "gen/cl_options.h" 50 #include "gen/cl_options.h"
52 #include "gen/optimizer.h" 51 #include "gen/optimizer.h"
53 #include "gen/llvm-version.h" 52 #include "gen/llvm-version.h"
53 #include "gen/programs.h"
54 54
55 #include "ir/irvar.h" 55 #include "ir/irvar.h"
56 #include "ir/irmodule.h" 56 #include "ir/irmodule.h"
57 57
58 ////////////////////////////////////////////////////////////////////////////////////////// 58 //////////////////////////////////////////////////////////////////////////////////////////
308 // based on llvm-ld code, University of Illinois Open Source License 308 // based on llvm-ld code, University of Illinois Open Source License
309 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath) 309 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath)
310 { 310 {
311 using namespace llvm; 311 using namespace llvm;
312 312
313 const char *cc; 313 sys::Path gcc = getGcc();
314 #if !_WIN32
315 cc = getenv("CC");
316 if (!cc)
317 #endif
318 cc = "gcc";
319
320 sys::Path gcc = llvm::sys::Program::FindProgramByName(cc);
321 if (gcc.empty())
322 {
323 error("failed to locate gcc");
324 fatal();
325 }
326 314
327 // Run GCC to assemble and link the program into native code. 315 // Run GCC to assemble and link the program into native code.
328 // 316 //
329 // Note: 317 // Note:
330 // We can't just assemble and link the file with the system assembler 318 // We can't just assemble and link the file with the system assembler