lofarinit.csh.in 5.29 KB
Newer Older
Ger van Diepen's avatar
Ger van Diepen committed
1 2 3 4 5 6
#!/bin/echo Usage: source
#-----------------------------------------------------------------------------
# lofarinit.csh: Define the LOFAR environment for C-like shells
#-----------------------------------------------------------------------------
#
# Copyright (C) 2005
Ger van Diepen's avatar
Ger van Diepen committed
7 8
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
Ger van Diepen's avatar
Ger van Diepen committed
9
#
Ger van Diepen's avatar
Ger van Diepen committed
10 11 12 13
# This file is part of the LOFAR software suite.
# The LOFAR software suite 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
Ger van Diepen's avatar
Ger van Diepen committed
14 15
# (at your option) any later version.
#
Ger van Diepen's avatar
Ger van Diepen committed
16
# The LOFAR software suite is distributed in the hope that it will be useful,
Ger van Diepen's avatar
Ger van Diepen committed
17 18 19 20
# 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.
#
Ger van Diepen's avatar
Ger van Diepen committed
21 22
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
Ger van Diepen's avatar
Ger van Diepen committed
23 24 25
#
# $Id$

Ger van Diepen's avatar
Ger van Diepen committed
26 27 28
# Define root here.
# This is a placeholder, so do NOT change the line.
# The actual value is filled in by make install (see Makefile.am).
29
set lfr_root=@prefix@
Ger van Diepen's avatar
Ger van Diepen committed
30 31
set lfr_libdir=@libdir@

32 33 34 35 36
# CMake does not define libdir, so we need to do things differently
if ("$lfr_libdir" == "") then
  set lfr_libdir=@CMAKE_INSTALL_PREFIX@/@LOFAR_LIBDIR@
endif

Ger van Diepen's avatar
Ger van Diepen committed
37 38
# Use only the basename of the the lib
set lfr_libdir=`basename $lfr_libdir`
Ger van Diepen's avatar
Ger van Diepen committed
39

40 41 42 43 44 45
# Get directory for Python modules relative to install prefix
set lfr_pylibdir=@PYTHON_INSTALL_DIR@
set lfr_pylibdir=`echo $lfr_pylibdir | sed 's,^@CMAKE_INSTALL_PREFIX@/,,'`
if ("$lfr_pylibdir" == "") then
    unset lfr_pylibdir
endif
Ger van Diepen's avatar
Ger van Diepen committed
46

Ger van Diepen's avatar
Ger van Diepen committed
47 48 49
# Only modify path variables if $lfr_root is an existing directory.
if (! (-d $lfr_root) ) then
    echo "LOFAR root directory $lfr_root does not exist"
Marcel Loose's avatar
Marcel Loose committed
50
else
Ger van Diepen's avatar
Ger van Diepen committed
51
    # First strip the current LOFARROOT from PATH, LD_LIBRARY_PATH, PYTHONPATH.
Marcel Loose's avatar
Marcel Loose committed
52 53
    # Take care that a possible . is preceeded by a backslash.
    if ($?LOFARROOT) then
Ger van Diepen's avatar
Ger van Diepen committed
54
        set lfr_path = `echo $LOFARROOT | sed -e 's/\./\\\./g'`
Ger van Diepen's avatar
Ger van Diepen committed
55
	if ($?PATH) then
Ger van Diepen's avatar
Ger van Diepen committed
56 57 58
	    foreach lfr_bin (bin sbin)
		set lfr_bin = "$lfr_path/$lfr_bin"
		setenv PATH `echo $PATH | sed -e "s%:${lfr_bin}:%:%g" -e "s%^${lfr_bin}:%%"  -e "s%:${lfr_bin}"'$%%' -e "s%^${lfr_bin}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
59
	    end
Ger van Diepen's avatar
Ger van Diepen committed
60 61
        endif
        if ($?LD_LIBRARY_PATH) then
Ger van Diepen's avatar
Ger van Diepen committed
62 63
            set lfr_lib = "$lfr_path/$lfr_libdir"
            setenv LD_LIBRARY_PATH `echo $LD_LIBRARY_PATH | sed -e "s%:${lfr_lib}:%:%g" -e "s%^${lfr_lib}:%%"  -e "s%:${lfr_lib}"'$%%' -e "s%^${lfr_lib}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
64
        endif
65
        if ($?PYTHONPATH && $?lfr_pylibdir) then
66
            set lfr_pyt = "$lfr_path/$lfr_pylibdir"
