summary refs log tree commit diff stats
path: root/boot.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2009-04-22 16:12:19 +0200
committerAndreas Rumpf <rumpf_a@web.de>2009-04-22 16:12:19 +0200
commit08bc9ac03c49db7bfcdee82f46aadf95a324e015 (patch)
treed266022435c53e386162814c566248123653ca59 /boot.nim
parente792940f5273bf8f8761c4cb29b241445e8b1d0b (diff)
downloadNim-08bc9ac03c49db7bfcdee82f46aadf95a324e015.tar.gz
version 0.7.6
Diffstat (limited to 'boot.nim')
-rw-r--r--boot.nim67
1 files changed, 67 insertions, 0 deletions
diff --git a/boot.nim b/boot.nim
new file mode 100644
index 000000000..7b1745391
--- /dev/null
+++ b/boot.nim
@@ -0,0 +1,67 @@
+#
+#
+#             Nimrod Bootstrap Program
+#        (c) Copyright 2009 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+import
+  os, strutils
+
+const
+  BootCmd = "nimrod cc --compile:build/platdef.c $1 rod/nimrod.nim"
+  PlatdefCTmpl = """
+/* Generated by boot.nim */
+char* nimOS(void) { return "$1"; }
+char* nimCPU(void) { return "$2"; }
+"""
+
+proc exec(cmd: string) =
+  echo(cmd)
+  if executeShellCommand(cmd) != 0: quit("FAILURE")
+
+proc writePlatdefC =
+  var f: TFile
+  if openFile(f, "build/platdef.c", fmWrite): 
+    write(f, PlatdefcTmpl % [system.hostOS, system.hostCPU])
+    closeFile(f)
+  else:
+    quit("Cannot write 'build/platdef.c'\n")
+  
+proc rodsrc = 
+  const
+    blacklist = ["nsystem", "nmath", "nos", "ntime", "strutils"]
+    cmd = "nimrod boot --skip_proj_cfg -o:rod/$1.nim nim/$1"
+  for fi in walkFiles("nim/*.pas"):
+    var f = extractFileTrunk(fi)
+    if find(blacklist, f) >= 0: continue
+    var r = "rod" / appendFileExt(f, "nim")
+    if not existsFile(r) or fileNewer(fi, r):
+      Exec(cmd % f)
+  
+proc boot(args: string) =
+  writePlatdefC()
+  rodsrc()
+  var newExe = appendFileExt("rod/nimrod", ExeExt)
+  var oldExe = appendFileExt("bin/nimrod", ExeExt)
+  for i in 1..2:
+    Echo("iteration: ", $i)
+    # use the new executable to compile the files in the bootstrap directory:
+    Exec(Bootcmd % args)
+    if sameFileContent(newExe, oldExe): 
+      Echo("executables are equal: SUCCESS!")
+      return
+    else:
+      Echo("executables are not equal: compile once again...")
+      # move the new executable to bin directory:
+      os.moveFile(oldExe, newExe)
+  Echo("[Warning] executables are still not equal")
+
+var a = ""
+for i in 1 .. paramCount():
+  add(a, ' ')
+  add(a, paramStr(i))
+boot(a)
+