Guest User

Untitled

a guest
Jul 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. diff --git a/rod/extccomp.nim b/rod/extccomp.nim
  2. index 0f36d08..fa034ff 100644
  3. --- a/rod/extccomp.nim
  4. +++ b/rod/extccomp.nim
  5. @@ -231,21 +231,6 @@ const # the used compiler
  6. var cExt*: string = "c" # extension of generated C/C++ files
  7. # (can be changed to .cpp later)
  8.  
  9. -proc completeCFilePath*(cfile: string, createSubDir: bool = true): string
  10. -
  11. -proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string
  12. -proc addFileToCompile*(filename: string)
  13. -proc addExternalFileToCompile*(filename: string)
  14. -proc addFileToLink*(filename: string)
  15. -proc addCompileOption*(option: string)
  16. -proc addLinkOption*(option: string)
  17. -proc toObjFile*(filenameWithoutExt: string): string
  18. -proc CallCCompiler*(projectFile: string)
  19. -proc execExternalProgram*(cmd: string)
  20. -proc NameToCC*(name: string): TSystemCC
  21. -proc initVars*()
  22. -proc setCC*(ccname: string)
  23. -proc writeMapping*(gSymbolMapping: PRope)
  24. # implementation
  25.  
  26. var
  27. @@ -254,7 +239,13 @@ var
  28. compileOptions: string = ""
  29. ccompilerpath: string = ""
  30.  
  31. -proc setCC(ccname: string) =
  32. +proc NameToCC*(name: string): TSystemCC =
  33. + for i in countup(succ(ccNone), high(TSystemCC)):
  34. + if cmpIgnoreStyle(name, CC[i].name) == 0:
  35. + return i
  36. + result = ccNone
  37. +
  38. +proc setCC*(ccname: string) =
  39. ccompiler = nameToCC(ccname)
  40. if ccompiler == ccNone: rawMessage(errUnknownCcompiler, ccname)
  41. compileOptions = getConfigVar(CC[ccompiler].name & ".options.always")
  42. @@ -263,7 +254,18 @@ proc setCC(ccname: string) =
  43. for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
  44. defineSymbol(CC[ccompiler].name)
  45.  
  46. -proc initVars() =
  47. +proc addOpt(dest: var string, src: string) =
  48. + if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
  49. + add(dest, src)
  50. +
  51. +proc addLinkOption*(option: string) =
  52. + if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
  53. +
  54. +proc addCompileOption*(option: string) =
  55. + if strutils.find(compileOptions, option, 0) < 0:
  56. + addOpt(compileOptions, option)
  57. +
  58. +proc initVars*() =
  59. # we need to define the symbol here, because ``CC`` may have never been set!
  60. for i in countup(low(CC), high(CC)): undefSymbol(CC[i].name)
  61. defineSymbol(CC[ccompiler].name)
  62. @@ -272,32 +274,19 @@ proc initVars() =
  63. addLinkOption(getConfigVar(CC[ccompiler].name & ".options.linker"))
  64. if len(ccompilerPath) == 0:
  65. ccompilerpath = getConfigVar(CC[ccompiler].name & ".path")
  66. -
  67. -proc completeCFilePath(cfile: string, createSubDir: bool = true): string =
  68. - result = completeGeneratedFilePath(cfile, createSubDir)
  69.  
  70. -proc NameToCC(name: string): TSystemCC =
  71. - for i in countup(succ(ccNone), high(TSystemCC)):
  72. - if cmpIgnoreStyle(name, CC[i].name) == 0:
  73. - return i
  74. - result = ccNone
  75. +proc completeCFilePath*(cfile: string, createSubDir: bool = true): string =
  76. + result = completeGeneratedFilePath(cfile, createSubDir)
  77.  
  78. -proc addOpt(dest: var string, src: string) =
  79. - if len(dest) == 0 or dest[len(dest) - 1 + 0] != ' ': add(dest, " ")
  80. - add(dest, src)
  81. +proc toObjFileCompile*(filenameWithoutExt: string): string =
  82. + # Object file for compilation
  83. + result = changeFileExt(filenameWithoutExt, cc[ccompiler].objExt)
  84.  
  85. -proc addCompileOption(option: string) =
  86. - if strutils.find(compileOptions, option, 0) < 0:
  87. - addOpt(compileOptions, option)
  88. -
  89. -proc addLinkOption(option: string) =
  90. - if find(linkOptions, option, 0) < 0: addOpt(linkOptions, option)
  91. -
  92. -proc toObjFile(filenameWithoutExt: string): string =
  93. - # BUGFIX: changeFileExt is wrong, use addFileExt!
  94. - result = addFileExt(filenameWithoutExt, cc[ccompiler].objExt)
  95. +proc toObjFile*(filenameWithoutExt: string): string =
  96. + # Object file for linking
  97. + result = changeFileExt(filenameWithoutExt, cc[ccompiler].objExt)
  98.  
  99. -proc addFileToCompile(filename: string) =
  100. +proc addFileToCompile*(filename: string) =
  101. appendStr(toCompile, filename)
  102.  
  103. proc footprint(filename: string): TCrc32 =
  104. @@ -323,18 +312,18 @@ proc externalFileChanged(filename: string): bool =
  105. f.writeln($currentCrc)
  106. close(f)
  107.  
  108. -proc addExternalFileToCompile(filename: string) =
  109. +proc addExternalFileToCompile*(filename: string) =
  110. if optForceFullMake in gGlobalOptions or externalFileChanged(filename):
  111. - appendStr(externalToCompile, changeFileExt(filename, ""))
  112. + appendStr(externalToCompile, filename)
  113.  
  114. -proc addFileToLink(filename: string) =
  115. +proc addFileToLink*(filename: string) =
  116. prependStr(toLink, filename)
  117. # BUGFIX: was ``appendStr``
  118. -
  119. -proc execExternalProgram(cmd: string) =
  120. +
  121. +proc execExternalProgram*(cmd: string) =
  122. if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MessageOut(cmd)
  123. if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
  124. -
  125. +
  126. proc generateScript(projectFile: string, script: PRope) =
  127. var (dir, name, ext) = splitFile(projectFile)
  128. WriteRope(script, dir / addFileExt("compile_" & name,
  129. @@ -344,24 +333,24 @@ proc getOptSpeed(c: TSystemCC): string =
  130. result = getConfigVar(cc[c].name & ".options.speed")
  131. if result == "":
  132. result = cc[c].optSpeed # use default settings from this file
  133. -
  134. +
  135. proc getDebug(c: TSystemCC): string =
  136. result = getConfigVar(cc[c].name & ".options.debug")
  137. if result == "":
  138. result = cc[c].debug # use default settings from this file
  139. -
  140. +
  141. proc getOptSize(c: TSystemCC): string =
  142. result = getConfigVar(cc[c].name & ".options.size")
  143. if result == "":
  144. result = cc[c].optSize # use default settings from this file
  145. -
  146. +
  147. const
  148. specialFileA = 42
  149. specialFileB = 42
  150.  
  151. var fileCounter: int
  152.  
  153. -proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
  154. +proc getCompileCFileCmd*(cfilename: string, isExternal: bool = false): string =
  155. var
  156. cfile, objfile, options, includeCmd, compilePattern, key, trunk, exe: string
  157. var c = ccompiler
  158. @@ -400,8 +389,8 @@ proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
  159. compilePattern = cc[c].compilerExe
  160. if targetOS == platform.hostOS: cfile = cfilename
  161. else: cfile = extractFileName(cfilename)
  162. - if not isExternal or targetOS != platform.hostOS: objfile = toObjFile(cfile)
  163. - else: objfile = completeCFilePath(toObjFile(cfile))
  164. + if not isExternal or targetOS != platform.hostOS: objfile = toObjFileCompile(cfile)
  165. + else: objfile = completeCFilePath(toObjFileCompile(cfile))
  166. cfile = quoteIfContainsWhite(AddFileExt(cfile, cExt))
  167. objfile = quoteIfContainsWhite(objfile)
  168. result = quoteIfContainsWhite(`%`(compilePattern, ["file", cfile, "objfile",
  169. @@ -427,7 +416,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
  170. app(script, tnl)
  171. it = PStrEntry(it.next)
  172.  
  173. -proc CallCCompiler(projectfile: string) =
  174. +proc CallCCompiler*(projectfile: string) =
  175. var
  176. linkCmd, buildgui, builddll: string
  177. if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
  178. @@ -502,7 +491,7 @@ proc genMappingFiles(list: TLinkedList): PRope =
  179. appf(result, "--file:r\"$1\"$n", [toRope(AddFileExt(it.data, cExt))])
  180. it = PStrEntry(it.next)
  181.  
  182. -proc writeMapping(gSymbolMapping: PRope) =
  183. +proc writeMapping*(gSymbolMapping: PRope) =
  184. if optGenMapping notin gGlobalOptions: return
  185. var code = toRope("[C_Files]\n")
  186. app(code, genMappingFiles(toCompile))
Add Comment
Please, Sign In to add comment