MacOS X App Octave Shell Script: Difference between revisions

From Octave
Jump to navigation Jump to search
No edit summary
(Mark as outdated.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Warning|This page is outdated (October 2019). For more recent information, see [[Octave for macOS]].}}
The script below is intended to be part of a [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|MacOS X App bundle for Octave]]. This script is called by the [[MacOS_X_App_Launcher_Script|App launcher script]]. The script is responsible for initializing the shell environment and running Octave.
The script below is intended to be part of a [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|MacOS X App bundle for Octave]]. This script is called by the [[MacOS_X_App_Launcher_Script|App launcher script]]. The script is responsible for initializing the shell environment and running Octave.


Line 24: Line 26:
VER="3.7.0+"
VER="3.7.0+"
if [ -L "$0" ] ; then
if [ -L "$0" ] ; then
  ROOT="$(dirname $(readlink -f "$0"))"
  ROOT="$(dirname $(readlink -n "$0"))"
else
else
  ROOT="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
  ROOT="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
Line 85: Line 87:


# Ghostscript stuff
# Ghostscript stuff
GS_LIB="${ROOT}/share/ghostscript/9.05/Resource/Init"
GS_LIB="${ROOT}/share/ghostscript/9.05/Resource/Init:${ROOT}/share/ghostscript/9.05/Resource:${ROOT}/share/ghostscript/9.05/iccprofiles:${ROOT}/lib"
GS_LIB="${GS_LIB}:${ROOT}/share/ghostscript/9.05/Resource"
if [ -z ${GS_FONTPATH} ]; then
if [ -z ${GS_FONTPATH} ]; then
   GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/Resource/Font"
   GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/9.05/Resource/Font:${ROOT}/share/fonts"
else
else
   GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/Resource/Font:${GS_FONTPATH}"
   GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/9.05/Resource/Font:$ROOT/share/fonts:${GS_FONTPATH}"
fi
fi
# Add /usr/X11/share/fonts to GS_FONTPATH ?
# Add /usr/X11/share/fonts to GS_FONTPATH
GS_FONTPATH="${GS_FONTPATH}:/usr/X11/share/fonts"
GS_OPTIONS="-sGenericResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/\""
GS_OPTIONS="-sGenericResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/\""
GS_OPTIONS="${GS_OPTIONS} -sFontResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/Font/\""
GS_OPTIONS="${GS_OPTIONS} -sFontResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/Font/\""
GS_OPTIONS="${GS_OPTIONS} -sICCProfilesDir=\"${ROOT}/share/ghostscript/9.05/iccprofiles/\""


# Gnuplot stuff
# Gnuplot stuff
GNUPLOT_HOME="${ROOT}"
GNUHELP="${ROOT}/share/gnuplot/4.6/gnuplot.gih"
GNUPLOT_DRIVER_DIR="${ROOT}/libexec/gnuplot/4.6"
GNUPLOT_FONTPATH="${ROOT}/share/fonts/urw-fonts"
# Add /usr/X11/share/fonts to GNUPLOT_FONTPATH
GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}:/usr/X11/share/fonts/TTF"
GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}:/usr/X11/share/fonts/Type1"
GNUPLOT_PS_DIR="${ROOT}/share/gnuplot/4.6/PostScript"
GNUPLOT_DEFAULT_GDFONT=Helvetica
GDFONTPATH="${ROOT}/Resources/share/ghostscript/fonts"
GNUTERM=aqua
GNUTERM=aqua
GNUTERMAPP="${ROOT}/Applications/AquaTerm.app"
GNUTERMAPP="${ROOT}/Applications/AquaTerm.app"
Line 103: Line 116:
# If AquaTerm is running, use AppleScript to tell it to quit. This is done to ensure
# If AquaTerm is running, use AppleScript to tell it to quit. This is done to ensure
# the AquaTerm which is running is part of the app bundle.
# the AquaTerm which is running is part of the app bundle.
export DYLD_FRAMEWORK_PATH
osascript 2>&1>/dev/null <<EOF
osascript 2>&1>/dev/null <<EOF
   tell application "System Events" to set ProcessList to get name of every process
   tell application "System Events" to set ProcessList to get name of every process
Line 113: Line 127:


# Invoke Octave, preserving spaces in all the input arguments.
# Invoke Octave, preserving spaces in all the input arguments.
OCTAVE_HOME="${OCTAVE_HOME}" PATH="${PATH}" \
OCTAVE_HOME="${OCTAVE_HOME}" \
PATH="${PATH}" \
  DYLD_FALLBACK_LIBRARY_PATH="${DYLD_FALLBACK_LIBRARY_PATH}" \
  DYLD_FALLBACK_LIBRARY_PATH="${DYLD_FALLBACK_LIBRARY_PATH}" \
  CC="${CC}" CXX="${CXX}" F77="${F77}" \
  CC="${CC}" \
  LD_CXX="${CXX}" DL_LD="${CXX}" \
