diff options
author | Araq <rumpf_a@web.de> | 2012-07-08 23:33:45 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-08 23:33:45 +0200 |
commit | f0dd96fa58478f732009def25f527d67d87e464c (patch) | |
tree | 4445c7663570fc351853451f6f68b0de3c4bf6cc /compiler | |
parent | bb82e305081f65af828a0b88a455ee352bac8157 (diff) | |
download | Nim-f0dd96fa58478f732009def25f527d67d87e464c.tar.gz |
cross-compilation improvements
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/commands.nim | 2 | ||||
-rwxr-xr-x | compiler/extccomp.nim | 49 |
2 files changed, 32 insertions, 19 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index cec0bbe6b..508106cca 100755 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -386,7 +386,6 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) = if theOS == osNone: LocalError(info, errUnknownOS, arg) elif theOS != platform.hostOS: setTarget(theOS, targetCPU) - incl(gGlobalOptions, optCompileOnly) condsyms.InitDefines() of "cpu": expectArg(switch, arg, pass, info) @@ -395,7 +394,6 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) = if cpu == cpuNone: LocalError(info, errUnknownCPU, arg) elif cpu != platform.hostCPU: setTarget(targetOS, cpu) - incl(gGlobalOptions, optCompileOnly) condsyms.InitDefines() of "run", "r": expectNoArg(switch, arg, pass, info) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 1f3def384..298d5b212 100755 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -326,12 +326,27 @@ proc NameToCC*(name: string): TSystemCC = return i result = ccNone +proc getConfigVar(c: TSystemCC, suffix: string): string = + # use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given + # for niminst support + if (platform.hostOS != targetOS or platform.hostCPU != targetCPU) and + optCompileOnly notin gGlobalOptions: + let fullCCname = platform.cpu[targetCPU].name & '.' & + platform.os[targetOS].name & '.' & + CC[c].name & suffix + result = getConfigVar(fullCCname) + if result.len == 0: + # not overriden for this cross compilation setting? + result = getConfigVar(CC[c].name & suffix) + else: + result = getConfigVar(CC[c].name & suffix) + proc setCC*(ccname: string) = ccompiler = nameToCC(ccname) if ccompiler == ccNone: rawMessage(errUnknownCcompiler, ccname) - compileOptions = getConfigVar(CC[ccompiler].name & ".options.always") - linkOptions = getConfigVar(CC[ccompiler].name & ".options.linker") - ccompilerpath = getConfigVar(CC[ccompiler].name & ".path") + compileOptions = getConfigVar(ccompiler, ".options.always") + linkOptions = getConfigVar(ccompiler, ".options.linker") + ccompilerpath = getConfigVar(ccompiler, ".path") for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name) defineSymbol(CC[ccompiler].name) @@ -352,10 +367,10 @@ proc initVars*() = defineSymbol(CC[ccompiler].name) if gCmd == cmdCompileToCpp: cExt = ".cpp" elif gCmd == cmdCompileToOC: cExt = ".m" - addCompileOption(getConfigVar(CC[ccompiler].name & ".options.always")) - addLinkOption(getConfigVar(CC[ccompiler].name & ".options.linker")) - if len(ccompilerPath) == 0: - ccompilerpath = getConfigVar(CC[ccompiler].name & ".path") + addCompileOption(getConfigVar(ccompiler, ".options.always")) + addLinkOption(getConfigVar(ccompiler, ".options.linker")) + if len(ccompilerPath) == 0: + ccompilerpath = getConfigVar(ccompiler, ".path") proc completeCFilePath*(cfile: string, createSubDir: bool = true): string = result = completeGeneratedFilePath(cfile, createSubDir) @@ -408,18 +423,18 @@ proc generateScript(projectFile: string, script: PRope) = platform.os[targetOS].scriptExt)) proc getOptSpeed(c: TSystemCC): string = - result = getConfigVar(cc[c].name & ".options.speed") - if result == "": + result = getConfigVar(c, ".options.speed") + if result == "": result = cc[c].optSpeed # use default settings from this file proc getDebug(c: TSystemCC): string = - result = getConfigVar(cc[c].name & ".options.debug") - if result == "": + result = getConfigVar(c, ".options.debug") + if result == "": result = cc[c].debug # use default settings from this file proc getOptSize(c: TSystemCC): string = - result = getConfigVar(cc[c].name & ".options.size") - if result == "": + result = getConfigVar(c, ".options.size") + if result == "": result = cc[c].optSize # use default settings from this file proc noAbsolutePaths: bool {.inline.} = @@ -469,9 +484,9 @@ proc getLinkOptions: string = proc getCompileCFileCmd*(cfilename: string, isExternal = false): string = var c = ccompiler var options = CFileSpecificOptions(cfilename) - var exe = cc[c].compilerExe - var key = cc[c].name & ".exe" - if existsConfigVar(key): exe = getConfigVar(key) + var exe = getConfigVar(c, ".exe") + if exe.len == 0: exe = cc[c].compilerExe + if targetOS == osWindows: exe = addFileExt(exe, "exe") if optGenDynLib in gGlobalOptions and ospNeedsPIC in platform.OS[targetOS].props: @@ -561,7 +576,7 @@ proc CallCCompiler*(projectfile: string) = "objfiles", objfiles] if optCompileOnly notin gGlobalOptions: execExternalProgram(linkCmd) else: - var linkerExe = getConfigVar(cc[c].name & ".linkerexe") + var linkerExe = getConfigVar(c, ".linkerexe") if len(linkerExe) == 0: linkerExe = cc[c].linkerExe if targetOS == osWindows: linkerExe = addFileExt(linkerExe, "exe") if noAbsolutePaths(): linkCmd = quoteIfContainsWhite(linkerExe) |