Skip to content

Commit d50bb60

Browse files
committed
fixes #5, also cleaned up extccomp a bit.
1 parent 8e6d341 commit d50bb60

File tree

2 files changed

+40
-55
lines changed

2 files changed

+40
-55
lines changed

rod/extccomp.nim

+39-54
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,6 @@ const # the used compiler
231231
var cExt*: string = "c" # extension of generated C/C++ files
232232
# (can be changed to .cpp later)
233233

234-
proc completeCFilePath*(cfile: string, createSubDir: bool = true): string
235-
236-
proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string
237-
proc addFileToCompile*(filename: string)
238-
proc addExternalFileToCompile*(filename: string)
239-
proc addFileToLink*(filename: string)
240-
proc addCompileOption*(option: string)
241-
proc addLinkOption*(option: string)
242-
proc toObjFile*(filenameWithoutExt: string): string
243-
proc CallCCompiler*(projectFile: string)
244-
proc execExternalProgram*(cmd: string)
245-
proc NameToCC*(name: string): TSystemCC
246-
proc initVars*()
247-
proc setCC*(ccname: string)
248-
proc writeMapping*(gSymbolMapping: PRope)
249234
# implementation
250235

251236
var
@@ -254,7 +239,13 @@ var
254239
compileOptions: string = ""
255240
ccompilerpath: string = ""
256241

257-
proc setCC(ccname: string) =
242+
proc NameToCC*(name: string): TSystemCC =
243+
for i in countup(succ(ccNone), high(TSystemCC)):
244+
if cmpIgnoreStyle(name, CC[i].name) == 0:
245+
return i
246+
result = ccNone
247+
248+
proc setCC*(ccname: string) =
258249
ccompiler = nameToCC(ccname)
259250
if ccompiler == ccNone: rawMessage(errUnknownCcompiler, ccname)
260251
compileOptions = getConfigVar(CC[ccompiler].name & ".options.always")
@@ -263,7 +254,18 @@ proc setCC(ccname: string) =
263254
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
264255
defineSymbol(CC[ccompiler].name)
265256

266-
proc initVars() =
257+
proc addOpt(dest: var string, src: string) =
258+
if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
259+
add(dest, src)
260+
261+
proc addLinkOption*(option: string) =
262+
if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
263+
264+
proc addCompileOption*(option: string) =
265+
if strutils.find(compileOptions, option, 0) < 0:
266+
addOpt(compileOptions, option)
267+
268+
proc initVars*() =
267269
# we need to define the symbol here, because ``CC`` may have never been set!
268270
for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
269271
defineSymbol(CC[ccompiler].name)
@@ -272,32 +274,15 @@ proc initVars() =
272274
addLinkOption(getConfigVar(CC[ccompiler].name & ".options.linker"))
273275
if len(ccompilerPath) == 0:
274276
ccompilerpath = getConfigVar(CC[ccompiler].name & ".path")
275-
276-
proc completeCFilePath(cfile: string, createSubDir: bool = true): string =
277-
result = completeGeneratedFilePath(cfile, createSubDir)
278-
279-
proc NameToCC(name: string): TSystemCC =
280-
for i in countup(succ(ccNone), high(TSystemCC)):
281-
if cmpIgnoreStyle(name, CC[i].name) == 0:
282-
return i
283-
result = ccNone
284277

285-
proc addOpt(dest: var string, src: string) =
286-
if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
287-
add(dest, src)
278+
proc completeCFilePath*(cfile: string, createSubDir: bool = true): string =
279+
result = completeGeneratedFilePath(cfile, createSubDir)
288280

289-
proc addCompileOption(option: string) =
290-
if strutils.find(compileOptions, option, 0) < 0:
291-
addOpt(compileOptions, option)
292-
293-
proc addLinkOption(option: string) =
294-
if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
295-
296-
proc toObjFile(filenameWithoutExt: string): string =
297-
# BUGFIX: changeFileExt is wrong, use addFileExt!
298-
result = addFileExt(filenameWithoutExt, cc[ccompiler].objExt)
281+
proc toObjFile*(filenameWithoutExt: string): string =
282+
# Object file for compilation
283+
result = changeFileExt(filenameWithoutExt, cc[ccompiler].objExt)
299284

300-
proc addFileToCompile(filename: string) =
285+
proc addFileToCompile*(filename: string) =
301286
appendStr(toCompile, filename)
302287