CXX="${CXX}" \
  CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" \
F77="${F77}" \
  CXXFLAGS="${CXXFLAGS}" XTRA_CXXFLAGS="${XTRA_CXXFLAGS}" \
  LD_CXX="${CXX}" \
  FFLAGS="${FFLAGS}" LDFLAGS="${LDFLAGS}" FLIBS="${FLIBS}" \
DL_LD="${CXX}" \
  CFLAGS="${CFLAGS}" \
CPPFLAGS="${CPPFLAGS}" \
  CXXFLAGS="${CXXFLAGS}" \
XTRA_CXXFLAGS="${XTRA_CXXFLAGS}" \
  FFLAGS="${FFLAGS}" \
LDFLAGS="${LDFLAGS}" \
FLIBS="${FLIBS}" \
  DL_LDFLAGS="${DL_LDFLAGS}" \
  DL_LDFLAGS="${DL_LDFLAGS}" \
  INCLUDEDIR="${INCLUDEDIR}" LIBDIR="${LIBDIR}" \
  INCLUDEDIR="${INCLUDEDIR}" \
  OCTINCLUDEDIR="${OCTINCLUDEDIR}" OCTLIBDIR="${OCTLIBDIR}" \
LIBDIR="${LIBDIR}" \
  OCTINCLUDEDIR="${OCTINCLUDEDIR}" \
OCTLIBDIR="${OCTLIBDIR}" \
  OCT_LINK_OPTS="${OCT_LINK_OPTS}" \
  OCT_LINK_OPTS="${OCT_LINK_OPTS}" \
  SED="$SED" MAGICK_HOME="${ROOT}" \
  SED="$SED" MAGICK_HOME="${ROOT}" \
  FONTCONFIG_PATH="${ROOT}/etc/fonts" \
  FONTCONFIG_PATH="${ROOT}/etc/fonts" \
  GS_FONTPATH="${GS_FONTPATH}" GS_LIB="${GS_LIB}" GS_OPTIONS="${GS_OPTIONS}" \
  GS_FONTPATH="${GS_FONTPATH}" \
GS_LIB="${GS_LIB}" \
GS_OPTIONS="${GS_OPTIONS}" \
  DYLD_FRAMEWORK_PATH="${DYLD_FRAMEWORK_PATH}" \
  DYLD_FRAMEWORK_PATH="${DYLD_FRAMEWORK_PATH}" \
  AQUATERM_PATH="${AQUATERM_PATH}" \
  AQUATERM_PATH="${AQUATERM_PATH}" \
  GNUTERM="${GNUTERM}" \
  GNUTERM="${GNUTERM}" \
  GNUTERMAPP="${GNUTERMAPP}" \
  GNUTERMAPP="${GNUTERMAPP}" \
GNUPLOT_HOME="${GNUPLOT_HOME}" \
GNUHELP="${GNUHELP}" \
GNUPLOT_DRIVER_DIR="${GNUPLOT_DRIVER_DIR}" \
GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}" \
GNUPLOT_PS_DIR="${GNUPLOT_PS_DIR}" \
GNUPLOT_DEFAULT_GDFONT="${GNUPLOT_DEFAULT_GDFONT}" \
GDFONTPATH="${GDFONTPATH}" \
  "${ROOT}/bin/octave-$VER" "$@"
  "${ROOT}/bin/octave-$VER" "$@"


Line 140: Line 173:
   end tell
   end tell
EOF</nowiki>
EOF</nowiki>
[[Category:Outdated pages]]

Latest revision as of 14:15, 28 October 2019

Warning icon.svg
This page is outdated (October 2019). For more recent information, see Octave for macOS.

The script below is intended to be part of a MacOS X App bundle for Octave. This script is called by the App launcher script. The script is responsible for initializing the shell environment and running Octave.

The scripts name is "octave" and its location in the App bundle is Octave-x.y.z.app/Contents/Resources/bin/octave. Where x.y.z refers to the version of the bundled Octave.

#!/bin/sh
# Copyright (C) 2007-2008, Thomas Treichl and Paul Kienzle
# Copyright (C) 2009-2011, Thomas Treichl
# Copyright (C) 2012, Ben Abbott
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

