@@ -231,21 +231,6 @@ const # the used compiler
231
231
var cExt* : string = " c" # extension of generated C/C++ files
232
232
# (can be changed to .cpp later)
233
233
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 )
249
234
# implementation
250
235
251
236
var
254
239
compileOptions: string = " "
255
240
ccompilerpath: string = " "
256
241
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 ) =
258
249
ccompiler = nameToCC (ccname)
259
250
if ccompiler == ccNone: rawMessage (errUnknownCcompiler, ccname)
260
251
compileOptions = getConfigVar (CC [ccompiler].name & " .options.always" )
@@ -263,7 +254,18 @@ proc setCC(ccname: string) =
263
254
for i in countup (low (CC ), high (CC )): undefSymbol (CC [i].name)
264
255
defineSymbol (CC [ccompiler].name)
265
256
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 * () =
267
269
# we need to define the symbol here, because ``CC`` may have never been set!
268
270
for i in countup (low (CC ), high (CC )): undefSymbol (CC [i].name)
269
271
defineSymbol (CC [ccompiler].name)
@@ -272,32 +274,15 @@ proc initVars() =
272
274
addLinkOption (getConfigVar (CC [ccompiler].name & " .options.linker" ))
273
275
if len (ccompilerPath) == 0 :
274
276
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
284
277
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)
288
280
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)
299
284
300
- proc addFileToCompile (filename: string ) =
285
+ proc addFileToCompile * (filename: string ) =
301
286
appendStr (toCompile, filename)
302
287
303
288
proc footprint (filename: string ): TCrc32 =
@@ -323,18 +308,18 @@ proc externalFileChanged(filename: string): bool =
323
308
f.writeln ($ currentCrc)
324
309
close (f)
325
310
326
- proc addExternalFileToCompile (filename: string ) =
311
+ proc addExternalFileToCompile * (filename: string ) =
327
312
if optForceFullMake in gGlobalOptions or externalFileChanged (filename):
328
- appendStr (externalToCompile, changeFileExt ( filename, " " ) )
313
+ appendStr (externalToCompile, filename)
329
314
330
- proc addFileToLink (filename: string ) =
315
+ proc addFileToLink * (filename: string ) =
331
316
prependStr (toLink, filename)
332
317
# BUGFIX: was ``appendStr``
333
-
334
- proc execExternalProgram (cmd: string ) =
318
+
319
+ proc execExternalProgram * (cmd: string ) =
335
320
if (optListCmd in gGlobalOptions) or (gVerbosity > 0 ): MessageOut (cmd)
336
321
if execCmd (cmd) != 0 : rawMessage (errExecutionOfProgramFailed, " " )
337
-
322
+
338
323
proc generateScript (projectFile: string , script: PRope ) =
339
324
var (dir, name, ext) = splitFile (projectFile)
340
325
WriteRope (script, dir / addFileExt (" compile_" & name,
@@ -344,24 +329,24 @@ proc getOptSpeed(c: TSystemCC): string =
344
329
result = getConfigVar (cc[c].name & " .options.speed" )
345
330
if result == " " :
346
331
result = cc[c].optSpeed # use default settings from this file
347
-
332
+
348
333
proc getDebug (c: TSystemCC ): string =
349
334
result = getConfigVar (cc[c].name & " .options.debug" )
350
335
if result == " " :
351
336
result = cc[c].debug # use default settings from this file
352
-
337
+
353
338
proc getOptSize (c: TSystemCC ): string =
354
339
result = getConfigVar (cc[c].name & " .options.size" )
355
340
if result == " " :
356
341
result = cc[c].optSize # use default settings from this file
357
-
342
+
358
343
const
359
344
specialFileA = 42
360
345
specialFileB = 42
361
346
362
347
var fileCounter: int
363
348
364
- proc getCompileCFileCmd (cfilename: string , isExternal: bool = false ): string =
349
+ proc getCompileCFileCmd * (cfilename: string , isExternal: bool = false ): string =
365
350
var
366
351
cfile, objfile, options, includeCmd, compilePattern, key, trunk, exe: string
367
352
var c = ccompiler
@@ -427,7 +412,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
427
412
app (script, tnl)
428
413
it = PStrEntry (it.next)
429
414
430
- proc CallCCompiler (projectfile: string ) =
415
+ proc CallCCompiler * (projectfile: string ) =
431
416
var
432
417
linkCmd, buildgui, builddll: string
433
418
if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
@@ -475,9 +460,9 @@ proc CallCCompiler(projectfile: string) =
475
460
while it != nil :
476
461
add (objfiles, ' ' )
477
462
if targetOS == platform.hostOS :
478
- add (objfiles, quoteIfContainsWhite (toObjfile (it.data)))
463
+ add (objfiles, quoteIfContainsWhite (addFileExt (it.data, cc[ccompiler].objExt )))
479
464
else :
480
- add (objfiles, quoteIfContainsWhite (toObjfile ( extractFileName ( it.data) )))
465
+ add (objfiles, quoteIfContainsWhite (addFileExt ( it.data, cc[ccompiler].objExt )))
481
466
it = PStrEntry (it.next)
482
467
linkCmd = quoteIfContainsWhite (linkCmd % [" builddll" , builddll,
483
468
" buildgui" , buildgui, " options" , linkOptions, " objfiles" , objfiles,
@@ -502,7 +487,7 @@ proc genMappingFiles(list: TLinkedList): PRope =
502
487
appf (result , " --file:r\" $1\" $n" , [toRope (AddFileExt (it.data, cExt))])
503
488
it = PStrEntry (it.next)
504
489
505
- proc writeMapping (gSymbolMapping: PRope ) =
490
+ proc writeMapping * (gSymbolMapping: PRope ) =
506
491
if optGenMapping notin gGlobalOptions: return
507
492
var code = toRope (" [C_Files]\n " )
508
493
app (code, genMappingFiles (toCompile))
0 commit comments