@echo off
REM Windows Makefile, by Neil Mitchell
REM <http://www.cs.york.ac.uk/~ndm/>

set CALL=call %0 JUMP
set DEFINE= -DFILEVERSION=\"2.04\" -DVERSION=\"2.04\"
set CPPHS=-cpp -pgmPcpphs -optP--cpp

set MKDIRS=%CALL% mkdirs
set COMPILE_C=%CALL% compile_c
set COMPILE_HS=%CALL% compile_hs

if "%1" == "JUMP" goto jump


REM Create Directories

%MKDIRS% obj obj\lib
%MKDIRS% windows windows\c

REM HatTrans
ghc --make src\hattrans\HatTrans.hs -isrc\hattrans;src\compiler98 %CPPHS% -o windows\hat-trans.exe -odir obj\hattrans -hidir obj\hattrans

REM C
copy include\*.h windows\c
copy src\hatlib\*.h windows\c
copy src\hatlib\*.c windows\c
gcc -c windows\c\hat-c.c %DEFINE% -o windows\c\hat-c.o

REM Hs - todo
REM Hx - todo

REM Compile all the Hat tools
%COMPILE_C% artutils pathutils observeutils finitemap ntohl hat-names
%COMPILE_HS% HatMake hat-make
gcc src\hattools\hat-check.c -Iinclude %DEFINE% -o windows\hat-check.exe obj\lib\ntohl.o
%COMPILE_HS% HatCover hat-cover
%COMPILE_HS% HatStack hat-stack
%COMPILE_HS% HatObserve hat-observe

goto exit


REM ROUTINES

:jump
set jump=%2
shift
shift
goto %jump%


:mkdirs
if not exist %1 mkdir %1
shift
if not "%1" == "" goto mkdirs
goto exit


:compile_c
gcc -c src\hattools\%1.c -o obj\lib\%1.o -Iinclude %DEFINE%
shift
if not "%1" == "" goto compile_c
goto exit


:compile_hs
if not exist obj\%2 mkdir obj\%2
ghc --make src\hattools\%1 -o windows\%2.exe -isrc\hattools %CPPHS% -ffi -fglasgow-exts obj\lib\*.o -odir obj\%2 -hidir obj\%2
goto exit


:exit