# Checks if Octave is started from a file that is a link or if this
# file has been taken directly to startup the Octave program.

VER="3.7.0+"
if [ -L "$0" ] ; then
 ROOT="$(dirname $(readlink -n "$0"))"
else
 ROOT="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
fi
ROOT="$(dirname "${ROOT}")"

# Remove MacPorts from the path
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

# Setting up various path information variables that are needed to
# startup the Octave program.
OCTAVE_HOME="${ROOT}"
PATH="${ROOT}/bin:${PATH}"
if [ -z ${DYLD_FALLBACK_LIBRARY_PATH} ]; then
  DYLD_FALLBACK_LIBRARY_PATH="${ROOT}/lib"
else
  DYLD_FALLBACK_LIBRARY_PATH="${ROOT}/lib:${DYLD_FALLBACK_LIBRARY_PATH}"
fi
DYLD_FALLBACK_LIBRARY_PATH="${ROOT}/lib/octave/$VER:${DYLD_FALLBACK_LIBRARY_PATH}"
DYLD_FALLBACK_LIBRARY_PATH="${ROOT}/lib/gcc44:${DYLD_FALLBACK_LIBRARY_PATH}"
if [ -z ${DYLD_FRAMEWORK_PATH} ]; then
  DYLD_FRAMEWORK_PATH="${ROOT}/Library/Frameworks"
else
  DYLD_FRAMEWORK_PATH="${ROOT}/Library/Frameworks:${DYLD_FRAMEWORK_PATH}"
fi

# Setting up various path information variables that are needed to run
# the "mkoctfile" and "mex" commands from within the Octave program.
INCLUDEDIR="\"${ROOT}/include/Octave-${VER}\""
CFLAGS="-I\"${ROOT}/include/curl\" -I\"${ROOT}/include/readline\" ${CFLAGS}"
FFLAGS="-I\"${ROOT}/include/curl\" -I\"${ROOT}/include/readline\" ${FFLAGS}"
CPPFLAGS="-I\"${ROOT}/include/curl\" -I\"${ROOT}/include/readline\" ${CPPFLAGS}"
CXXFLAGS="-I\"${ROOT}/include/curl\" -I\"${ROOT}/include/readline\" ${CXXFLAGS}"
LDFLAGS="-L\"${ROOT}/lib\" -L\"${ROOT}/lib/octave/$VER\" ${LDFLAGS}"
XTRA_CXXFLAGS=" "

OCT_LINK_OPTS="\"${ROOT}/lib/gcc44/libstdc++.6.dylib\""
OCTLIBDIR="\"${ROOT}/lib/octave/${VER}\""
LIBDIR="\"${ROOT}/lib\""
OCTINCLUDEDIR="\"${ROOT}/include/Octave-${VER}/octave\""
# These default include paths are set by mkoctfile-2.9.12 automatically
# CFLAGS="-I${ROOT}/include -I${ROOT}/include/octave/$VER"

# Fortran stuff. FIXME - spaces in LIBDIR?
FLIBS="-L${LIBDIR} -L${LIBDIR}/gcc44/gcc/x86_64-apple-darwin11/4.4.6 -L${LIBDIR}/gcc44/gcc/x86_64-apple-darwin11/4.4.6/../../.. -lm -lgfortranbegin -lgfortran"

# Setting up other variables that are needed to run the Octave program
# or mkoctfile and to install packages.
DL_LDFLAGS="-bundle -bundle_loader \"${ROOT}/bin/octave-$VER\""
SED="/usr/bin/sed"
CC=`mkoctfile -p CC`
CXX=`mkoctfile -p CXX`
F77=`mkoctfile -p F77`
CC="$(basename $CC)"
CXX="$(basename $CXX)"
F77="$(basename $F77)"
CC=\"${ROOT}/bin/$CC\"
CXX=\"${ROOT}/bin/$CXX\"
F77=\"${ROOT}/bin/$F77\"

# Ghostscript stuff
GS_LIB="${ROOT}/share/ghostscript/9.05/Resource/Init:${ROOT}/share/ghostscript/9.05/Resource:${ROOT}/share/ghostscript/9.05/iccprofiles:${ROOT}/lib"
if [ -z ${GS_FONTPATH} ]; then
  GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/9.05/Resource/Font:${ROOT}/share/fonts"
else
  GS_FONTPATH="${GS_LIB}:${ROOT}/share/ghostscript/fonts:${ROOT}/share/ghostscript/9.05/Resource/Font:$ROOT/share/fonts:${GS_FONTPATH}"
