Detect gcc arch in build.bat (#7856)
* Detect gcc arch in build.bat * Fix 64-bit test
This commit is contained in:
parent
4da0135ace
commit
1d72ec3f1b
2 changed files with 58 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
#? stdtmpl(subsChar='?') | standard
|
#? 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"
|
# result = "@echo off\nREM Generated by niminst\n"
|
||||||
SET CC=gcc
|
SET CC=gcc
|
||||||
SET LINKER=gcc
|
SET LINKER=gcc
|
||||||
|
|
@ -7,27 +7,63 @@ SET COMP_FLAGS=?{c.ccompiler.flags}
|
||||||
SET LINK_FLAGS=?{c.linker.flags}
|
SET LINK_FLAGS=?{c.linker.flags}
|
||||||
SET BIN_DIR=?{firstBinPath(c).toWin}
|
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 EXIST ..\koch.nim SET BIN_DIR=..\bin
|
||||||
|
|
||||||
if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR%
|
if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR%
|
||||||
|
|
||||||
REM call the compiler:
|
REM call the compiler:
|
||||||
|
|
||||||
|
IF %ARCH% EQU 32 (
|
||||||
|
|
||||||
# block win32:
|
# block win32:
|
||||||
# var linkCmd = ""
|
# var linkCmd = ""
|
||||||
# for ff in items(c.cfiles[winIndex][cpuIndex]):
|
# if cpuIndex32 != -1:
|
||||||
# let f = ff.toWin
|
# for ff in items(c.cfiles[winIndex][cpuIndex32]):
|
||||||
ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
|
# let f = ff.toWin
|
||||||
CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
|
ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
|
||||||
# linkCmd.add(" " & changeFileExt(f, "o"))
|
CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
|
||||||
IF ERRORLEVEL 1 (GOTO:END)
|
# linkCmd.add(" " & changeFileExt(f, "o"))
|
||||||
# end for
|
IF ERRORLEVEL 1 (GOTO:END)
|
||||||
|
# end for
|
||||||
|
# end if
|
||||||
|
|
||||||
ECHO %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%
|
CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
|
||||||
|
|
||||||
# end block
|
# 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
|
:END
|
||||||
IF ERRORLEVEL 1 (
|
IF ERRORLEVEL 1 (
|
||||||
ECHO FAILURE
|
ECHO FAILURE
|
||||||
|
|
@ -35,6 +71,8 @@ IF ERRORLEVEL 1 (
|
||||||
ECHO CSource compilation failed. Please check that the gcc compiler is in
|
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 the PATH environment variable, and that you are calling the batch script
|
||||||
ECHO that matches the target architecture of the compiler.
|
ECHO that matches the target architecture of the compiler.
|
||||||
|
ECHO.
|
||||||
|
ECHO Use build.bat to autodetect the compiler architecture.
|
||||||
) ELSE (
|
) ELSE (
|
||||||
ECHO SUCCESS
|
ECHO SUCCESS
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ const
|
||||||
maxOS = 20 # max number of OSes
|
maxOS = 20 # max number of OSes
|
||||||
maxCPU = 20 # max number of CPUs
|
maxCPU = 20 # max number of CPUs
|
||||||
buildShFile = "build.sh"
|
buildShFile = "build.sh"
|
||||||
buildBatFile32 = "build.bat"
|
buildBatFile = "build.bat"
|
||||||
|
buildBatFile32 = "build32.bat"
|
||||||
buildBatFile64 = "build64.bat"
|
buildBatFile64 = "build64.bat"
|
||||||
makeFile = "makefile"
|
makeFile = "makefile"
|
||||||
installShFile = "install.sh"
|
installShFile = "install.sh"
|
||||||
|
|
@ -542,12 +543,13 @@ proc srcdist(c: var ConfigData) =
|
||||||
inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec})
|
inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec})
|
||||||
writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10")
|
writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10")
|
||||||
if winIndex >= 0:
|
if winIndex >= 0:
|
||||||
|
if intel32Index >= 0 or intel64Index >= 0:
|
||||||
|
writeFile(getOutputDir(c) / buildBatFile,
|
||||||
|
generateBuildBatchScript(c, winIndex, intel32Index, intel64Index), "\13\10")
|
||||||
if intel32Index >= 0:
|
if intel32Index >= 0:
|
||||||
writeFile(getOutputDir(c) / buildBatFile32,
|
writeFile(getOutputDir(c) / buildBatFile32, "SET ARCH=32\nCALL build.bat\n")
|
||||||
generateBuildBatchScript(c, winIndex, intel32Index), "\13\10")
|
|
||||||
if intel64Index >= 0:
|
if intel64Index >= 0:
|
||||||
writeFile(getOutputDir(c) / buildBatFile64,
|
writeFile(getOutputDir(c) / buildBatFile64, "SET ARCH=64\nCALL build.bat\n")
|
||||||
generateBuildBatchScript(c, winIndex, intel64Index), "\13\10")
|
|
||||||
writeInstallScripts(c)
|
writeInstallScripts(c)
|
||||||
|
|
||||||
# --------------------- generate inno setup -----------------------------------
|
# --------------------- generate inno setup -----------------------------------
|
||||||
|
|
@ -593,6 +595,7 @@ when haveZipLib:
|
||||||
else: n = c.outdir / n
|
else: n = c.outdir / n
|
||||||
var z: ZipArchive
|
var z: ZipArchive
|
||||||
if open(z, n, fmWrite):
|
if open(z, n, fmWrite):
|
||||||
|
addFile(z, proj / buildBatFile, "build" / buildBatFile)
|
||||||
addFile(z, proj / buildBatFile32, "build" / buildBatFile32)
|
addFile(z, proj / buildBatFile32, "build" / buildBatFile32)
|
||||||
addFile(z, proj / buildBatFile64, "build" / buildBatFile64)
|
addFile(z, proj / buildBatFile64, "build" / buildBatFile64)
|
||||||
addFile(z, proj / buildShFile, "build" / buildShFile)
|
addFile(z, proj / buildShFile, "build" / buildShFile)
|
||||||
|
|
@ -631,11 +634,12 @@ proc xzDist(c: var ConfigData; windowsZip=false) =
|
||||||
if not dirExists(destDir): createDir(destDir)
|
if not dirExists(destDir): createDir(destDir)
|
||||||
copyFileWithPermissions(src, dest)
|
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 " &
|
quit("No C sources found in ./build/, please build by running " &
|
||||||
"./koch csource -d:release.")
|
"./koch csource -d:release.")
|
||||||
|
|
||||||
if not windowsZip:
|
if not windowsZip:
|
||||||
|
processFile(proj / buildBatFile, "build" / buildBatFile)
|
||||||
processFile(proj / buildBatFile32, "build" / buildBatFile32)
|
processFile(proj / buildBatFile32, "build" / buildBatFile32)
|
||||||
processFile(proj / buildBatFile64, "build" / buildBatFile64)
|
processFile(proj / buildBatFile64, "build" / buildBatFile64)
|
||||||
processFile(proj / buildShFile, "build" / buildShFile)
|
processFile(proj / buildShFile, "build" / buildShFile)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue