mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Detect gcc arch in build.bat (#7856)
* Detect gcc arch in build.bat * Fix 64-bit test
This commit is contained in:
committed by
Andreas Rumpf
parent
4da0135ace
commit
1d72ec3f1b
@@ -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,27 +7,63 @@ 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%
|
||||
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%
|
||||
|
||||
# end block
|
||||
)
|
||||
|
||||
:END
|
||||
IF ERRORLEVEL 1 (
|
||||
ECHO FAILURE
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user