summary refs log tree commit diff stats
path: root/tools/niminst
diff options
context:
space:
mode:
Diffstat (limited to 'tools/niminst')
-rw-r--r--tools/niminst/buildbat.tmpl58
-rw-r--r--tools/niminst/buildsh.tmpl4
-rw-r--r--tools/niminst/niminst.nim18
3 files changed, 61 insertions, 19 deletions
diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl
index 278b6caea..6767461e3 100644
--- a/tools/niminst/buildbat.tmpl
+++ b/tools/niminst/buildbat.tmpl
@@ -1,5 +1,5 @@
 #? stdtmpl(subsChar='?') | standard
-#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string =
+#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex32, cpuIndex64: int): string =
 #  result = "@echo off\nREM Generated by niminst\n"
 SET CC=gcc
 SET LINKER=gcc
@@ -7,26 +7,62 @@ SET COMP_FLAGS=?{c.ccompiler.flags}
 SET LINK_FLAGS=?{c.linker.flags}
 SET BIN_DIR=?{firstBinPath(c).toWin}
 
+REM Detect gcc arch
+IF DEFINED ARCH (
+  ECHO Forcing %CC% arch
+) ELSE (
+  ECHO Detecting %CC% arch
+  ECHO int main^(^) { return sizeof^(void *^); } | gcc -xc - -o archtest && archtest
+  IF ERRORLEVEL 4 SET ARCH=32
+  IF ERRORLEVEL 8 SET ARCH=64
+  del archtest.*
+)
+ECHO Building with %ARCH% bit %CC%
+
 if EXIST ..\koch.nim SET BIN_DIR=..\bin
 
 if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR%
 
 REM call the compiler:
 
+IF %ARCH% EQU 32 (
+
 #  block win32:
 #    var linkCmd = ""
-#    for ff in items(c.cfiles[winIndex][cpuIndex]):
-#      let f = ff.toWin
-ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
-CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
-#      linkCmd.add(" " & changeFileExt(f, "o"))
-IF ERRORLEVEL 1 (GOTO:END)
-#    end for
+#    if cpuIndex32 != -1:
+#      for ff in items(c.cfiles[winIndex][cpuIndex32]):
+#        let f = ff.toWin
+  ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
+  CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
+#        linkCmd.add(" " & changeFileExt(f, "o"))
+  IF ERRORLEVEL 1 (GOTO:END)
+#      end for
+#    end if
+
+  ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
+  CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
+
+#  end block
+
+) ELSE IF %ARCH% EQU 64 (
+
+#  block win64:
+#    var linkCmd = ""
+#    if cpuIndex64 != -1:
+#      for ff in items(c.cfiles[winIndex][cpuIndex64]):
+#        let f = ff.toWin
+  ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
+  CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
+#        linkCmd.add(" " & changeFileExt(f, "o"))
+  IF ERRORLEVEL 1 (GOTO:END)
+#      end for
+#    end if
 
-ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
-CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
+  ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
+  CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
 
 #  end block
+)
 
 :END
 IF ERRORLEVEL 1 (
@@ -35,6 +71,8 @@ IF ERRORLEVEL 1 (
     ECHO CSource compilation failed. Please check that the gcc compiler is in
     ECHO the PATH environment variable, and that you are calling the batch script
     ECHO that matches the target architecture of the compiler.
+    ECHO.
+    ECHO Use build.bat to autodetect the compiler architecture.
 ) ELSE (
     ECHO SUCCESS
 )
diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl
index 3e7d8ae6e..be6d43754 100644
--- a/tools/niminst/buildsh.tmpl
+++ b/tools/niminst/buildsh.tmpl
@@ -39,8 +39,8 @@ do
   esac
 done
 
-CC="gcc"
-LINKER="gcc"
+CC="${CC:-gcc}"
+LINKER="${LD:-gcc}"
 COMP_FLAGS="${CPPFLAGS:-} ${CFLAGS:-} ?{c.ccompiler.flags}$extraBuildArgs"
 LINK_FLAGS="${LDFLAGS:-} ?{c.linker.flags}"
 PS4=""
diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim
index 9c15326b0..e2cc8cf3a 100644
--- a/tools/niminst/niminst.nim
+++ b/tools/niminst/niminst.nim
@@ -15,13 +15,14 @@ when haveZipLib:
 
 import
   os, osproc, strutils, parseopt, parsecfg, strtabs, streams, debcreation,
-  securehash
+  std / sha1
 
 const
   maxOS = 20 # max number of OSes
   maxCPU = 20 # max number of CPUs
   buildShFile = "build.sh"
-  buildBatFile32 = "build.bat"
+  buildBatFile = "build.bat"
+  buildBatFile32 = "build32.bat"
   buildBatFile64 = "build64.bat"
   makeFile = "makefile"
   installShFile = "install.sh"
@@ -542,12 +543,13 @@ proc srcdist(c: var ConfigData) =
   inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec})
   writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10")
   if winIndex >= 0:
+    if intel32Index >= 0 or intel64Index >= 0:
+      writeFile(getOutputDir(c) / buildBatFile,
+                generateBuildBatchScript(c, winIndex, intel32Index, intel64Index), "\13\10")
     if intel32Index >= 0:
-      writeFile(getOutputDir(c) / buildBatFile32,
-                generateBuildBatchScript(c, winIndex, intel32Index), "\13\10")
+      writeFile(getOutputDir(c) / buildBatFile32, "SET ARCH=32\nCALL build.bat\n")
     if intel64Index >= 0:
-      writeFile(getOutputDir(c) / buildBatFile64,
-                generateBuildBatchScript(c, winIndex, intel64Index), "\13\10")
+      writeFile(getOutputDir(c) / buildBatFile64, "SET ARCH=64\nCALL build.bat\n")
   writeInstallScripts(c)
 
 # --------------------- generate inno setup -----------------------------------
@@ -593,6 +595,7 @@ when haveZipLib:
     else: n = c.outdir / n
     var z: ZipArchive
     if open(z, n, fmWrite):
+      addFile(z, proj / buildBatFile, "build" / buildBatFile)
       addFile(z, proj / buildBatFile32, "build" / buildBatFile32)
       addFile(z, proj / buildBatFile64, "build" / buildBatFile64)
       addFile(z, proj / buildShFile, "build" / buildShFile)
@@ -631,11 +634,12 @@ proc xzDist(c: var ConfigData; windowsZip=false) =
     if not dirExists(destDir): createDir(destDir)
     copyFileWithPermissions(src, dest)
 
-  if not windowsZip and not existsFile("build" / buildBatFile32):
+  if not windowsZip and not existsFile("build" / buildBatFile):
     quit("No C sources found in ./build/, please build by running " &
          "./koch csource -d:release.")
 
   if not windowsZip:
+    processFile(proj / buildBatFile, "build" / buildBatFile)
     processFile(proj / buildBatFile32, "build" / buildBatFile32)
     processFile(proj / buildBatFile64, "build" / buildBatFile64)
     processFile(proj / buildShFile, "build" / buildShFile)