summary refs log tree commit diff stats
path: root/rod
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-laptop>2010-04-05 19:47:18 +0200
committerAndreas Rumpf <andreas@andreas-laptop>2010-04-05 19:47:18 +0200
commite90665bff2e062598b51ada915c4861db6e94a8d (patch)
treed05a0cfdc7b0b9f84e9ed362eee21a17edab2373 /rod
parentb2ad7b30dc5866a92e239acfd6032e5fb005a240 (diff)
downloadNim-e90665bff2e062598b51ada915c4861db6e94a8d.tar.gz
crc check for external files to compile; bugfix: os.parseCmdLine
Diffstat (limited to 'rod')
-rwxr-xr-xrod/commands.nim7
-rwxr-xr-xrod/crc.nim13
-rwxr-xr-xrod/extccomp.nim65
-rwxr-xr-xrod/pragmas.nim2
4 files changed, 52 insertions, 35 deletions
diff --git a/rod/commands.nim b/rod/commands.nim
index 01b015b53..289f9c68e 100755
--- a/rod/commands.nim
+++ b/rod/commands.nim
@@ -216,11 +216,10 @@ proc processPath(path: string): string =
   result = UnixToNativePath(path % ["nimrod", getPrefixDir(), "lib", libpath])
 
 proc processCompile(filename: string) = 
-  var found, trunc: string
-  found = findFile(filename)
+  var found = findFile(filename)
   if found == "": found = filename
-  trunc = changeFileExt(found, "")
-  extccomp.addExternalFileToCompile(trunc)
+  var trunc = changeFileExt(found, "")
+  extccomp.addExternalFileToCompile(found)
   extccomp.addFileToLink(completeCFilePath(trunc, false))
 
 proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) = 
diff --git a/rod/crc.nim b/rod/crc.nim
index e66ce30fb..b397d5382 100755
--- a/rod/crc.nim
+++ b/rod/crc.nim
@@ -1,7 +1,7 @@
 #
 #
 #           The Nimrod Compiler
-#        (c) Copyright 2008 Andreas Rumpf
+#        (c) Copyright 2010 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -90,8 +90,7 @@ type
   PByteArray = ref TByteArray
 
 proc crcFromBuf(buf: Pointer, length: int): TCrc32 = 
-  var p: PByteArray
-  p = cast[PByteArray](buf)
+  var p = cast[PByteArray](buf)
   result = InitCrc32
   for i in countup(0, length - 1): result = updateCrc32(p[i], result)
   
@@ -117,10 +116,12 @@ proc crcFromFile(filename: string): TCrc32 =
 
 const 
   base = int32(65521) # largest prime smaller than 65536 
-                      #NMAX = 5552; original code with unsigned 32 bit integer 
-                      # NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 
+                      # NMAX = 5552; original code with unsigned 32 bit integer 
+                      # NMAX is the largest n 
+                      # such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 
   nmax = 3854 # code with signed 32 bit integer 
-              # NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^31-1 
+              # NMAX is the largest n such that 
+              # 255n(n+1)/2 + (n+1)(BASE-1) <= 2^31-1 
               # The penalty is the time loss in the extra MOD-calls. 
 
 proc updateAdler32(adler: int32, buf: pointer, length: int): int32 = 
diff --git a/rod/extccomp.nim b/rod/extccomp.nim
index 8d70bf16d..6ca816eb1 100755
--- a/rod/extccomp.nim
+++ b/rod/extccomp.nim
@@ -11,7 +11,7 @@
 # some things are read in from the configuration file
 
 import                        
-  lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs
+  lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc
 
 type 
   TSystemCC* = enum 
@@ -299,12 +299,30 @@ proc toObjFile(filenameWithoutExt: string): string =
 proc addFileToCompile(filename: string) = 
   appendStr(toCompile, filename)
 
+proc externalFileChanged(filename: string): bool = 
+  var crcFile = toGeneratedFile(filename, "crc")
+  var currentCrc = int(crcFromFile(filename))
+  var f: TFile
+  if open(f, crcFile, fmRead): 
+    var line = f.readLine()
+    if isNil(line) or line.len == 0: line = "0"
+    close(f)
+    var oldCrc = parseInt(line)
+    result = oldCrc != currentCrc
+  else:
+    result = true
+  if result: 
+    if open(f, crcFile, fmWrite):
+      f.writeln($currentCrc)
+      close(f)
+
 proc addExternalFileToCompile(filename: string) = 
-  appendStr(externalToCompile, filename)
+  if optForceFullMake in gGlobalOptions or externalFileChanged(filename):
+    appendStr(externalToCompile, changeFileExt(filename, ""))
 
 proc addFileToLink(filename: string) = 
-  prependStr(toLink, filename) # BUGFIX
-                               #appendStr(toLink, filename);
+  prependStr(toLink, filename) 
+  # BUGFIX: was ``appendStr``
   
 proc execExternalProgram(cmd: string) = 
   if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MessageOut(cmd)
@@ -361,8 +379,8 @@ proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
   key = cc[c].name & ".exe"
   if existsConfigVar(key): exe = getConfigVar(key)
   if targetOS == osWindows: exe = addFileExt(exe, "exe")
-  if (optGenDynLib in gGlobalOptions) and
-      (ospNeedsPIC in platform.OS[targetOS].props): 
+  if optGenDynLib in gGlobalOptions and
+      ospNeedsPIC in platform.OS[targetOS].props: 
     add(options, ' ' & cc[c].pic)
   if targetOS == platform.hostOS: 
     # compute include paths:
@@ -383,11 +401,11 @@ proc getCompileCFileCmd(cfilename: string, isExternal: bool = false): string =
       objfile, "options", options, "include", includeCmd, "nimrod", 
       getPrefixDir(), "lib", libpath]))
   add(result, ' ')
-  add(result, `%`(cc[c].compileTmpl, ["file", cfile, "objfile", objfile, 
-                                      "options", options, "include", includeCmd, 
-                                      "nimrod", 
-                                      quoteIfContainsWhite(getPrefixDir()), 
-                                      "lib", quoteIfContainsWhite(libpath)]))
+  addf(result, cc[c].compileTmpl, [
+    "file", cfile, "objfile", objfile, 
+    "options", options, "include", includeCmd, 
+    "nimrod", quoteIfContainsWhite(getPrefixDir()), 
+    "lib", quoteIfContainsWhite(libpath)])
 
 proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq, 
                   isExternal: bool) = 
@@ -396,7 +414,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
     inc(fileCounter)          # call the C compiler for the .c file:
     var compileCmd = getCompileCFileCmd(it.data, isExternal)
     if not (optCompileOnly in gGlobalOptions): 
-      add(cmds, compileCmd)   #execExternalProgram(compileCmd);
+      add(cmds, compileCmd)
     if (optGenScript in gGlobalOptions): 
       app(script, compileCmd)
       app(script, tnl)
@@ -405,7 +423,7 @@ proc CompileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
 proc CallCCompiler(projectfile: string) = 
   var 
     linkCmd, buildgui, builddll: string
-  if (gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}): 
+  if gGlobalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}: 
     return # speed up that call if only compiling and no script shall be
            # generated
   fileCounter = 0
@@ -414,7 +432,7 @@ proc CallCCompiler(projectfile: string) =
   var cmds: TStringSeq = @[]
   CompileCFile(toCompile, script, cmds, false)
   CompileCFile(externalToCompile, script, cmds, true)
-  if not (optCompileOnly in gGlobalOptions): 
+  if optCompileOnly notin gGlobalOptions: 
     if gNumberOfProcessors == 0: gNumberOfProcessors = countProcessors()
     var res = 0
     if gNumberOfProcessors <= 1: 
@@ -426,7 +444,7 @@ proc CallCCompiler(projectfile: string) =
       res = execProcesses(cmds, {poUseShell, poParentStreams}, 
                           gNumberOfProcessors)
     if res != 0: rawMessage(errExecutionOfProgramFailed, [])
-  if not (optNoLinking in gGlobalOptions): 
+  if optNoLinking notin gGlobalOptions: 
     # call the linker:
     var linkerExe = getConfigVar(cc[c].name & ".linkerexe")
     if len(linkerExe) == 0: linkerExe = cc[c].linkerExe
@@ -448,22 +466,21 @@ proc CallCCompiler(projectfile: string) =
     var it = PStrEntry(toLink.head)
     var objfiles = ""
     while it != nil: 
-      add(objfiles, " ")
+      add(objfiles, ' ')
       if targetOS == platform.hostOS: 
         add(objfiles, quoteIfContainsWhite(toObjfile(it.data)))
       else: 
         add(objfiles, quoteIfContainsWhite(toObjfile(extractFileName(it.data))))
       it = PStrEntry(it.next)
-    linkCmd = quoteIfContainsWhite(`%`(linkCmd, ["builddll", builddll, 
+    linkCmd = quoteIfContainsWhite(linkCmd % ["builddll", builddll, 
         "buildgui", buildgui, "options", linkOptions, "objfiles", objfiles, 
-        "exefile", exefile, "nimrod", getPrefixDir(), "lib", libpath]))
+        "exefile", exefile, "nimrod", getPrefixDir(), "lib", libpath])
     add(linkCmd, ' ')
-    add(linkCmd, `%`(cc[c].linkTmpl, ["builddll", builddll, "buildgui", 
-                                      buildgui, "options", linkOptions, 
-                                      "objfiles", objfiles, "exefile", exefile, 
-                                      "nimrod", 
-                                      quoteIfContainsWhite(getPrefixDir()), 
-                                      "lib", quoteIfContainsWhite(libpath)]))
+    addf(linkCmd, cc[c].linkTmpl, ["builddll", builddll, 
+        "buildgui", buildgui, "options", linkOptions, 
+        "objfiles", objfiles, "exefile", exefile, 
+        "nimrod", quoteIfContainsWhite(getPrefixDir()), 
+        "lib", quoteIfContainsWhite(libpath)])
     if not (optCompileOnly in gGlobalOptions): execExternalProgram(linkCmd)
   else: 
     linkCmd = ""
diff --git a/rod/pragmas.nim b/rod/pragmas.nim
index 02411ee52..28e4b2a7b 100755
--- a/rod/pragmas.nim
+++ b/rod/pragmas.nim
@@ -299,7 +299,7 @@ proc processCompile(c: PContext, n: PNode) =
   var found = findFile(s)
   if found == "": found = s
   var trunc = ChangeFileExt(found, "")
-  extccomp.addExternalFileToCompile(trunc)
+  extccomp.addExternalFileToCompile(found)
   extccomp.addFileToLink(completeCFilePath(trunc, false))
 
 proc processCommonLink(c: PContext, n: PNode, feature: TLinkFeature) =