Ger van Diepen's avatar
Ger van Diepen committed
67
            setenv PYTHONPATH `echo $PYTHONPATH | sed -e "s%:${lfr_pyt}:%:%g" -e "s%^${lfr_pyt}:%%"  -e "s%:${lfr_pyt}"'$%%' -e "s%^${lfr_pyt}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
68
        endif
Marcel Loose's avatar
Marcel Loose committed
69 70 71
    endif

    # Now define the new LOFARROOT
Ger van Diepen's avatar
Ger van Diepen committed
72 73 74 75 76 77
    # If not needed, do not do cd;pwd because that resolves symlinks.
    if ( $lfr_root =~ /* ) then
        setenv LOFARROOT $lfr_root
    else
        setenv LOFARROOT `cd >/dev/null $lfr_root; pwd`   # make path absolute
    endif
Marcel Loose's avatar
Marcel Loose committed
78 79 80

    # Also strip this path from the current paths (in case it is contained in
    # it).
Ger van Diepen's avatar
Ger van Diepen committed
81
    set lfr_path = `echo $LOFARROOT | sed -e 's/\./\\\./g'`
Ger van Diepen's avatar
Ger van Diepen committed
82
    if ($?PATH) then
Ger van Diepen's avatar
Ger van Diepen committed
83 84 85
	foreach lfr_bin (bin sbin)
	    set lfr_bin = "$lfr_path/$lfr_bin"
            setenv PATH `echo $PATH | sed -e "s%:${lfr_bin}:%:%g" -e "s%^${lfr_bin}:%%"  -e "s%:${lfr_bin}"'$%%' -e "s%^${lfr_bin}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
86
	end
Ger van Diepen's avatar
Ger van Diepen committed
87 88
    endif
    if ($?LD_LIBRARY_PATH) then
Ger van Diepen's avatar
Ger van Diepen committed
89 90
        set lfr_lib = "$lfr_path/$lfr_libdir"
        setenv LD_LIBRARY_PATH `echo $LD_LIBRARY_PATH | sed -e "s%:${lfr_lib}:%:%g" -e "s%^${lfr_lib}:%%"  -e "s%:${lfr_lib}"'$%%' -e "s%^${lfr_lib}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
91
    endif
92
    if ($?PYTHONPATH && $?lfr_pylibdir) then
93
        set lfr_pyt = "$lfr_path/$lfr_pylibdir"
Ger van Diepen's avatar
Ger van Diepen committed
94
        setenv PYTHONPATH `echo $PYTHONPATH | sed -e "s%:${lfr_pyt}:%:%g" -e "s%^${lfr_pyt}:%%"  -e "s%:${lfr_pyt}"'$%%' -e "s%^${lfr_pyt}"'$%%'`
Ger van Diepen's avatar
Ger van Diepen committed
95 96
    endif

Marcel Loose's avatar
Marcel Loose committed
97 98
    # Add the path to the standard paths.
    if (! $?PATH) then
99
        setenv PATH $LOFARROOT/sbin:$LOFARROOT/bin
Marcel Loose's avatar
Marcel Loose committed
100
    else
101
        setenv PATH $LOFARROOT/sbin:$LOFARROOT/bin:$PATH
Marcel Loose's avatar
Marcel Loose committed
102 103
    endif
    if (! $?LD_LIBRARY_PATH) then
Ger van Diepen's avatar
Ger van Diepen committed
104
        setenv LD_LIBRARY_PATH $LOFARROOT/$lfr_libdir
Marcel Loose's avatar
Marcel Loose committed
105
    else
Arno Schoenmakers's avatar
Arno Schoenmakers committed
106
        setenv LD_LIBRARY_PATH $LOFARROOT/${lfr_libdir}:$LD_LIBRARY_PATH
Marcel Loose's avatar
Marcel Loose committed
107
    endif
108 109 110 111 112 113 114
    if ($?lfr_pylibdir) then
        set lfr_pyt = "$LOFARROOT/$lfr_pylibdir"
        if (! $?PYTHONPATH) then
            setenv PYTHONPATH $lfr_pyt
        else
            setenv PYTHONPATH ${lfr_pyt}:$PYTHONPATH
        endif
Ger van Diepen's avatar
Ger van Diepen committed
115
    endif
Ger van Diepen's avatar
Ger van Diepen committed
116

Ger van Diepen's avatar
Ger van Diepen committed
117 118
    # Now define the new LOFARDATAROOT (if possible).
    # First try as data directory of the LOFAR install directory.
Ger van Diepen's avatar
Ger van Diepen committed
119 120 121
    set lfr_path = `echo $LOFARROOT | sed -e 's%/installed.*%%'`
    if ( "$lfr_path" != ""  &&  -d $lfr_path/data ) then
        setenv LOFARDATAROOT $lfr_path/data
Ger van Diepen's avatar
Ger van Diepen committed
122 123
    else
        # Try it as the LOFARDATA directory (part of the source tree).
Ger van Diepen's avatar
Ger van Diepen committed
124 125 126
        set lfr_path = `echo $LOFARROOT | sed -e 's%/LOFAR/.*%/LOFAR%'`
        if ( "$lfr_path" != ""  &&  -d ${lfr_path}DATA ) then
            setenv LOFARDATAROOT ${lfr_path}DATA
Ger van Diepen's avatar
Ger van Diepen committed
127 128 129 130 131
        else
            setenv LOFARDATAROOT /opt/lofar/data
        endif
    endif

Ger van Diepen's avatar
Ger van Diepen committed
132
endif
Ger van Diepen's avatar
Ger van Diepen committed
133

134
unset lfr_root lfr_bin lfr_libdir lfr_lib lfr_pylibdir lfr_pyt lfr_path