!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! BUILDOPT macro for the NXM option tree (NeXtMidas as option tree inside X-Midas)
!
! OptDepend: NONE
!
!  @author  J. Czechowski IV
!  @version $Id: buildopt.txt,v 1.16 2015/03/30 13:23:10 ntn Exp $
!  @since   NeXtMidas 2.1.0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
startmacro A:optiontree
  local javahome, nxm, nmroot, foundshell

  ! Get the current settings for JAVAHOME and XMAREA_NXM
  import "JAVAHOME" javahome
  import "XMAREA_^{optiontree}" nxm

  ! If javahome is not set try to determine from path
  if javahome eqs "" then
    warn "Need to set environment variable JAVAHOME before building NXM"
    stop
  endif

  ! Calculate NMROOT from option tree location
  sedit/verbose nxm nmroot element 1 "/nxm/sys"
  export nmroot "NMROOT"

  say ""
  say "BUILDOPT;NXM: Setting NMROOT=^{nmroot}"

  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !! BUILD NEXTMIDAS
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  os source "^{NMROOT}/os/unix/nmstart"
  
  ! can't check for nxm/sys/lib/Shell.class because of mixed case
  find "^{NMROOT}/nxm/sys/prim/system.class" foundshell
  if foundshell neqs " " then
    say "NeXtMidas already built - bypassing 'nm make all'"
  else
    say "NeXtMidas not built - running 'nm make all'"
    os nm "make" "all"
  endif

  ! Use the %BUILDOPT_LIBXM macro in $NMROOT/nxm/sys/mcr to build the libxm
  ! directory.
  os nm "home mcr sys"
  os nm "%BUILDOPT_LIBXM"

  os source "^{NMROOT}/os/unix/nmend"
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !! END BUILD NEXTMIDAS
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  say "BUILDOPT;NXM: Running genmsginc"
  genmsginc "^optiontree"
  
  say "BUILDOPT;NXM: Building host primitives"
  xmbld * ,,, "^{optiontree}"
endmacro