fi
# Add /usr/X11/share/fonts to GS_FONTPATH
GS_FONTPATH="${GS_FONTPATH}:/usr/X11/share/fonts"
GS_OPTIONS="-sGenericResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/\""
GS_OPTIONS="${GS_OPTIONS} -sFontResourceDir=\"${ROOT}/share/ghostscript/9.05/Resource/Font/\""
GS_OPTIONS="${GS_OPTIONS} -sICCProfilesDir=\"${ROOT}/share/ghostscript/9.05/iccprofiles/\""

# Gnuplot stuff
GNUPLOT_HOME="${ROOT}"
GNUHELP="${ROOT}/share/gnuplot/4.6/gnuplot.gih"
GNUPLOT_DRIVER_DIR="${ROOT}/libexec/gnuplot/4.6"
GNUPLOT_FONTPATH="${ROOT}/share/fonts/urw-fonts"
# Add /usr/X11/share/fonts to GNUPLOT_FONTPATH
GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}:/usr/X11/share/fonts/TTF"
GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}:/usr/X11/share/fonts/Type1"
GNUPLOT_PS_DIR="${ROOT}/share/gnuplot/4.6/PostScript"
GNUPLOT_DEFAULT_GDFONT=Helvetica
GDFONTPATH="${ROOT}/Resources/share/ghostscript/fonts"
GNUTERM=aqua
GNUTERMAPP="${ROOT}/Applications/AquaTerm.app"
AQUATERM_PATH="${GNUTERMAPP}"

# If AquaTerm is running, use AppleScript to tell it to quit. This is done to ensure
# the AquaTerm which is running is part of the app bundle.
export DYLD_FRAMEWORK_PATH
osascript 2>&1>/dev/null <<EOF
  tell application "System Events" to set ProcessList to get name of every process
  if ProcessList contains "AquaTerm" then
    quit application "AquaTerm" 
    delay 0.5
  end if
EOF
open "${GNUTERMAPP}"

# Invoke Octave, preserving spaces in all the input arguments.
OCTAVE_HOME="${OCTAVE_HOME}" \
 PATH="${PATH}" \
 DYLD_FALLBACK_LIBRARY_PATH="${DYLD_FALLBACK_LIBRARY_PATH}" \
 CC="${CC}" \
 CXX="${CXX}" \
 F77="${F77}" \
 LD_CXX="${CXX}" \
 DL_LD="${CXX}" \
 CFLAGS="${CFLAGS}" \
 CPPFLAGS="${CPPFLAGS}" \
 CXXFLAGS="${CXXFLAGS}" \
 XTRA_CXXFLAGS="${XTRA_CXXFLAGS}" \
 FFLAGS="${FFLAGS}" \
 LDFLAGS="${LDFLAGS}" \
 FLIBS="${FLIBS}" \
 DL_LDFLAGS="${DL_LDFLAGS}" \
 INCLUDEDIR="${INCLUDEDIR}" \
 LIBDIR="${LIBDIR}" \
 OCTINCLUDEDIR="${OCTINCLUDEDIR}" \
 OCTLIBDIR="${OCTLIBDIR}" \
 OCT_LINK_OPTS="${OCT_LINK_OPTS}" \
 SED="$SED" MAGICK_HOME="${ROOT}" \
 FONTCONFIG_PATH="${ROOT}/etc/fonts" \
 GS_FONTPATH="${GS_FONTPATH}" \
 GS_LIB="${GS_LIB}" \
 GS_OPTIONS="${GS_OPTIONS}" \
 DYLD_FRAMEWORK_PATH="${DYLD_FRAMEWORK_PATH}" \
 AQUATERM_PATH="${AQUATERM_PATH}" \
 GNUTERM="${GNUTERM}" \
 GNUTERMAPP="${GNUTERMAPP}" \
 GNUPLOT_HOME="${GNUPLOT_HOME}" \
 GNUHELP="${GNUHELP}" \
 GNUPLOT_DRIVER_DIR="${GNUPLOT_DRIVER_DIR}" \
 GNUPLOT_FONTPATH="${GNUPLOT_FONTPATH}" \
 GNUPLOT_PS_DIR="${GNUPLOT_PS_DIR}" \
 GNUPLOT_DEFAULT_GDFONT="${GNUPLOT_DEFAULT_GDFONT}" \
 GDFONTPATH="${GDFONTPATH}" \
 "${ROOT}/bin/octave-$VER" "$@"

# Use AppleScript to kill the icon in the dock.
# FIXME - how to replace "Octave-3.7.0+" with "Octave-$VER"
osascript 2>&1>/dev/null <<EOF
  tell application "Octave-3.7.0+"
    quit
  end tell
EOF