diff options
author | genotrance <dev@genotrance.com> | 2018-05-22 13:53:29 -0500 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-22 20:53:29 +0200 |
commit | 1d72ec3f1bd94e20f442cfe418c98a371d3dd9e4 (patch) | |
tree | bbb3cc7397e5c52478420e6c8e62da4608470a82 /tools | |
parent | 4da0135ace7847323f0d1c65e32a2814d9bfc6e6 (diff) | |
download | Nim-1d72ec3f1bd94e20f442cfe418c98a371d3dd9e4.tar.gz |
Detect gcc arch in build.bat (#7856)
* Detect gcc arch in build.bat * Fix 64-bit test
Diffstat (limited to 'tools')
-rw-r--r-- | tools/niminst/buildbat.tmpl | 58 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 16 |
2 files changed, 58 insertions, 16 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/niminst.nim b/tools/niminst/niminst.nim index c2816a0ef..e2cc8cf3a 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -21,7 +21,8 @@ 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) |