+# Setup functions and settings used in subdirectories.
+#
+# Their setup.sh script sources this file.
+
+
+# csh gives the error "Unknown colorls variable `su'." when used with newer
+# options supported by zsh or GNU ls.
+unset LS_COLORS
+
+# Get path to m4 because it's later redefined as function.
+m4=`which m4`
+
+
+# Creates a symbolic link for file $1 in dirname of $2 with name of basenmae
+# $2.
+#
+# `./link.sh example ~/.examplerc` creates a symbolic link to example
+# (wherever it is located) in ~/ named .examplerc.
+link() {
+ # Get all necessary paths.
+ pwd=`pwd`
+ base=`dirname "$2"`
+ source=`echo -n "$pwd/$1" | sed "s|$base/||"`
+ target=`basename "$2"`
+
+ # Go to the directory where the link is going to be created.
+ cd "$base"
+
+ # Abort if the target file exists and is no symbolic link. Prevents
+ # overwriting real files.
+ if [ -e "$target" -a ! -h "$target" ]; then
+ echo "link(): target '$target' exists already and is no symbolic link!" >&2
+ exit 1
+ fi
+
+ # Make sure the source exists.
+ if [ ! -e "$source" ]; then
+ echo "link(): source '$source' doesn't exist!" >&2
+ exit 1
+ fi
+
+ # Create the new symbolic link; remove the old one if necessary.
+ echo "link(): linking '$source' to '$target'"
+ rm -f "$target"
+ ln -s "$source" "$target"
+
+ # Go back to the directory where we were before.
+ cd "$pwd"
+
+ unset pwd base source target
+}
+
+# m4 wrapper which uses $1.m4 as template file, feeds it to m4 and writes it
+# to $1 with a warning at the beginning to not edit the generated file.
+#
+# All arguments (except the first which is the filename) are passed to m4.
+m4() {
+ # First argument is file name.
+ file=$1
+ shift
+
+ # Write a warning to the generated file.
+ echo "###################################" > $file
+ echo "# WARNING! DO NOT EDIT THIS FILE! #" >> $file
+ echo "###################################" >> $file
+ echo >> $file
+ echo "# It was generated from $file.m4 on `date`." >> $file
+ echo >> $file
+
+ # Process $1.m4 with m4 using the given options.
+ echo "m4(): generating '$file' from '$file.m4' with options '$*'"
+ $m4 $* $file.m4 >> $file
+}