@echo off
rem
rem   @(#)configure.bat               PANDORE

rem   PANTHEON Project

rem   GREYC IMAGE
rem   6 Boulevard Maréchal Juin
rem   F-14050 Caen Cedex France

rem   This file is free software. You can use it, distribute it
rem   and/or modify it. However, the entire risk to the quality
rem   and performance of this program is with you.
rem
rem   Please email any bugs, comments, and/or additions to this file to:
rem   Regis.Clouard@greyc.ensicaen.fr
rem   http://www.greyc.ensicaen.fr/~regis


rem 
rem @author Régis Clouard - 2004-07-01
rem @author Régis Clouard - 2005-08-08 (+ qt)
rem 


rem   *** Set the VCHOME with the convenient Visual C++ directory.
rem   *** ex set VCHOME=C:\Program Files\Microsoft Visual Studio\VC98\
set VCHOME=

rem   *** Set the PANDORE_HOME with the convenient Pandore directory.
rem   *** ex set PANDORE_HOME=C:\Program Files\Microsoft Visual Studio\VC98\
set PANDORE_HOME=






















cls

rem ----------------------------------------------------------------------
rem    Search for pandore

echo searching Pandore directory ...

if exist "%PANDOREHOME%\lib\pandore.lib"  goto :found1
if exist "%PANDORE_HOME%\lib\pandore.lib"  (
	PANDOREHOME=%PANDORE_HOME%
	goto :found1
)

rem ... not found
echo *** ERROR. Cannot find Pandore directory
echo     Please edit configure.bat by hand
echo     and set PANDORE_HOME with the convenient Pandore directory;
echo     For example:
echo         set PANDORE_HOME=C:\Program Files\Pandore
echo.
goto :end

:found1
echo ... found in %PANDOREHOME%.

rem ----------------------------------------------------------------------
rem    Search for Visual C++ directory = Search for the file VCVARS32.BAT

echo searching Microsoft Visual C++ directory ...

if exist "%VCHOME%\bin\vcvars32.bat"  goto :found2

setlocal
for /f "Tokens=*" %%a in ('dir /s /b /ad "%ProgramFiles%\"') do (
 set VCHOME=%%a
 if exist "%%a\bin\vcvars32.bat" goto :found2
)
endlocal

rem ... not found
echo *** ERROR. Cannot find Microsoft Visual C++ directory
echo     Please edit configure.bat by hand
echo     and set VCHOME with the convenient C++ compiler directory;
echo     For example:
echo         set VCHOME=C:\Program Files\Microsoft Visual Studio\VC98
echo.
goto :end

:found2
echo ... found in %VCHOME%.

rem ----------------------------------------------------------------------
rem    Generate the makefile.bat file.
set makefile_file=./Makefile
echo generating makefile...
echo ## Makefile PANDORE> %makefile_file%
echo ##>> %makefile_file%
echo ##----------------------------------------------------------->> %makefile_file%
echo ## DO NOT EDIT BY HAND>> %makefile_file%
echo ## Autogenerated by ./configure.>> %makefile_file%
echo ## If something is wrong, fix ./configure and run it again.>> %makefile_file%
echo ##----------------------------------------------------------->> %makefile_file%
echo ##>> %makefile_file%
echo ## GREYC - IMAGE >> %makefile_file%
echo ## 6, boulevard Maréchal Juin 14050 CAEN. >> %makefile_file%
echo ## email : Regis.Clouard@greyc.ensicaen.fr>> %makefile_file%
echo ##>> %makefile_file%
echo.>> %makefile_file%
echo CPP=cl.exe>> %makefile_file%
echo CPPFLAGS=/nologo /MT /W3 /GR /GX /O2 /D "MAIN" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /FD /c /I "%PANDOREHOME%\include">>%makefile_file%

set CPPFLAGSOP=/I"%PANDOREHIOME%\src\operatorsP0">> %makefile_file%
set CPPFLAGSOP=%CPPFLAGSOP% /I.\src

echo CPPFLAGSOP=%CPPFLAGSOP%>> %makefile_file%
echo LD=link.exe>> %makefile_file%
echo LDFLAGSLIB=-lib /nologo>> %makefile_file%
echo LDFLAGSOP= /nologo /subsystem:console /incremental:no /machine:I386\>> %makefile_file%
echo 	/LIBPATH:"%PANDOREHOME%\lib" pandore.lib kernel32.lib user32.lib gdi32.lib winspool.lib\>> %makefile_file%
echo 	comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\>> %makefile_file%
echo 	odbc32.lib odbccp32.lib>> %makefile_file%

echo.>> %makefile_file%
echo OPERS=\>> %makefile_file%
for /f "tokens=1 delims=." %%b in ('dir src\*.cpp /b') do (
	echo 	bin\%%b.exe\>>%makefile_file%
)

echo.>> %makefile_file%
echo all: opers>> %makefile_file%
echo.>> %makefile_file%
echo.>> %makefile_file%
echo opers: $(OPERS)>> %makefile_file%

rem ** Operators
echo {src}.cpp{bin}.exe:>> %makefile_file%
echo 	$(CPP) $(CPPFLAGS) $(CPPFLAGSOP) /Fo$*.obj "$<">> %makefile_file%
echo 	-$(LD) $(LDFLAGSOP) /out:$@ $*.obj>> %makefile_file%
echo 	@erase $*.obj>> %makefile_file%
echo 	@erase vc??.*>> %makefile_file%

echo.>> %makefile_file%
echo clean :>> %makefile_file%
echo 	-@erase bin\*.obj>> %makefile_file%
echo 	-@erase vc*.*>> %makefile_file%

echo.>> %makefile_file%
echo distclean: clean>> %makefile_file%
echo 	-@erase Makefile>> %makefile_file%
echo 	-@erase install.bat>> %makefile_file%
echo 	-@erase $(OPERS)>> %makefile_file%

echo.>> %makefile_file%
for /f "tokens=1 delims=." %%b in ('dir src\*.cpp /b') do (
	echo bin\%%b.exe: src\%%b.cpp>>%makefile_file%
)
echo.>> %makefile_file%

rem ----------------------------------------------------------------------
rem    Generate the install.bat file.
set install_file=./install.bat
echo generating install.bat ...
echo @echo off>%install_file%
echo rem>>%install_file%
echo rem   @(#)install.bat               PANDORE>>%install_file%
echo. >>%install_file%
echo call "%VCHOME%\bin\vcvars32.bat">>%install_file%
echo set PATH=%%PATH%%;%%PANDOREHOME%%\bin>>%install_file%
echo echo Compiling the boxe operators ...>>%install_file%
echo nmake all>>%install_file%
echo echo Successfully installed>>%install_file%
echo echo.>>%install_file%
echo pause>>%install_file%

echo 8
echo.
echo SUMMARY
echo.
echo    Pandore directory: %PANDOREHOME%
echo    User directory is: %HOME%
echo.
echo    Microsoft Visual Directory is: %VCHOME%
echo    C++ compiler is: cl.exe
echo    Linker is: ld.exe
echo    Make is : nmake.exe
echo.
echo If this is correct, you can just launch the 'install' script.

:end
pause