303288
proc footprint(filename: string): TCrc32 =
@@ -323,18 +308,18 @@ proc externalFileChanged(filename: string): bool =
323308
f.writeln($currentCrc)
324309
close(f)
325310

326-
proc addExternalFileToCompile(filename: string) =
311+
proc addExternalFileToCompile*(filename: string) =
327312
if optForceFullMake in gGlobalOptions or externalFileChanged(filename):
328-
appendStr(externalToCompile, changeFileExt(filename, ""))
313+
appendStr(externalToCompile, filename)
329314

330-
proc addFileToLink(filename: string) =
315+
proc addFileToLink*(filename: string) =
331316
prependStr(toLink, filename)
332317
# BUGFIX: was ``appendStr``
333-
334-
proc execExternalProgram(cmd: string) =
318+
319+
proc execExternalProgram*(cmd: string) =
335320
if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MessageOut(cmd)
336321
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
337-
322+
338323
proc generateScript(projectFile: string, script: PRope) =
339324
var (dir, name, ext) = splitFile(projectFile)
340325
WriteRope(script, dir / addFileExt("compile_" & name,
@@ -344,24 +329,24 @@ proc getOptSpeed(c: TSystemCC): string =
344329
result = getConfigVar(cc[c].name & ".options.speed")
345330
if result == "":
346331
result = cc[c].optSpeed # use default settings from this file
347-
332+
348333
proc getDebug(c: TSystemCC): string =
349334
result = getConfigVar(cc[c].name & ".options.debug")
350335
if result == "":
351336
result = cc[c].debug # use default settings from this file
352-
337+
353338
proc getOptSize(c: TSystemCC): string =
354339
result = getConfigVar(cc[c].name & ".options.size")
355340
if result == "":
356341
result = cc[c].optSize # use default settings from this file
357-
342+
358343
const
359344
specialFileA = 42
360345
specialFileB = 42
361346

362347
var fileCounter: int
363348

364-
proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
349+
proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string =
365350
var
366351
cfile, objfile, options, includeCmd, compilePattern, key, trunk, exe: string
367352
var c = ccompiler
@@ -427,7 +412,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
427412
app(script, tnl)
428413
it = PStrEntry(it.next)
429414

430-
proc CallCCompiler(projectfile: string) =
415+
proc CallCCompiler*(projectfile: string) =
431416
var
432417
linkCmd, buildgui, builddll: string
433418
if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
@@ -475,9 +460,9 @@ proc CallCCompiler(projectfile: string) =
475460
while it != nil:
476461
add(objfiles, ' ')
477462
if targetOS == platform.hostOS:
478-
add(objfiles, quoteIfContainsWhite(toObjfile(it.data)))
463+
add(objfiles, quoteIfContainsWhite(addFileExt(it.data, cc[ccompiler].objExt)))
479464
else:
480-
add(objfiles, quoteIfContainsWhite(toObjfile(extractFileName(it.data))))
465+
add(objfiles, quoteIfContainsWhite(addFileExt(it.data, cc[ccompiler].objExt)))
481466
it = PStrEntry(it.next)
482467
linkCmd = quoteIfContainsWhite(linkCmd % ["builddll", builddll,
483468
"buildgui", buildgui, "options", linkOptions, "objfiles", objfiles,
@@ -502,7 +487,7 @@ proc genMappingFiles(list: TLinkedList): PRope =
502487
appf(result, "--file:r\"$1\"$n", [toRope(AddFileExt(it.data, cExt))])
503488
it = PStrEntry(it.next)
504489

505-
proc writeMapping(gSymbolMapping: PRope) =
490+
proc writeMapping*(gSymbolMapping: PRope) =
506491
if optGenMapping notin gGlobalOptions: return
507492
var code = toRope("[C_Files]\n")
508493
app(code, genMappingFiles(toCompile))

rod/pragmas.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ proc processCompile(c: PContext, n: PNode) =
305305

306306
proc processCommonLink(c: PContext, n: PNode, feature: TLinkFeature) =
307307
var f = expectStrLit(c, n)
308-
if splitFile(f).ext == "": f = toObjFile(f)
308+
if splitFile(f).ext == "": f = addFileExt(f, cc[ccompiler].objExt)
309309
var found = findFile(f)
310310
if found == "": found = f # use the default
311311
case feature

0 commit comments

Comments
 (0)