diff options
Diffstat (limited to '')
| -rw-r--r-- | build.bat | 149 |
1 files changed, 139 insertions, 10 deletions
| @@ -1,21 +1,150 @@ | |||
| 1 | SET COMPILER=clang | 1 | @echo off |
| 2 | |||
| 3 | if [%1]==[/d] ( | ||
| 4 | SET DEBUG=1 | ||
| 5 | shift | ||
| 6 | ) else ( | ||
| 7 | SET DEBUG=0 | ||
| 8 | ) | ||
| 9 | |||
| 10 | SET CC=clang | ||
| 11 | SET ARCH=PORTABLE | ||
| 12 | SET THREADS=1 | ||
| 13 | SET SANITIZE= | ||
| 14 | |||
| 15 | :: TODO depends on ARCH variable | ||
| 16 | SET ARCHOPTS= | ||
| 17 | :: TODO depends on SANITIZE variable | ||
| 18 | SET DFLAGS=-g3 -DDEBUG | ||
| 2 | 19 | ||
| 3 | SET ARCH= | ||
| 4 | SET WARNINGS=-Wno-deprecated-declarations | 20 | SET WARNINGS=-Wno-deprecated-declarations |
| 5 | SET VARIABLES=-DTHREADS=1 -DPORTABLE | 21 | SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% |
| 6 | SET OFLAGS=-O3 | 22 | SET OFLAGS=-O3 |
| 7 | SET DFLAGS=-g -fsanitize=address | 23 | |
| 8 | SET CFLAGS=-std=c11 %OFLAGS% %ARCH% %WARNINGS% %VARIABLES% | 24 | SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% |
| 9 | 25 | ||
| 10 | SET STACKSIZE=-Wl,-stack:16777216 | 26 | SET STACKSIZE=-Wl,-stack:16777216 |
| 11 | SET LFLAGS=%STACKSIZE% | 27 | SET LFLAGS=%STACKSIZE% |
| 12 | 28 | ||
| 13 | %COMPILER% %CFLAGS% -c src\nissy.c || exit /b | 29 | :: Python libraries - change to match your local installation |
| 14 | %COMPILER% %CFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe || exit /b | ||
| 15 | |||
| 16 | :: Python libraries - change to mathc your local installation | ||
| 17 | SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 | 30 | SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 |
| 18 | SET PYINCLUDE=%PYPATH%\include | 31 | SET PYINCLUDE=%PYPATH%\include |
| 19 | SET PYLIBS=%PYPATH%\libs | 32 | SET PYLIBS=%PYPATH%\libs |
| 20 | 33 | ||
| 21 | %COMPILER% %CFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 python/nissy_module.c nissy.o -o nissy.pyd \ No newline at end of file | 34 | SET TARGET=%1 |
| 35 | if not defined TARGET SET TARGET=nissy | ||
| 36 | SET EXPR=%2 | ||
| 37 | for %%a in (nissy python shell test config help) do ( | ||
| 38 | if %TARGET%==%%a ( | ||
| 39 | call:build_%TARGET% | ||
| 40 | exit /b | ||
| 41 | ) | ||
| 42 | ) | ||
| 43 | |||
| 44 | echo Target '%TARGET%' unavailable, run 'build help' for info | ||
| 45 | exit /b 1 | ||
| 46 | |||
| 47 | :build_help | ||
| 48 | echo *** Warning: support for building nissy on Windows is incomplete *** | ||
| 49 | echo. | ||
| 50 | echo Build system for nissy. Usage: | ||
| 51 | echo. | ||
| 52 | echo build [/d] [TARGET] | ||
| 53 | echo. | ||
| 54 | echo Possible values for TARGET (defaults to 'nissy' if unspecified): | ||
| 55 | echo. | ||
| 56 | echo nissy Build the nissy.o object file. | ||
| 57 | echo python Build the Python module for nissy. | ||
| 58 | echo shell Build the basic nissy shell (./run). | ||
| 59 | echo help Show this help message. | ||
| 60 | echo config Show build configuration and exit. | ||
| 61 | echo test [EXPR] Build and run unit tests. If EXPR is provided, only the | ||
| 62 | echo tests whose name contains EXPR are run. The /d option is | ||
| 63 | echo is always implied. | ||
| 64 | echo. | ||
| 65 | echo The /d option activates debug mode (slower, used for testing). | ||
| 66 | echo Tests are automatically built in debug mode even without /d. | ||
| 67 | echo For more on build configurations, see the comments in build.bat. | ||
| 68 | exit /b | ||
| 69 | |||
| 70 | :build_config | ||
| 71 | echo Compiler: %CC% | ||
| 72 | echo Architecture: %ARCH% | ||
| 73 | echo Max threads: %THREADS% | ||
| 74 | echo Optimization flags: %OFLAGS% | ||
| 75 | echo Debug flags: %DFLAGS% | ||
| 76 | exit /b | ||
| 77 | |||
| 78 | :build_nissy | ||
| 79 | call:odflags | ||
| 80 | @echo on | ||
| 81 | %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1 | ||
| 82 | @echo off | ||
| 83 | exit /b | ||
| 84 | |||
| 85 | :build_shell | ||
| 86 | call:build_nissy || exit /b 1 | ||
| 87 | call:odflags | ||
| 88 | @echo on | ||
| 89 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^ | ||
| 90 | || exit /b 1 | ||
| 91 | @echo off | ||
| 92 | exit /b | ||
| 93 | |||
| 94 | :build_python | ||
| 95 | call:build_nissy || exit /b 1 | ||
| 96 | call:odflags | ||
| 97 | @echo on | ||
| 98 | %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^ | ||
| 99 | python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1 | ||
| 100 | @echo off | ||
| 101 | exit /b | ||
| 102 | |||
| 103 | :build_test | ||
| 104 | SET DEBUG=1 | ||
| 105 | call:build_nissy || exit /b 1 | ||
| 106 | if not defined EXPR ( | ||
| 107 | SET WILDCARD=* | ||
| 108 | ) else ( | ||
| 109 | SET WILDCARD=*%EXPR%* | ||
| 110 | ) | ||
| 111 | for /d %%d in ( test\%WILDCARD% ) do ( | ||
| 112 | if exist %%d\* ( | ||
| 113 | call:build_single_test %%d || exit /b 1 | ||
| 114 | ) | ||
| 115 | ) | ||
| 116 | exit /b | ||
| 117 | |||
| 118 | :build_single_test | ||
| 119 | call:odflags | ||
| 120 | %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 | ||
| 121 | set error=0 | ||
| 122 | for %%c in ( %1\*.in ) do ( | ||
| 123 | if %error%==1 exit /b 1 | ||
| 124 | @echo | set /p v="%1\%%~nc: " | ||
| 125 | runtest < %%c > test\last.out 2> test\last.err | ||
| 126 | FC /a %1\%%~nc.out test\last.out > test\last.fc.out | ||
| 127 | if ERRORLEVEL 1 ( | ||
| 128 | @echo Test failed! Different output: | ||
| 129 | type test\last.fc.out | ||
| 130 | @echo stderr: | ||
| 131 | type test\last.err | ||
| 132 | goto :error | ||
| 133 | ) else ( | ||
| 134 | @echo ok | ||
| 135 | ) | ||
| 136 | ) | ||
| 137 | if %error%==1 exit /b 1 | ||
| 138 | del runtest.* | ||
| 139 | exit /b | ||
| 140 | |||
| 141 | :odflags | ||
| 142 | if %DEBUG%==1 ( | ||
| 143 | SET ODFLAGS=%DFLAGS% | ||
| 144 | ) else ( | ||
| 145 | SET ODFLAGS=%OFLAGS% | ||
| 146 | ) | ||
| 147 | exit /b | ||
| 148 | |||
| 149 | :error | ||
| 150 | exit /b 1 \ No newline at end of file | ||
