@echo %NM_DEBUG% off
rem NeXtMidas build script
rem @author Jeff Schoen
rem @version $Id: nmbld.bat,v 1.12 2011/06/01 16:59:38 ntn Exp $

set routine=all
set area=%NM_DIR%
set option=%NM_OPT%
if not [%1]==[] set routine=%1
if not [%2]==[] set area=%2
if not [%3]==[] set option=%3

call nmsfset root opt.%option%
if [%root%]==[NotFound] set root=%NMROOT%

set cdir=%root%\nxm\%option%\%area%
set cpath=%cdir%\%routine%
set lpath=%cdir%\lib%routine%

if not [%routine%]==[all] goto NO_ALL
%NM_JB%\javac %NM_DEBUG% -classpath %NM_CP% %cdir%\*.java
:NO_ALL

if not exist %cpath%.java goto NO_JAVA
%NM_JB%\javac %NM_DEBUG% -classpath %NM_CP% %cpath%.java
:NO_JAVA

if not exist %cpath%.c goto NO_C
 if not defined NM_CC goto NO_CC
 if ["%NM_CC%"] == ["none"] goto NO_CC
 set cflags= %NM_DEBUG% -shared -Wl,--add-stdcall-alias 
 set cflags= %cflags% -I%root%\nxm\%option%\inc -I%NMROOT%\nxm\sys\inc 
 set cflags= %cflags% -I%JAVAHOME%\include -I%JAVAHOME%\include\win32 
 set cflags= %cflags% -I%NM_CC_INC% -D_DOS -D_WIN -D_W98
 %NM_JB%\javah -classpath %NM_CP% -jni -d %cdir% nxm.%option%.%area%.%routine%
 echo .  .  . compiling locally: %cpath%_win.dll
 if exist %lpath%.o set cflags= %cflags% %lpath%.o
 %NM_CC% %cflags% -o %cpath%_win.dll %cpath%.c
 del %root%\nxm\%option%\%area%\nxm_%option%_%area%_%routine%.h
 goto DONE
 
:NO_CC
 set prefile=%NM_DLLS%\%routine%_win.dll 
 echo .  .  . using pre-compiled %prefile%
 if exist %prefile% copy %prefile% %cdir% > null
:NO_C
:DONE