startmacro A:optiontree
  local javahome, nxm, nmroot

  ! 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
  ! TBS

  ! Calculate NMROOT from option tree location
  sedit/verbose nxm nmroot element 1 "/nxm/sys"
  say "Setting NMROOT to ^{nmroot}"

  export 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"

endmacro
