summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/spack/csh/spack.csh71
-rw-r--r--share/spack/csh/spack_pathadd.csh23
-rwxr-xr-xshare/spack/setup-env.csh46
3 files changed, 140 insertions, 0 deletions
diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh
new file mode 100644
index 0000000000..2f6b96f4eb
--- /dev/null
+++ b/share/spack/csh/spack.csh
@@ -0,0 +1,71 @@
+########################################################################
+# This is a wrapper around the spack command that forwards calls to
+# 'spack use' and 'spack unuse' to shell functions. This in turn
+# allows them to be used to invoke dotkit functions.
+#
+# 'spack use' is smarter than just 'use' because it converts its
+# arguments into a unique spack spec that is then passed to dotkit
+# commands. This allows the user to use packages without knowing all
+# their installation details.
+#
+# e.g., rather than requring a full spec for libelf, the user can type:
+#
+# spack use libelf
+#
+# This will first find the available libelf dotkits and use a
+# matching one. If there are two versions of libelf, the user would
+# need to be more specific, e.g.:
+#
+# spack use libelf@0.8.13
+#
+# This is very similar to how regular spack commands work and it
+# avoids the need to come up with a user-friendly naming scheme for
+# spack dotfiles.
+########################################################################
+# Set up args -- we want a subcommand and a spec.
+set _sp_subcommand="";
+set _sp_spec="";
+[ $#_sp_args -gt 0 ] && set _sp_subcommand = ($_sp_args[1]);
+[ $#_sp_args -gt 1 ] && set _sp_spec = ($_sp_args[2-]);
+
+# Figure out what type of module we're running here.
+set _sp_modtype = "";
+switch ($_sp_subcommand)
+case use:
+case unuse:
+case load:
+case unload:
+ set _sp_module_args=""""
+ if ( "$_sp_spec" =~ "-*" ) then
+ set _sp_module_args = $_sp_spec[1]
+ shift _sp_spec
+ set _sp_spec = ($_sp_spec)
+ endif
+ # Translate the parameter into pieces of a command.
+ # _sp_modtype is an arg to spack module find, and
+ # _sp_sh_cmd is the equivalent shell command.
+ switch ($_sp_subcommand)
+ case use:
+ case unuse:
+ set _sp_modtype = dotkit
+ set _sp_sh_cmd = $_sp_subcommand
+ breaksw
+ case load:
+ case unload:
+ set _sp_modtype = tcl
+ set _sp_sh_cmd = ( module $_sp_subcommand )
+ breaksw
+ endsw
+
+ # Here the user has run use or unuse with a spec. Find a matching
+ # spec using 'spack module find', then use the appropriate module
+ # tool's commands to add/remove the result from the environment.
+ # If spack module command comes back with an error, do nothing.
+ if { set _sp_full_spec = `command spack module find $_sp_modtype $_sp_spec` } then
+ echo $_sp_sh_cmd $_sp_module_args $_sp_full_spec
+ endif
+default:
+ command spack $_sp_args
+endsw
+
+unset _sp_args _sp_full_spec _sp_modtype _sp_module_args _sp_sh_cmd _sp_spec _sp_subcommand
diff --git a/share/spack/csh/spack_pathadd.csh b/share/spack/csh/spack_pathadd.csh
new file mode 100644
index 0000000000..1e0800c5f3
--- /dev/null
+++ b/share/spack/csh/spack_pathadd.csh
@@ -0,0 +1,23 @@
+########################################################################
+# Prepends directories to path, if they exist.
+# pathadd /path/to/dir # add to PATH
+# or pathadd OTHERPATH /path/to/dir # add to OTHERPATH
+########################################################################
+# If no variable name is supplied, just append to PATH
+# otherwise append to that variable.
+set _pa_varname = PATH;
+set _pa_new_path = $_pa_args[1];
+[ $#_pa_args -gt 1 ] && set _pa_varname = $_pa_args[1] && set _pa_new_path = $_pa_args[2];
+
+# Check whether the variable is set yet.
+set _pa_old_value = ""
+eval set _pa_set = '$?'$_pa_varname
+[ $_pa_set -eq 1 ] && eval set _pa_old_value='$'$_pa_varname;
+
+# Do the actual prepending here, if it is a dir and not already in the path
+if ( -d $_pa_new_path && \:$_pa_old_value\: !~ *\:$_pa_new_path\:* ) then
+ [ -n "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path\:$_pa_old_value
+ [ -z "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path
+endif
+
+unset _pa_args _pa_new_path _pa_old_value _pa_set _pa_varname
diff --git a/share/spack/setup-env.csh b/share/spack/setup-env.csh
new file mode 100755
index 0000000000..e3243e40b2
--- /dev/null
+++ b/share/spack/setup-env.csh
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://scalability-llnl.github.io/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# 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) version 2.1 dated February 1999.
+#
+# 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 terms and
+# conditions of the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+
+#
+# This file is part of Spack and sets up the spack environment for
+# csh and tcsh. This includes dotkit support, module support, and
+# it also puts spack in your path. Source it like this:
+#
+# setenv SPACK_ROOT /path/to/spack
+# source $SPACK_ROOT/share/spack/setup-env.csh
+#
+if ($?SPACK_ROOT) then
+ set _spack_source_file = $SPACK_ROOT/share/spack/setup-env.csh
+ set _spack_share_dir = $SPACK_ROOT/share/spack
+
+ # Command aliases point at separate source files
+ alias spack 'set _sp_args = (\!*); source $_spack_share_dir/csh/spack.csh'
+ alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/spack_pathadd.csh'
+
+ # Set up modules and dotkit search paths in the user environment
+ _spack_pathadd DK_NODE "$_spack_share_dir/dotkit"
+ _spack_pathadd MODULEPATH "$_spack_share_dir/modules"
+ _spack_pathadd PATH "$SPACK_ROOT/bin"
+endif