+# $Id$
+#
+# Path information is stored on separate lines in XXXdirs.
+# We extract each directory exists and add it to the appropriate PATH.
+#
+
+# Location of the XXXdirs files.
+DIR=$HOME/.profile.d
+
+# Set one path to be the same as another.
+function copypath() {
+ newpath="$1"; shift
+ oldpath="$1"; shift
+
+ # Sanitise and export.
+ path="$(eval echo \$$oldpath)"
+ [ -z "$path" ] || eval export $newpath="$path"
+
+ unset path newpath oldpath
+}
+
+# Set a path from directories.
+function makepath() {
+ newpath="$1"; shift
+ dirs="$1"; shift
+
+ # Check the file exists.
+ [ -e "$DIR/$dirs" ] || return
+
+ # Read them.
+ path=
+ for dir in $(cat "$DIR/$dirs"); do
+ [ -d "$dir" ] || continue
+
+ path="$path:$dir"
+ done
+
+ # Sanitise path.
+ path=${path#:}
+ [ -z "$path" ] && return
+
+ # Export.
+ eval export $newpath="$path"
+
+ unset path newpath dirs
+}
+
+makepath PATH bindirs
+makepath C_INCLUDE_PATH incdirs
+copypath CPLUS_INCLUDE_PATH C_INCLUDE_PATH
+makepath LD_LIBRARY_PATH libdirs
+copypath LD_RUN_PATH LD_LIBRARY_PATH
+makepath MANPATH mandirs
+makepath PKG_CONFIG_PATH pkgdirs
+
+unset sedscr makepath copypath