buildbat.tmpl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #? stdtmpl(subsChar='?') | standard
  2. #proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex32, cpuIndex64: int): string =
  3. # result = "@echo off\nREM Generated by niminst\n"
  4. SET CC=gcc
  5. SET LINKER=gcc
  6. SET COMP_FLAGS=?{c.ccompiler.flags}
  7. SET LINK_FLAGS=?{c.linker.flags}
  8. SET BIN_DIR=?{firstBinPath(c).toWin}
  9. REM Detect gcc arch
  10. IF DEFINED ARCH (
  11. ECHO Forcing %CC% arch
  12. ) ELSE (
  13. ECHO Detecting %CC% arch
  14. ECHO int main^(^) { return sizeof^(void *^); } | gcc -xc - -o archtest && archtest
  15. IF ERRORLEVEL 4 SET ARCH=32
  16. IF ERRORLEVEL 8 SET ARCH=64
  17. del archtest.*
  18. )
  19. ECHO Building with %ARCH% bit %CC%
  20. if EXIST ..\koch.nim SET BIN_DIR=..\bin
  21. if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR%
  22. REM call the compiler:
  23. IF %ARCH% EQU 32 (
  24. # block win32:
  25. # var linkCmd = ""
  26. # if cpuIndex32 != -1:
  27. # for ff in items(c.cfiles[winIndex][cpuIndex32]):
  28. # let f = ff.toWin
  29. ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
  30. CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
  31. # linkCmd.add(" " & changeFileExt(f, "o"))
  32. IF ERRORLEVEL 1 (GOTO:END)
  33. # end for
  34. # end if
  35. ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
  36. CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
  37. # end block
  38. ) ELSE IF %ARCH% EQU 64 (
  39. # block win64:
  40. # var linkCmd = ""
  41. # if cpuIndex64 != -1:
  42. # for ff in items(c.cfiles[winIndex][cpuIndex64]):
  43. # let f = ff.toWin
  44. ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
  45. CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
  46. # linkCmd.add(" " & changeFileExt(f, "o"))
  47. IF ERRORLEVEL 1 (GOTO:END)
  48. # end for
  49. # end if
  50. ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
  51. CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS%
  52. # end block
  53. )
  54. :END
  55. IF ERRORLEVEL 1 (
  56. ECHO FAILURE
  57. ECHO.
  58. ECHO CSource compilation failed. Please check that the gcc compiler is in
  59. ECHO the PATH environment variable, and that you are calling the batch script
  60. ECHO that matches the target architecture of the compiler.
  61. ECHO.
  62. ECHO Use build.bat to autodetect the compiler architecture.
  63. ) ELSE (
  64. ECHO SUCCESS
  65. )
  66. exit /b %ERRORLEVEL%