diff options
Diffstat (limited to 'boot.nim')
-rw-r--r-- | boot.nim | 67 |
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) + |