== Starlink ==

In the following code substitute the actual release name for {{{<release>}}}.

Also change all paths as appropriate for the system.

=== Clone from GitHub ===

{{{
 cd /export/data/star
 git clone https://github.com/Starlink/starlink.git starlink-<release>
 cd starlink-<release>
 git checkout <release>
}}}

=== General Setup ===

{{{
 export STARLINK_DIR=/star-2025A
 export STARCONF_DEFAULT_STARLINK=${STARLINK_DIR}
 export STARCONF_DEFAULT_PREFIX=${STARLINK_DIR}
 export PERL_CPANM_HOME=/export/data/star/cpanm

 unset STARLINK
 unset INSTALL
 unset CFLAGS
 unset CXXFLAGS
 unset FFLAGS

 export LC_ALL=C
 export FC=gfortran
 export F77=gfortran
 export CC=gcc
 export CXX=g++

 export PATH=${STARLINK_DIR}/buildsupport/bin:${STARLINK_DIR}/bin:${PATH}
}}}

=== Linux ===

{{{
 unset LDFLAGS
 export CFLAGS="-g -O2"
 export CXXFLAGS="$CFLAGS"

 export LD_LIBRARY_PATH=$STARLINK_DIR/lib
}}}

For newer Linux (e.g. Rocky 9 with GCC 11)

{{{
 export CXXFLAGS="$CXXFLAGS -std=c++11"
}}}

{{{
 ./bootstrap
 make configure-deps
 ./configure -C
 make world
 make componentset.html
}}}

=== macOS ===

{{{
 # For Perl module build:
 export OPENSSL_PREFIX=/usr/local/opt/openssl@3

 export MACOSX_DEPLOYMENT_TARGET=11.0
 export LDFLAGS="-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -L/opt/X11/lib"
 export CFLAGS="-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -I/opt/X11/include -g -O2"
 export CXXFLAGS="$CFLAGS"

 # To avoid errors with hdf5 (and nbs...)
 export CFLAGS="$CFLAGS -Wno-error=incompatible-function-pointer-types"

 # To avoid problems later in macos_postbuild_library_fixup
 # where install_name_tool says the new load commands do not fit:
 export LDFLAGS="$LDFLAGS -headerpad_max_install_names"

 export DYLD_LIBRARY_PATH=$STARLINK_DIR/lib
}}}

{{{
 mkdir -p $STARLINK_DIR/lib
 cp /usr/local/opt/gcc/lib/gcc/current/libquadmath.0.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/gcc/lib/gcc/current/libgcc_s.1.1.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/libyaml/lib/libyaml-0.2.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/jpeg-turbo/lib/libjpeg.8.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/openssl@3/lib/libssl.3.dylib $STARLINK_DIR/lib/
 cp /usr/local/opt/openssl@3/lib/libcrypto.3.dylib $STARLINK_DIR/lib/
 ln -s libyaml-0.2.dylib $STARLINK_DIR/lib/libyaml.dylib

 ./bootstrap
 make configure-deps
 install_name_tool -change libtcl8.6.dylib $STARLINK_DIR/lib/libtcl8.6.dylib $STARLINK_DIR/bin/tclsh
 ./configure -C --without-vtk
 make world
 make componentset.html
}}}

== StarPerl ==

The Perl modules installer can be found in the ''perlmods'' subdirectory.

When creating a release branch, use the ''module2dist.sh'' script to write the current version of each Perl module and commit this to the branch.  You can do this first on any OS.

Change into the directory and for more information, see the instructions in the {{{README}}}.

{{{
 cd thirdparty/perlsys/perlmods/
 ./build-modules.sh
}}}

== StarJava ==

=== Linux ===

Download JDK (1.6) from Oracle. Download JAI from java.net: http://download.java.net/media/jai/builds/release/1_1_3/

Change directory to $STARCONF_DEFAULT_PREFIX and run the binary installer for the JDK, which will create jdk-<whatever> directories.  Change into the created jdk- directory, then run the binary installer for JAI, which will install JAI into the JDK directory.

{{{
 mv jdk-WHATEVER java
 export STAR_JAVA=$STARLINK_DIR/java/bin/java
}}}

