summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2013-08-04 19:41:20 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2013-08-04 19:41:20 +0100
commit201e4d283511af57c6e20bf3a77405c99ebbe305 (patch)
tree03e0522c0a66ea9117dffb3f87e580bb0df018da
parent8ac7bda2441ddd512e9206df290d3e2b74a05b95 (diff)
downloadNim-201e4d283511af57c6e20bf3a77405c99ebbe305.tar.gz
Modified the behaviour of the build scripts to accommodate new C sources
repo.
-rw-r--r--tools/niminst/buildbat.tmpl13
-rw-r--r--tools/niminst/buildsh.tmpl20
-rw-r--r--tools/niminst/niminst.nim27
3 files changed, 41 insertions, 19 deletions
diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl
index a8dfd597f..256f61b3d 100644
--- a/tools/niminst/buildbat.tmpl
+++ b/tools/niminst/buildbat.tmpl
@@ -5,6 +5,11 @@ SET CC=gcc
 SET LINKER=gcc
 SET COMP_FLAGS=?{c.ccompiler.flags}
 SET LINK_FLAGS=?{c.linker.flags}
+SET BIN_DIR=?{firstBinPath(c)}
+
+if EXIST ..\koch.nim SET BIN_DIR=..\bin
+
+if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR%
 
 REM call the compiler:
 
@@ -12,13 +17,13 @@ REM call the compiler:
 #    var linkCmd = ""
 #    for ff in items(c.cfiles[1][ord(target)]):
 #      let f = ff.replace('/', '\\')
-ECHO %CC% %COMP_FLAGS% -Ibuild -c ?{f} -o ?{changeFileExt(f, "o")}
-%CC% %COMP_FLAGS% -Ibuild -c ?{f} -o ?{changeFileExt(f, "o")}
+ECHO %CC% %COMP_FLAGS% -Isrc -c ?{f} -o ?{changeFileExt(f, "o")}
+%CC% %COMP_FLAGS% -Isrc -c ?{f} -o ?{changeFileExt(f, "o")}
 #      linkCmd.add(" " & changeFileExt(f, "o"))
 #    end for
 
-ECHO %LINKER% -o ?{firstBinPath(c)\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS%
-%LINKER% -o ?{firstBinPath(c)\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS%
+ECHO %LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS%
+%LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS%
 
 #  end block
 
diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl
index da9c40f55..1ce182b63 100644
--- a/tools/niminst/buildsh.tmpl
+++ b/tools/niminst/buildsh.tmpl
@@ -34,6 +34,16 @@ LINK_FLAGS="?{c.linker.flags}"
 #  add(result, "# platform detection\n")
 ucpu=`uname -m`
 uos=`uname`
+#  add(result, "# bin dir detection\n")
+binDir=?{firstBinPath(c)}
+
+if [ -s ../koch.nim ]; then
+  binDir="../bin"
+fi
+
+if [ ! -d $binDir ]; then
+  mkdir $binDir
+fi
 
 #  add(result, "# convert to lower case:\n")
 ucpu=`echo $ucpu | tr "[:upper:]" "[:lower:]"`
@@ -117,12 +127,12 @@ case $myos in
   ?{c.cpus[cpuA-1]})
 #      var linkCmd = ""
 #      for f in items(c.cfiles[osA][cpuA]):
-    echo "$CC $COMP_FLAGS -Ibuild -c ?{f} -o ?{changeFileExt(f, "o")}"
-    $CC $COMP_FLAGS -Ibuild -c ?{f} -o ?{changeFileExt(f, "o")}
+    echo "$CC $COMP_FLAGS -Isrc -c ?{f} -o ?{changeFileExt(f, "o")}"
+    $CC $COMP_FLAGS -Isrc -c ?{f} -o ?{changeFileExt(f, "o")}
 #        add(linkCmd, " \\\n" & changeFileExt(f, "o"))
-#      end for    
-    echo "$LINKER -o ?{firstBinPath(c)/toLower(c.name)} ?linkCmd $LINK_FLAGS"
-    $LINKER -o ?{firstBinPath(c)/toLower(c.name)} ?linkCmd $LINK_FLAGS
+#      end for
+    echo "$LINKER -o ?{"$binDir"/toLower(c.name)} ?linkCmd $LINK_FLAGS"
+    $LINKER -o ?{"$binDir"/toLower(c.name)} ?linkCmd $LINK_FLAGS
     ;;
 #    end for
   *)
diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim
index 98a7ab8bb..faad2fb15 100644
--- a/tools/niminst/niminst.nim
+++ b/tools/niminst/niminst.nim
@@ -357,7 +357,10 @@ proc readCFiles(c: var TConfigData, osA, cpuA: int) =
     quit("Cannot open: " & f)
 
 proc buildDir(os, cpu: int): string =
-  return "build" / ($os & "_" & $cpu)
+  return "src" / ($os & "_" & $cpu)
+
+proc getOutputDir(c: var TConfigData): string =
+  if c.outdir.len > 0: c.outdir else: "build"
 
 proc writeFile(filename, content, newline: string) =
   var f: TFile
@@ -392,11 +395,14 @@ proc writeInstallScripts(c: var TConfigData) =
     writeFile(deinstallShFile, GenerateDeinstallScript(c), "\10")
 
 proc srcdist(c: var TConfigData) =
+  if not existsDir(getOutputDir(c) / "src"):
+    createDir(getOutputDir(c) / "src")
   for x in walkFiles(c.libpath / "lib/*.h"):
-    CopyFile(dest="build" / extractFilename(x), source=x)
+    echo(getOutputDir(c) / "src" / extractFilename(x))
+    CopyFile(dest=getOutputDir(c) / "src" / extractFilename(x), source=x)
   for osA in 1..c.oses.len:
     for cpuA in 1..c.cpus.len:
-      var dir = buildDir(osA, cpuA)
+      var dir = getOutputDir(c) / buildDir(osA, cpuA)
       if existsDir(dir): removeDir(dir)
       createDir(dir)
       var cmd = ("nimrod compile -f --symbolfiles:off --compileonly " &
@@ -409,14 +415,15 @@ proc srcdist(c: var TConfigData) =
         quit("Error: call to nimrod compiler failed")
       readCFiles(c, osA, cpuA)
       for i in 0 .. c.cfiles[osA][cpuA].len-1:
-        var dest = dir / extractFilename(c.cfiles[osA][cpuA][i])
+        let dest = dir / extractFilename(c.cfiles[osA][cpuA][i])
+        let relDest = buildDir(osA, cpuA) / extractFilename(c.cfiles[osA][cpuA][i])
         CopyFile(dest=dest, source=c.cfiles[osA][cpuA][i])
-        c.cfiles[osA][cpuA][i] = dest
+        c.cfiles[osA][cpuA][i] = relDest
   # second pass: remove duplicate files
   removeDuplicateFiles(c)
-  writeFile(buildShFile, GenerateBuildShellScript(c), "\10")
-  writeFile(buildBatFile32, GenerateBuildBatchScript(c, tWin32), "\13\10")
-  writeFile(buildBatFile64, GenerateBuildBatchScript(c, tWin64), "\13\10")
+  writeFile(getOutputDir(c) / buildShFile, GenerateBuildShellScript(c), "\10")
+  writeFile(getOutputDir(c) / buildBatFile32, GenerateBuildBatchScript(c, tWin32), "\13\10")
+  writeFile(getOutputDir(c) / buildBatFile64, GenerateBuildBatchScript(c, tWin64), "\13\10")
   writeInstallScripts(c)
 
 # --------------------- generate inno setup -----------------------------------
@@ -467,8 +474,8 @@ when haveZipLib:
 # -- prepare build files for .deb creation
 
 proc debDist(c: var TConfigData) =
-  if not existsFile("build.sh"): quit("No build.sh found.")
-  if not existsFile("install.sh"): quit("No install.sh found.")
+  if not existsFile(getOutputDir(c) / "build.sh"): quit("No build.sh found.")
+  if not existsFile(getOutputDir(c) / "install.sh"): quit("No install.sh found.")
   
   if c.debOpts.shortDesc == "": quit("shortDesc must be set in the .ini file.")
   if c.debOpts.licenses.len == 0: