@echo off
rem -------------------------------------------------------------------------
rem
rem Environment Variable Prerequisites:
rem
rem   SPCL_HOME  (Required!) 
rem
rem   CLASSPATH    (Required!) 
rem
rem   JAVA_HOME    (Required!) Must point at your Java Development Kit installation.
rem
rem -------------------------------------------------------------------------
rem Michael E. Locasto
rem 
rem cvs -d /home/mb/dat/cvs/w4115/final add [files]
rem cvs -d /home/mb/dat/cvs/w4115/final import [files]

rem save a copy of current java_home and other vars

set _JAVA_HOME=%JAVA_HOME%
set _SPCL_HOME=%SPCL_HOME%
set _CLASSPATH=%CLASSPATH%


rem setup our needed environment variables

set SPCL_HOME=C:\usr\projects\spcl\spcl-0.1
set JAVA_HOME=C:\opt\java\sdk\jdk1.4.1

set CLASSPATH=%CLASSPATH%;%SPCL_HOME%\lib\data.jar
set CLASSPATH=%CLASSPATH%;%SPCL_HOME%\lib\pole.jar
set CLASSPATH=%CLASSPATH%;%SPCL_HOME%\lib\polc.jar
set CLASSPATH=%CLASSPATH%;%SPCL_HOME%\lib\core.jar


if not "%JAVA_HOME%" == "" goto gotJavaHome
echo You must set JAVA_HOME to point at your Java Development Kit installation
goto cleanup
:gotJavaHome

if not "%SPCL_HOME%" == "" goto gotAPPHome
echo You must set SPCL_HOME to point at your application Development installation
goto cleanup
:gotAPPHome

rem We are compiling, so we change directory to the top of the source tree
cd %SPCL_HOME%\src


rem evaluate the command line argument ignore more than one - check 2 later

if "%1" == "" goto allCompile
if "%1" == "all" goto allCompile
if "%1" == "data" goto dataCompile
if "%1" == "polc" goto compilerCompile
if "%1" == "pole" goto pengineCompile
if "%1" == "core" goto coreCompile
if "%1" == "javadoc" goto makeJavaDoc
if "%1" == "clean" goto cleanCompile

rem if the command line arg does not match above choices, echo usage and quit

:doUsage
echo ------------------------------------------------------------------
echo Warning! Because of package dependencies there is a required order 
echo to compile-lication! You may compile parts because you may already 
echo have a stable jar in your classpath and you are working on another.
echo ------------------------------------------------------------------
echo Usage...  make [data][polc][pole][core][clean][javadoc][all] 
echo Commands:
echo   all -        Compile all packages and generate all jars
echo   data -       Compile the global data package
echo   scanner -    Compile the scanner package
echo   parser -     Compile the parser package
echo   core -       Compile the core compiler library package
echo   pengine -    Compile the PolicyEngine
echo   clean -      Clean out the classes directory structure
echo   javadoc -    Generate the Javadoc information
goto cleanup

goto cleanup

rem -- the source tree must start at spcl\..anything else will screw up the packages 

:allCompile

%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\data\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf data.jar spcl\data\*.class
move data.jar %SPCL_HOME%\lib
cd %SPCL_HOME%\src

%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\compiler\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf polc.jar spcl\compiler\*.class
move polc.jar %SPCL_HOME%\lib
cd %SPCL_HOME%\src

%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\policyengine\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf pole.jar spcl\policyengine\*.class
move pole.jar %SPCL_HOME%\lib
cd %SPCL_HOME%\src

%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\core\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf core.jar spcl\core\*.class
move core.jar %SPCL_HOME%\lib
cd %SPCL_HOME%\src
goto cleanup

:makeJavaDoc
set SOURCE_PATH1=%SPCL_HOME%\src\spcl\data\*.java
set SOURCE_PATH2=%SPCL_HOME%\src\spcl\compiler\*.java
set SOURCE_PATH3=%SPCL_HOME%\src\spcl\policyengine\*.java
set SOURCE_PATH4=%SPCL_HOME%\src\spcl\core\*.java


set OUTPUT_DIR=%SPCL_HOME%\docs\javadocs

%JAVA_HOME%\bin\javadoc -overview %SPCL_HOME%\docs\overview.html -author -public -d %OUTPUT_DIR% -classpath %CLASSPATH% -sourcepath %SOURCE_PATH1% %SOURCE_PATH2% %SOURCE_PATH3% %SOURCE_PATH4%
goto cleanup

:dataCompile
%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\data\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf data.jar spcl\data\*.class
move data.jar %SPCL_HOME%\lib
goto cleanup

:polcCompile
%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\compiler\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf polc.jar spcl\compiler\*.class
move polc.jar %SPCL_HOME%\lib
goto cleanup

:poleCompile
%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\policyengine\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf pole.jar spcl\policyengine\*.class
move pole.jar %SPCL_HOME%\lib
goto cleanup

:coreCompile
%JAVA_HOME%\bin\javac -d %SPCL_HOME%\classes -classpath %CLASSPATH% spcl\core\*.java
cd %SPCL_HOME%\classes
%JAVA_HOME%\bin\jar -cf core.jar spcl\core\*.class
move core.jar %SPCL_HOME%\lib
goto cleanup


:cleanCompile
del %SPCL_HOME%\classes\spcl\data\*.class
del %SPCL_HOME%\classes\spcl\compiler\*.class
del %SPCL_HOME%\classes\spcl\policyengine\*.class
del %SPCL_HOME%\classes\spcl\core\*.class

if "%2" == "-genjar" goto gencleanjar
goto cleanup

:gencleanjar
del %SPCL_HOME%\lib\*.jar
goto cleanup


rem ------ cleanup -----------------------------------------------------------------------
:cleanup
cd %SPCL_HOME%\bin

set CLASSPATH=%_CLASSPATH%
set _CLASSPATH=
set SPCL_HOME=%_SPCL_HOME%
set _SPCL_HOME=
set JAVA_HOME=%_JAVA_HOME%
set _JAVA_HOME=
rem echo done with cleanup - script ending..
:finish