build.bat (5881B)
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 CXX=clang++ 12 SET ARCH=PORTABLE 13 SET THREADS=1 14 SET SANITIZE= 15 16 :: TODO depends on ARCH variable 17 SET ARCHOPTS= 18 :: TODO depends on SANITIZE variable 19 SET DFLAGS=-g3 -DDEBUG 20 21 SET WARNINGS=-Wno-deprecated-declarations 22 SET VARIABLES=-DTHREADS=%THREADS% -D%ARCH% 23 SET OFLAGS=-O3 24 25 SET CFLAGS=-std=c11 %ARCHOPTS% %WARNINGS% %VARIABLES% 26 27 SET STACKSIZE=-Wl,-stack:16777216 28 SET LFLAGS=%STACKSIZE% 29 30 :: Python libraries - change to match your local installation 31 SET PYPATH=%userprofile%\AppData\Local\Programs\Python\Python313 32 SET PYINCLUDE=%PYPATH%\include 33 SET PYLIBS=%PYPATH%\libs 34 35 SET TARGET=%1 36 if not defined TARGET SET TARGET=nissy 37 SET EXPR=%2 38 for %%a in (nissy python shell test config help clean tool cpp solvetest) do ( 39 if %TARGET%==%%a ( 40 call:build_%TARGET% %* 41 exit /b 42 ) 43 ) 44 45 echo Target '%TARGET%' unavailable, run 'build help' for info 46 exit /b 1 47 48 :build_help 49 echo *** Warning: support for building nissy on Windows is incomplete *** 50 echo. 51 echo Build system for nissy. Usage: 52 echo. 53 echo build [/d] [TARGET] 54 echo. 55 echo Possible values for TARGET (defaults to 'nissy' if unspecified): 56 echo. 57 echo nissy Build the nissy.o object file. 58 echo python Build the Python module for nissy. 59 echo NOTE: Python development headers must be installed in 60 echo order to build the Python module. The path of these 61 echo headers is hardcoded in the PYPATH varible in 62 echo build.bat. You may need to edit this file. 63 echo shell Build the basic nissy shell (./run). 64 echo cpp FILE Build and run the given C++ FILE. 65 echo test [EXPR] Build and run unit tests. If EXPR is provided, only the 66 echo tests whose name contains EXPR are run. The /d option is 67 echo is always implied. 68 echo tool EXPR Run the 'tool' matching the given EXPR. 69 echo solvetest Build nissy and run a collection of tools for testing" 70 echo various solvers. 71 echo help Show this help message. 72 echo config Show build configuration and exit. 73 echo clean Remove all build files. 74 echo. 75 echo The /d option activates debug mode (slower, used for testing). 76 echo Tests are automatically built in debug mode even without /d. 77 echo For more on build configurations, see the comments in build.bat. 78 exit /b 79 80 :build_config 81 echo Compiler: %CC% 82 echo Architecture: %ARCH% 83 echo Max threads: %THREADS% 84 echo Optimization flags: %OFLAGS% 85 echo Debug flags: %DFLAGS% 86 exit /b 87 88 :build_nissy 89 call:odflags 90 @echo on 91 %CC% %CFLAGS% %ODFLAGS% -c src\nissy.c || exit /b 1 92 @echo off 93 exit /b 94 95 :build_shell 96 call:build_nissy || exit /b 1 97 call:odflags 98 @echo on 99 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o shell\shell.c -o run.exe ^ 100 || exit /b 1 101 @echo off 102 exit /b 103 104 :build_python 105 call:build_nissy || exit /b 1 106 call:odflags 107 @echo on 108 %CC% %CFLAGS% %LFLAGS% -I%PYINCLUDE% -L%PYLIBS% -shared -lpython3 ^ 109 python\nissy_module.c nissy.o -o python\nissy.pyd || exit /b 1 110 @echo off 111 exit /b 112 113 :build_test 114 SET DEBUG=1 115 call:build_nissy || exit /b 1 116 if not defined EXPR ( 117 SET WILDCARD=* 118 ) else ( 119 SET WILDCARD=*%EXPR%* 120 ) 121 for /d %%d in ( test\%WILDCARD% ) do ( 122 if exist %%d\* ( 123 call:build_single_test %%d || exit /b 1 124 ) 125 ) 126 exit /b 127 128 :build_clean 129 @echo on 130 del *.o *.so *.a *.ilk *.pdb *.exe 131 @echo off 132 exit /b 133 134 :build_tool 135 if not defined EXPR ( 136 @echo Please provide a valid EXPR to select a tool 137 exit /b 1 138 ) 139 140 set toolname= 141 for /d %%d in ( tools\*%EXPR%* ) do ( 142 set toolname=%%~nd 143 ) 144 145 if [%toolname%]==[] ( 146 @echo Expression '%EXPR%' does not match any tool 147 exit /b 1 148 ) 149 150 call:build_nissy || exit /b 1 151 call:build_single_tool %* 152 exit /b 153 154 :build_cpp 155 if not defined EXPR ( 156 @echo Please provide a valid C++ source file. 157 exit /b 1 158 ) 159 if not exist %EXPR% ( 160 @echo File %EXPR% does not exist. 161 exit /b 1 162 ) 163 call:build_nissy || exit /b 1 164 @echo on 165 %CXX% %ODFLAGS% -std=c++20 -o runcpp.exe cpp\nissy.cpp nissy.o %EXPR% ^ 166 || exit /b 1 167 runcpp 168 @echo off 169 exit /b 170 171 :build_solvetest 172 call:build_nissy || exit /b 1 173 for /d %%d in ( tools\*solvetest* ) do ( 174 set toolname=%%~nd 175 call:build_single_tool 176 ) 177 exit /b 178 179 :build_single_test 180 call:odflags 181 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o %1\*.c -o runtest.exe || exit /b 1 182 set error=0 183 for %%c in ( %1\*.in ) do ( 184 if %error%==1 exit /b 1 185 @echo | set /p v="%1\%%~nc: " 186 runtest < %%c > test\last.out 2> test\last.err 187 FC /a %1\%%~nc.out test\last.out > test\last.fc.out 188 if ERRORLEVEL 1 ( 189 @echo Test failed! Different output: 190 type test\last.fc.out 191 @echo stderr: 192 type test\last.err 193 goto :error 194 ) else ( 195 @echo ok 196 ) 197 ) 198 if %error%==1 exit /b 1 199 del runtest.* 200 exit /b 201 202 :build_single_tool 203 @echo on 204 %CC% %CFLAGS% %ODFLAGS% %LFLAGS% nissy.o tools\%toolname%\*.c ^ 205 -o runtool.exe || exit /b 1 206 @echo off 207 runtool %3 %4 %5 %6 %7 %8 %9 || exit /b 1 208 @echo. 209 @echo (On Windows, the output of a tool is not saved to any file.) 210 exit /b 211 212 :odflags 213 if %DEBUG%==1 ( 214 SET ODFLAGS=%DFLAGS% 215 ) else ( 216 SET ODFLAGS=%OFLAGS% 217 ) 218 exit /b 219 220 :error 221 exit /b 1