blob: 6767461e37d1871698f98cad89dabd5d9c71f37c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#? stdtmpl(subsChar='?') | standard
#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex32, cpuIndex64: int): string =
# result = "@echo off\nREM Generated by niminst\n"
SET CC=gcc
SET LINKER=gcc
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 = ""
# 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%
# end block
)
:END
IF ERRORLEVEL 1 (
ECHO FAILURE
ECHO.
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
)
exit /b %ERRORLEVEL%
|