There appears to be an issue with the permissions of issions of $STARCONF_DEFAULT_PREFIX/java/lib/htmlconverter.jar. By default this file seems (as of the 2015-A release) to have a default permission of only being readable to the owner. This has to be fixed, at least in the Hilo /star and /stardev installations as it will otherwise not be rsync-able.

=== macOS ===

Provide any copy of jai_core.jar and jai_codec.jar in CLASSPATH to allow the build to complete.

{{{
 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
 export STAR_JAVA=$JAVA_HOME/bin/java
 export CLASSPATH=/Users/star/jai/jai-1_1_2_01/lib/jai_core.jar:/Users/star/jai/jai-1_1_2_01/lib/jai_codec.jar
}}}

=== General Setup ===

{{{
 export LC_ALL=en_US.UTF-8
 export LANG=en_US.UTF-8
 export LANGUAGE=en_US.UTF-8
 unset DISPLAY
}}}

=== Both platforms ===

{{{
 git clone https://github.com/Starlink/starjava.git starjava-<release>
 cd starjava-<release>
 git checkout <release>

 cd ant
 OLDPATH=${PATH}
 export PATH=`pwd`/bin:${PATH}
}}}
{{{#!wiki comment
Make sure that the Starlink 'ant' command is first in your path by doing:

 ant -projecthelp

If you see references for Starlink in there, you've done it right. Then do:
}}}

{{{
  ant -Dstar.dir=${STARLINK_DIR}/starjava install
}}}

Start using the new ant:
{{{
 cd ..
 export PATH=${STARLINK_DIR}/starjava/bin:${OLDPATH}
}}}

And build starjava:
{{{
  ant -Dstardev=${STARLINK_DIR} -Dstar.dir=${STARLINK_DIR}/starjava install
}}}

Then build the JNI libraries:

In each of:

 * jniast
 * jnihds
 * splat

Do:
{{{
  ant -Dstardev=${STARLINK_DIR} -Dstar.dir=${STARLINK_DIR}/starjava build-native
  ant -Dstardev=${STARLINK_DIR} -Dstar.dir=${STARLINK_DIR}/starjava install
  ant -Dstardev=${STARLINK_DIR} -Dstar.dir=${STARLINK_DIR}/starjava test
}}}

It's important that the test stage succeeds. You may also want to check what
"ldd/otool -L" report as the shared library dependencies. SPLAT should be
able to read an NDF and report that the data type is NDF, not NDX.

== ORAC-DR ==
{{{
 cd $STARLINK_DIR/bin
 git clone https://github.com/Starlink/ORAC-DR.git oracdr
 cd oracdr
 git checkout <release>
 cd src/docs
 make install

 # Tidy up documents build tree?
 git clean -fdx
}}}

== Final tidy up ==

=== Create index of documents ===

{{{
  buildsupport/misc/docs_lis2index
}}}

=== Patch library paths (macOS only at present) ===

{{{
  # Add --sign option on M1.
  ./macos_postbuild_library_fixup
  sed -i '' -e '/Disable if library paths patched/s/if (1)/if (0)/' $STARLINK_DIR/etc/login
  sed -i '' -e '/Disable if library paths patched/s/if true/if false/' $STARLINK_DIR/etc/profile
}}}

=== Tidy release tree ===

Remove useless .dvi files:

{{{
  cd $STARLINK_DIR
  rm docs/*.htx/*.dvi
}}}

Recent Starlink releases seem to have left bin/oracdr/.git/ in place.  ORAC-DR uses this to set the PIPEVERS header -- the alternative would be to generate the ${ORAC_DIR}/oracdr.version file: see documentation for ORAC::Version::_oracversion().

=== Create release package ===

Finally make the release.  This must be done from the directory containing the release directory so that the source directory can be given as the plain directory name.  This ensures that it will unpack correctly into a simple subdirectory of the user's CWD when they unpack it.  The following command omits the -v option in order for errors not to be hidden amongst a lot of other output.

{{{
   cd $STARLINK_DIR/..
   tar -czf /export/data2/star/starlink-RELEASENAME-Linux_RCX.tar.gz star-2025A
}}}