Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,6 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
options.add ' '
options.add cfile.customArgs

var compilePattern: string
# compute include paths:
var includeCmd = CC[c].includeCmd & quoteShell(conf.libpath)
if not noAbsolutePaths(conf):
for includeDir in items(conf.cIncludes):
includeCmd.add(join([CC[c].includeCmd, includeDir.quoteShell]))

compilePattern = joinPath(conf.cCompilerPath, exe)
else:
compilePattern = exe

includeCmd.add(join([CC[c].includeCmd, quoteShell(conf.projectPath.string)]))

let cf = if noAbsolutePaths(conf): AbsoluteFile extractFilename(cfile.cname.string)
else: cfile.cname

Expand All @@ -635,12 +622,28 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
let dfile = objfile.changeFileExt(".d").quoteShell

let cfsh = quoteShell(cf)
result = quoteShell(compilePattern % [
# compute include paths:
var includeCmd = CC[c].includeCmd & quoteShell(conf.libpath)
let confAbsPaths = not noAbsolutePaths(conf)
if confAbsPaths:
for includeDir in items(conf.cIncludes):
includeCmd.add(join([CC[c].includeCmd, includeDir.quoteShell]))
includeCmd.add(join([CC[c].includeCmd, quoteShell(conf.projectPath.string)]))
let subsVars = [
"dfile", dfile,
"file", cfsh, "objfile", quoteShell(objfile), "options", options,
"include", includeCmd, "nim", getPrefixDir(conf).string,
"lib", conf.libpath.string,
"ccenvflags", envFlags(conf)])
"ccenvflags", envFlags(conf)]
var compilePattern: string
exe = exe % subsVars
if confAbsPaths:
compilePattern = joinPath(conf.cCompilerPath % subsVars, exe)
else:
compilePattern = exe


result = quoteShell(compilePattern)

if optProduceAsm in conf.globalOptions:
if CC[conf.cCompiler].produceAsm.len > 0:
Expand Down Expand Up @@ -717,10 +720,6 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
else:
var linkerExe = getConfigVar(conf, conf.cCompiler, ".linkerexe")
if linkerExe.len == 0: linkerExe = getLinkerExe(conf, conf.cCompiler)
# bug #6452: We must not use ``quoteShell`` here for ``linkerExe``
if needsExeExt(conf): linkerExe = addFileExt(linkerExe, "exe")
if noAbsolutePaths(conf): result = linkerExe
else: result = joinPath(conf.cCompilerPath, linkerExe)
let buildgui = if optGenGuiApp in conf.globalOptions and conf.target.targetOS == osWindows:
CC[conf.cCompiler].buildGui
else:
Expand All @@ -741,10 +740,16 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
var linkTmpl = getConfigVar(conf, conf.cCompiler, ".linkTmpl")
if linkTmpl.len == 0:
linkTmpl = CC[conf.cCompiler].linkTmpl
result = quoteShell(result % ["builddll", builddll,
let subsVars = ["builddll", builddll,
"mapfile", mapfile,
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
"exefile", exefile, "nim", getPrefixDir(conf).string, "lib", conf.libpath.string])
"exefile", exefile, "nim", getPrefixDir(conf).string, "lib", conf.libpath.string]
linkerExe = linkerExe % subsVars
# bug #6452: We must not use ``quoteShell`` here for ``linkerExe``
if needsExeExt(conf): linkerExe = addFileExt(linkerExe, "exe")
if noAbsolutePaths(conf): result = linkerExe
else: result = joinPath(conf.cCompilerPath % subsVars, linkerExe)
result = quoteShell(result)
result.add ' '
strutils.addf(result, linkTmpl, ["builddll", builddll,
"mapfile", mapfile,
Expand Down