added a new feature: --cc:env so that you can use any C compiler as long as it works like GCC
This commit is contained in:
parent
1b2b32169a
commit
c64db68f0b
3 changed files with 31 additions and 13 deletions
|
|
@ -240,15 +240,15 @@ compiler tcc:
|
||||||
props: {hasSwitchRange, hasComputedGoto, hasGnuAsm})
|
props: {hasSwitchRange, hasComputedGoto, hasGnuAsm})
|
||||||
|
|
||||||
# Your C Compiler
|
# Your C Compiler
|
||||||
compiler ucc:
|
compiler envcc:
|
||||||
result = (
|
result = (
|
||||||
name: "ucc",
|
name: "env",
|
||||||
objExt: "o",
|
objExt: "o",
|
||||||
optSpeed: " -O3 ",
|
optSpeed: " -O3 ",
|
||||||
optSize: " -O1 ",
|
optSize: " -O1 ",
|
||||||
compilerExe: "cc",
|
compilerExe: "",
|
||||||
cppCompiler: "",
|
cppCompiler: "",
|
||||||
compileTmpl: "-c $options $include -o $objfile $file",
|
compileTmpl: "-c $ccenvflags $options $include -o $objfile $file",
|
||||||
buildGui: "",
|
buildGui: "",
|
||||||
buildDll: " -shared ",
|
buildDll: " -shared ",
|
||||||
buildLib: "", # XXX: not supported yet
|
buildLib: "", # XXX: not supported yet
|
||||||
|
|
@ -263,7 +263,7 @@ compiler ucc:
|
||||||
structStmtFmt: "$1 $2",
|
structStmtFmt: "$1 $2",
|
||||||
produceAsm: "",
|
produceAsm: "",
|
||||||
cppXsupport: "",
|
cppXsupport: "",
|
||||||
props: {})
|
props: {hasGnuAsm})
|
||||||
|
|
||||||
const
|
const
|
||||||
CC*: array[succ(low(TSystemCC))..high(TSystemCC), TInfoCC] = [
|
CC*: array[succ(low(TSystemCC))..high(TSystemCC), TInfoCC] = [
|
||||||
|
|
@ -274,7 +274,7 @@ const
|
||||||
bcc(),
|
bcc(),
|
||||||
vcc(),
|
vcc(),
|
||||||
tcc(),
|
tcc(),
|
||||||
ucc(),
|
envcc(),
|
||||||
icl(),
|
icl(),
|
||||||
icc(),
|
icc(),
|
||||||
clangcl()]
|
clangcl()]
|
||||||
|
|
@ -483,7 +483,19 @@ proc needsExeExt(conf: ConfigRef): bool {.inline.} =
|
||||||
proc useCpp(conf: ConfigRef; cfile: AbsoluteFile): bool =
|
proc useCpp(conf: ConfigRef; cfile: AbsoluteFile): bool =
|
||||||
conf.cmd == cmdCompileToCpp and not cfile.string.endsWith(".c")
|
conf.cmd == cmdCompileToCpp and not cfile.string.endsWith(".c")
|
||||||
|
|
||||||
|
proc envFlags(conf: ConfigRef): string =
|
||||||
|
result = if conf.cmd == cmdCompileToCpp:
|
||||||
|
getEnv("CXXFLAGS")
|
||||||
|
else:
|
||||||
|
getEnv("CFLAGS")
|
||||||
|
|
||||||
proc getCompilerExe(conf: ConfigRef; compiler: TSystemCC; cfile: AbsoluteFile): string =
|
proc getCompilerExe(conf: ConfigRef; compiler: TSystemCC; cfile: AbsoluteFile): string =
|
||||||
|
if compiler == ccEnv:
|
||||||
|
result = if useCpp(conf, cfile):
|
||||||
|
getEnv("CXX")
|
||||||
|
else:
|
||||||
|
getEnv("CC")
|
||||||
|
else:
|
||||||
result = if useCpp(conf, cfile):
|
result = if useCpp(conf, cfile):
|
||||||
CC[compiler].cppCompiler
|
CC[compiler].cppCompiler
|
||||||
else:
|
else:
|
||||||
|
|
@ -581,7 +593,8 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
|
||||||
"dfile", dfile,
|
"dfile", dfile,
|
||||||
"file", cfsh, "objfile", quoteShell(objfile), "options", options,
|
"file", cfsh, "objfile", quoteShell(objfile), "options", options,
|
||||||
"include", includeCmd, "nim", getPrefixDir(conf).string,
|
"include", includeCmd, "nim", getPrefixDir(conf).string,
|
||||||
"lib", conf.libpath.string])
|
"lib", conf.libpath.string,
|
||||||
|
"ccenvflags", envFlags(conf)])
|
||||||
|
|
||||||
if optProduceAsm in conf.globalOptions:
|
if optProduceAsm in conf.globalOptions:
|
||||||
if CC[conf.cCompiler].produceAsm.len > 0:
|
if CC[conf.cCompiler].produceAsm.len > 0:
|
||||||
|
|
@ -601,7 +614,8 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
|
||||||
"options", options, "include", includeCmd,
|
"options", options, "include", includeCmd,
|
||||||
"nim", quoteShell(getPrefixDir(conf)),
|
"nim", quoteShell(getPrefixDir(conf)),
|
||||||
"lib", quoteShell(conf.libpath),
|
"lib", quoteShell(conf.libpath),
|
||||||
"vccplatform", vccplatform(conf)])
|
"vccplatform", vccplatform(conf),
|
||||||
|
"ccenvflags", envFlags(conf)])
|
||||||
|
|
||||||
proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
|
proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
|
||||||
result = secureHash(
|
result = secureHash(
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ type
|
||||||
|
|
||||||
TSystemCC* = enum
|
TSystemCC* = enum
|
||||||
ccNone, ccGcc, ccNintendoSwitch, ccLLVM_Gcc, ccCLang, ccBcc, ccVcc,
|
ccNone, ccGcc, ccNintendoSwitch, ccLLVM_Gcc, ccCLang, ccBcc, ccVcc,
|
||||||
ccTcc, ccUcc, ccIcl, ccIcc, ccClangCl
|
ccTcc, ccEnv, ccIcl, ccIcc, ccClangCl
|
||||||
|
|
||||||
ExceptionSystem* = enum
|
ExceptionSystem* = enum
|
||||||
excNone, # no exception system selected yet
|
excNone, # no exception system selected yet
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,10 @@ add the ``-f`` flag to force all files to be recompiled.
|
||||||
The default compiler is defined at the top of ``config\nim.cfg``.
|
The default compiler is defined at the top of ``config\nim.cfg``.
|
||||||
Changing this setting affects the compiler used by ``koch`` to (re)build Nim.
|
Changing this setting affects the compiler used by ``koch`` to (re)build Nim.
|
||||||
|
|
||||||
|
To use the ``CC`` environment variable, use ``nim c --cc:env myfile.nim``. To use the
|
||||||
|
``CXX`` environment variable, use ``nim cpp --cc:env myfile.nim``. ``--cc:env`` is available
|
||||||
|
since Nim version 1.4.
|
||||||
|
|
||||||
|
|
||||||
Cross compilation
|
Cross compilation
|
||||||
=================
|
=================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue