build.bat 6.77 KB
Newer Older
Axel Simon's avatar
Axel Simon committed
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
@ECHO OFF
setlocal ENABLEEXTENSIONS
rem This file is to be run on the Windows command line and generates the specified decoders.
rem

set ARGS=

rem remove bogus quotes from the PATH variable, that every path is in quotes
set LOCALPATH=%PATH:"=%
set LOCALPATH="%LOCALPATH:;=" "%"

rem let the user specify an output directory
set OUTDIR=
if NOT "%1"=="/odir" goto NoDir
set ARGS=%ARGS% %1
shift
set OUTDIR=%1
set ARGS=%ARGS% %1
shift
:NoDir

rem check if we find the Visual Studio compiler
set MSVC=
for %%p in (%LOCALPATH%) do if exist "%%~p\cl.exe" set MSVC="%%~p\cl.exe"

rem let the user specify the path to the C compiler
if NOT "%1"=="/cl" goto NoComp
set ARGS=%ARGS% %1
shift
set CL=%1
set ARGS=%ARGS% %1
shift
if exist %CL% goto NoComp
echo The compiler %CL% does not exist!
goto Error
:NoComp


rem let the user specify the Windows SDK lib directory
set SDKLIBPATH=
if NOT "%1"=="/sdklib" goto NoSDKLIB
set ARGS=%ARGS% %1
shift
set SDKLIBPATH=%1
set ARGS=%ARGS% %1
shift
:NoSDKLIB


SET DECODERS=x86 x86-rreil avr avr-rreil mips mips-rreil arm7

Axel Simon's avatar
Axel Simon committed
52
if "%1"=="" for %%d in (%DECODERS%) do build.bat %ARGS% %%d
Axel Simon's avatar
Axel Simon committed
53 54 55 56

for %%d IN (%DECODERS%) DO if "%1"=="%%d" set DECODER=%%d& goto Build

:Usage
Axel Simon's avatar
Axel Simon committed
57 58
echo Usage: build.bat [/odir "output-directory"] [/cl "cl-path"]
echo                  [/sdklib "sdklib-path"] ["decoder"]
Axel Simon's avatar
Axel Simon committed
59 60
echo where "cl-path" is the path to the Visual C compiler (ending in cl.exe)
echo and"sdklib-path" is the path to the \lib directory of the Windows SDK
Axel Simon's avatar
Axel Simon committed
61 62 63 64 65
echo and "decoder" may be omitted to build all or is one of the following:

for %%a in (%DECODERS%) do for /f "tokens=1,2 delims=-" %%d in ("%%a") do (
if "%%e"=="" (
echo	%%d		the %%d decoder and pretty printer
Axel Simon's avatar
Axel Simon committed
66
) ELSE (
Axel Simon's avatar
Axel Simon committed
67
echo	%%d-%%e	the %%d decoder, pretty printer and translation to %%e
Axel Simon's avatar
Axel Simon committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
)
)

goto End

:Build
echo off

rem keep these lists in sync with Makefile.am
set GDSL_BASIS=
set GDSL_BASIS=%GDSL_BASIS% specifications/basis/prelude.ml
set GDSL_BASIS=%GDSL_BASIS% specifications/basis/tree-set.ml
set GDSL_BASIS=%GDSL_BASIS% specifications/basis/bbtree.ml

set GDSL_ASM=
set GDSL_ASM=%GDSL_ASM%	specifications/asm/asm-cif.ml
set GDSL_ASM=%GDSL_ASM%	specifications/asm/asm.ml
set GDSL_ASM=%GDSL_ASM%	specifications/asm/asm-pretty.ml

set GDSL_X86= 
set GDSL_X86=%GDSL_X86% specifications/x86/x86.ml
set GDSL_X86=%GDSL_X86% specifications/x86/x86-traverse.ml
set GDSL_X86=%GDSL_X86% specifications/x86/x86-pretty.ml
set GDSL_X86=%GDSL_X86% specifications/x86/x86-asm.ml
set GDSL_X86=%GDSL_X86% specifications/x86/x86-semantics-mapping.ml
set GDSL_X86=%GDSL_X86% specifications/x86/x86-semantics-mapping-pretty.ml

set GDSL_X86SEM=
set GDSL_X86SEM=%GDSL_X86SEM% specifications/x86/x86-rreil-translator.ml
set GDSL_X86SEM=%GDSL_X86SEM% specifications/x86/x86-rreil-translator-a-l.ml
set GDSL_X86SEM=%GDSL_X86SEM% specifications/x86/x86-rreil-translator-m-z.ml
set GDSL_X86SEM=%GDSL_X86SEM% specifications/x86/x86-liveness.ml

set GDSL_AVR=
set GDSL_AVR=%GDSL_AVR% specifications/avr/avr.ml
set GDSL_AVR=%GDSL_AVR% specifications/avr/avr-asm.ml
set GDSL_AVR=%GDSL_AVR% specifications/avr/avr-traverse.ml
set GDSL_AVR=%GDSL_AVR% specifications/avr/avr-pretty.ml

set GDSL_AVRSEM=
set GDSL_AVRSEM=%GDSL_AVRSEM% specifications/avr/avr-rreil-translator.ml
set GDSL_AVRSEM=%GDSL_AVRSEM% specifications/avr/avr-rreil-registermapping.ml
set GDSL_AVRSEM=%GDSL_AVRSEM% specifications/avr/avr-rreil-pretty.ml
set GDSL_AVRSEM=%GDSL_AVRSEM% specifications/avr/avr-liveness.ml

set GDSL_MIPS=
set GDSL_MIPS=%GDSL_MIPS% specifications/mips/mips.ml
set GDSL_MIPS=%GDSL_MIPS% specifications/mips/mips-asm.ml
set GDSL_MIPS=%GDSL_MIPS% specifications/mips/mips-traverse.ml
set GDSL_MIPS=%GDSL_MIPS% specifications/mips/mips-pretty.ml

set GDSL_MIPSSEM=
set GDSL_MIPSSEM=%GDSL_MIPSSEM% specifications/mips/mips-rreil-translator.ml
set GDSL_MIPSSEM=%GDSL_MIPSSEM% specifications/mips/mips-rreil-registermapping.ml
set GDSL_MIPSSEM=%GDSL_MIPSSEM% specifications/mips/mips-rreil-pretty.ml
set GDSL_MIPSSEM=%GDSL_MIPSSEM% specifications/mips/mips-liveness.ml

set GDSL_RREIL=
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/fmap.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-examples.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-cif.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-pretty.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-liveness.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-forward-subst.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-cleanup.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-opt.ml
set GDSL_RREIL=%GDSL_RREIL% specifications/rreil/rreil-translator.ml

set GDSL_ARM7=
set GDSL_ARM7=%GDSL_ARM7% specifications/arm7/arm7.ml
set GDSL_ARM7=%GDSL_ARM7% specifications/arm7/arm7-pretty.ml

if NOT "%DECODER%"=="x86" goto NOT_x86
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_X86%
set OUT=gdsl-x86
:NOT_x86

if NOT "%DECODER%"=="x86-rreil" goto NOT_x86_rreil
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_X86% %GDSL_RREIL% %GDSL_X86SEM%
set OUT=gdsl-x86-rreil
:NOT_X86_rreil

if NOT "%DECODER%"=="avr" goto NOT_avr
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_AVR%
set OUT=gdsl-avr
:NOT_avr

if NOT "%DECODER%"=="avr-rreil" goto NOT_avr_rreil
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_AVR% %GDSL_RREIL% %GDSL_AVRSEM%
set OUT=gdsl-avr-rreil
:NOT_avr_rreil

if NOT "%DECODER%"=="mips" goto NOT_mips
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_MIPS%
set OUT=gdsl-mips
:NOT_mips

if NOT "%DECODER%"=="mips-rreil" goto NOT_mips_rreil
set SPEC=%GDSL_BASIS% %GDSL_ASM% %GDSL_MIPS% %GDSL_RREIL% %GDSL_MIPSSEM%
set OUT=gdsl-mips-rreil
:NOT_mips_rreil


if NOT "%DECODER%"=="arm7" goto NOT_arm7
set SPEC=%GDSL_BASIS% %GDSL_ARM7%
set OUT=gdsl-arm7
:NOT_arm7

Axel Simon's avatar
Axel Simon committed
177
echo Generating C code for %DECODER%.
Axel Simon's avatar
Axel Simon committed
178 179 180 181
gdslc.exe --target=C89 -o %OUT% %SPEC%
rem @echo off

if x%MSVC%x==xx (
Julian Kranz's avatar
Julian Kranz committed
182
echo Unable to compile the generated decoder since the compiler cannot be found.
Axel Simon's avatar
Axel Simon committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
goto End
)

rem Find out where to get kernel32.lib and friends. It's somewhere under "Windows Kits"
rem which resides in "Program Files (x86)". This will probably break occasionally, but
rem it works for my machine. I couldn't find a reliably registry key. Feedback welcome.
for /f "usebackq tokens=*" %%d in (`dir /ad /b /s "C:\Program Files (x86)\Windows Kits" ^| find "\x86" ^| find /i "lib"`) do set SDKLIBPATH=%%d

if NOT defined SDKLIBPATH (
	echo Cannot find SDK library directory. Use /sdklib switch to specify.
	goto Error
)


set MSVCBARE=%MSVC:.exe=%
set LIB=%MSVCBARE:\bin\cl=\lib%;"%SDKLIBPATH%"
set INCLUDE=%MSVCBARE:\bin\cl=\include%
set CL=

echo Compiling %OUT%.c
%MSVC% /Od /Gd /nologo /Za /D WITHMAIN /TC %OUT%.c /link /OUT:"%OUTDIR%%OUT%-demo.exe"

goto End

:Error
exit /b 1
:End