fixes #5, also cleaned up extccomp a bit.
This commit is contained in:
parent
da325bc7a4
commit
df86dc5874
2 changed files with 40 additions and 55 deletions
|
|
@ -231,21 +231,6 @@ const # the used compiler
|
||||||
var cExt*: string = "c" # extension of generated C/C++ files
|
var cExt*: string = "c" # extension of generated C/C++ files
|
||||||
# (can be changed to .cpp later)
|
# (can be changed to .cpp later)
|
||||||
|
|
||||||
proc completeCFilePath*(cfile: string, createSubDir: bool = true): string
|
|
||||||
|
|
||||||
proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string
|
|
||||||
proc addFileToCompile*(filename: string)
|
|
||||||
proc addExternalFileToCompile*(filename: string)
|
|
||||||
proc addFileToLink*(filename: string)
|
|
||||||
proc addCompileOption*(option: string)
|
|
||||||
proc addLinkOption*(option: string)
|
|
||||||
proc toObjFile*(filenameWithoutExt: string): string
|
|
||||||
proc CallCCompiler*(projectFile: string)
|
|
||||||
proc execExternalProgram*(cmd: string)
|
|
||||||
proc NameToCC*(name: string): TSystemCC
|
|
||||||
proc initVars*()
|
|
||||||
proc setCC*(ccname: string)
|
|
||||||
proc writeMapping*(gSymbolMapping: PRope)
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -254,7 +239,13 @@ var
|
||||||
compileOptions: string = ""
|
compileOptions: string = ""
|
||||||
ccompilerpath: string = ""
|
ccompilerpath: string = ""
|
||||||
|
|
||||||
proc setCC(ccname: string) =
|
proc NameToCC*(name: string): TSystemCC =
|
||||||
|
for i in countup(succ(ccNone), high(TSystemCC)):
|
||||||
|
if cmpIgnoreStyle(name, CC[i].name) == 0:
|
||||||
|
return i
|
||||||
|
result = ccNone
|
||||||
|
|
||||||
|
proc setCC*(ccname: string) =
|
||||||
ccompiler = nameToCC(ccname)
|
ccompiler = nameToCC(ccname)
|
||||||
if ccompiler == ccNone: rawMessage(errUnknownCcompiler, ccname)
|
if ccompiler == ccNone: rawMessage(errUnknownCcompiler, ccname)
|
||||||
compileOptions = getConfigVar(CC[ccompiler].name & ".options.always")
|
compileOptions = getConfigVar(CC[ccompiler].name & ".options.always")
|
||||||
|
|
@ -263,7 +254,18 @@ proc setCC(ccname: string) =
|
||||||
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
|
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
|
||||||
defineSymbol(CC[ccompiler].name)
|
defineSymbol(CC[ccompiler].name)
|
||||||
|
|
||||||
proc initVars() =
|
proc addOpt(dest: var string, src: string) =
|
||||||
|
if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
|
||||||
|
add(dest, src)
|
||||||
|
|
||||||
|
proc addLinkOption*(option: string) =
|
||||||
|
if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
|
||||||
|
|
||||||
|
proc addCompileOption*(option: string) =
|
||||||
|
if strutils.find(compileOptions, option, 0) < 0:
|
||||||
|
addOpt(compileOptions, option)
|
||||||
|
|
||||||
|
proc initVars*() =
|
||||||
# we need to define the symbol here, because ``CC`` may have never been set!
|
# we need to define the symbol here, because ``CC`` may have never been set!
|
||||||
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
|
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
|
||||||
defineSymbol(CC[ccompiler].name)
|
defineSymbol(CC[ccompiler].name)
|
||||||
|
|
@ -273,31 +275,14 @@ proc initVars() =
|
||||||
if len(ccompilerPath) == 0:
|
if len(ccompilerPath) == 0:
|
||||||
ccompilerpath = getConfigVar(CC[ccompiler].name & ".path")
|
ccompilerpath = getConfigVar(CC[ccompiler].name & ".path")
|
||||||
|
|
||||||
proc completeCFilePath(cfile: string, createSubDir: bool = true): string =
|
proc completeCFilePath*(cfile: string, createSubDir: bool = true): string =
|
||||||
result = completeGeneratedFilePath(cfile, createSubDir)
|
result = completeGeneratedFilePath(cfile, createSubDir)
|
||||||
|
|
||||||
proc NameToCC(name: string): TSystemCC =
|
proc toObjFile*(filenameWithoutExt: string): string =
|
||||||
for i in countup(succ(ccNone), high(TSystemCC)):
|
# Object file for compilation
|
||||||
if cmpIgnoreStyle(name, CC[i].name) == 0:
|
result = changeFileExt(filenameWithoutExt, cc[ccompiler].objExt)
|
||||||
return i
|
|
||||||
result = ccNone
|
|
||||||
|
|
||||||
proc addOpt(dest: var string, src: string) =
|
proc addFileToCompile*(filename: string) =
|
||||||
if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
|
|
||||||
add(dest, src)
|
|
||||||
|
|
||||||
proc addCompileOption(option: string) =
|
|
||||||
if strutils.find(compileOptions, option, 0) < 0:
|
|
||||||
addOpt(compileOptions, option)
|
|
||||||
|
|
||||||
proc addLinkOption(option: string) =
|
|
||||||
if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
|
|
||||||
|
|
||||||
proc toObjFile(filenameWithoutExt: string): string =
|
|
||||||
# BUGFIX: changeFileExt is wrong, use addFileExt!
|
|
||||||
result = addFileExt(filenameWithoutExt, cc[ccompiler].objExt)
|
|
||||||
|
|
||||||
proc addFileToCompile(filename: string) =
|
|
||||||
appendStr(toCompile, filename)
|
appendStr(toCompile, filename)
|
||||||
|
|
||||||
proc footprint(filename: string): TCrc32 =
|
proc footprint(filename: string): TCrc32 =
|
||||||
|
|
@ -323,15 +308,15 @@ proc externalFileChanged(filename: string): bool =
|
||||||
f.writeln($currentCrc)
|
f.writeln($currentCrc)
|
||||||
close(f)
|
close(f)
|
||||||
|
|
||||||
proc addExternalFileToCompile(filename: string) =
|
proc addExternalFileToCompile*(filename: string) =
|
||||||
if optForceFullMake in gGlobalOptions or externalFileChanged(filename):
|
if optForceFullMake in gGlobalOptions or externalFileChanged(filename):
|
||||||
appendStr(externalToCompile, changeFileExt(filename, ""))
|
appendStr(externalToCompile, filename)
|
||||||
|
|
||||||
proc addFileToLink(filename: string) =
|
proc addFileToLink*(filename: string) =
|
||||||
prependStr(toLink, filename)
|
prependStr(toLink, filename)
|
||||||
# BUGFIX: was ``appendStr``
|
# BUGFIX: was ``appendStr``
|
||||||
|
|
||||||
proc execExternalProgram(cmd: string) =
|
proc execExternalProgram*(cmd: string) =
|
||||||
if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MessageOut(cmd)
|
if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MessageOut(cmd)
|
||||||
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
|
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
|
||||||
|
|
||||||
|
|
@ -361,7 +346,7 @@ const
|
||||||
|
|
||||||
var fileCounter: int
|
var fileCounter: int
|
||||||
|
|
||||||
proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
|
proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string =
|
||||||
var
|
var
|
||||||
cfile, objfile, options, includeCmd, compilePattern, key, trunk, exe: string
|
cfile, objfile, options, includeCmd, compilePattern, key, trunk, exe: string
|
||||||
var c = ccompiler
|
var c = ccompiler
|
||||||
|
|
@ -427,7 +412,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
|
||||||
app(script, tnl)
|
app(script, tnl)
|
||||||
it = PStrEntry(it.next)
|
it = PStrEntry(it.next)
|
||||||
|
|
||||||
proc CallCCompiler(projectfile: string) =
|
proc CallCCompiler*(projectfile: string) =
|
||||||
var
|
var
|
||||||
linkCmd, buildgui, builddll: string
|
linkCmd, buildgui, builddll: string
|
||||||
if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
|
if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
|
||||||
|
|
@ -475,9 +460,9 @@ proc CallCCompiler(projectfile: string) =
|
||||||
while it != nil:
|
while it != nil:
|
||||||
add(objfiles, ' ')
|
add(objfiles, ' ')
|
||||||
if targetOS == platform.hostOS:
|
if targetOS == platform.hostOS:
|
||||||
add(objfiles, quoteIfContainsWhite(toObjfile(it.data)))
|
add(objfiles, quoteIfContainsWhite(addFileExt(it.data, cc[ccompiler].objExt)))
|
||||||
else:
|
else:
|
||||||
add(objfiles, quoteIfContainsWhite(toObjfile(extractFileName(it.data))))
|
add(objfiles, quoteIfContainsWhite(addFileExt(it.data, cc[ccompiler].objExt)))
|
||||||
it = PStrEntry(it.next)
|
it = PStrEntry(it.next)
|
||||||
linkCmd = quoteIfContainsWhite(linkCmd % ["builddll", builddll,
|
linkCmd = quoteIfContainsWhite(linkCmd % ["builddll", builddll,
|
||||||
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
|
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
|
||||||
|
|
@ -502,7 +487,7 @@ proc genMappingFiles(list: TLinkedList): PRope =
|
||||||
appf(result, "--file:r\"$1\"$n", [toRope(AddFileExt(it.data, cExt))])
|
appf(result, "--file:r\"$1\"$n", [toRope(AddFileExt(it.data, cExt))])
|
||||||
it = PStrEntry(it.next)
|
it = PStrEntry(it.next)
|
||||||
|
|
||||||
proc writeMapping(gSymbolMapping: PRope) =
|
proc writeMapping*(gSymbolMapping: PRope) =
|
||||||
if optGenMapping notin gGlobalOptions: return
|
if optGenMapping notin gGlobalOptions: return
|
||||||
var code = toRope("[C_Files]\n")
|
var code = toRope("[C_Files]\n")
|
||||||
app(code, genMappingFiles(toCompile))
|
app(code, genMappingFiles(toCompile))
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ proc processCompile(c: PContext, n: PNode) =
|
||||||
|
|
||||||
proc processCommonLink(c: PContext, n: PNode, feature: TLinkFeature) =
|
proc processCommonLink(c: PContext, n: PNode, feature: TLinkFeature) =
|
||||||
var f = expectStrLit(c, n)
|
var f = expectStrLit(c, n)
|
||||||
if splitFile(f).ext == "": f = toObjFile(f)
|
if splitFile(f).ext == "": f = addFileExt(f, cc[ccompiler].objExt)
|
||||||
var found = findFile(f)
|
var found = findFile(f)
|
||||||
if found == "": found = f # use the default
|
if found == "": found = f # use the default
|
||||||
case feature
|
case feature
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue