1 # Path information is stored on separate lines in XXXdirs.
2 # We check each directory exists and add it to the appropriate PATH.
3 # Prepend paths with XXXdirs.pre. They are guaranteed to precede other paths.
4 # Append paths with XXXdirs.post. They are not guaranteed to follow others.
5 # Set per-OS files in $SYSTEM[/$ARCHITECTURE] subdirectories of $DIR.
8 # Location of the XXXdirs files.
9 DIR=${PROFILE_HOME:-~}/.PATH
11 # Paths to set and the file to get them from @variable to copy from.
14 C_INCLUDE_PATH:incdirs
15 CPLUS_INCLUDE_PATH:@C_INCLUDE_PATH
16 LD_LIBRARY_PATH:libdirs
19 PKG_CONFIG_PATH:pkgdirs
22 function sanitisepath() {
23 local paths="${@//:/ }"
26 for path in $paths; do
29 paths="${paths#$path} "
30 if [ "${sane/:$path:/}" = "$sane" ]; then
42 # Set one path to be the same as another.
44 local newpath="$1"; shift
45 local oldpath="$1"; shift
47 # Sanitise and export.
48 local path="$(eval echo \$$oldpath)"
49 [ -z "$path" ] || eval "export $newpath='$path'"
54 local path="$1"; shift
57 dir=$(eval echo "$dir")
58 if [ -d "$dir" ]; then
65 # Set a path from directories.
67 local newpath="$1"; shift
68 local dirs="$1"; shift
70 # Set IFS to newline only so that we can read $(embedded shell commands).
77 path=$(addpath "$path" "$dir")
78 if [ -n "$PROFILE_HOME" -a ! "${dir#\$HOME}" = "$dir" ]; then
79 dir="$PROFILE_HOME${dir#\$HOME}"
80 path=$(addpath "$path" "$dir")
87 # Are we setting, prepending or appending?
88 local existing="$(eval echo \$$newpath)"
90 local where="${dirs##*.}"
93 pre) path="$path:$existing";;
94 post) path="$existing:$path";;
99 path=$(sanitisepath "$path")
100 [ -z "$path" ] && return
103 eval "export $newpath='$path'"
106 # Construct directory list, omitting nonexistent and undefined ones.
108 for dir in "${SYSTEM:-@}/${ARCHITECTURE:-@}" "${SYSTEM:-@}" ""; do
109 [ "${dir/@/}" = "$dir" ] || continue
110 [ -d "$DIR/$dir" ] || continue
111 dirs="$dirs,$DIR/$dir"
115 [ "${dirs/,/}" = "$dirs" ] || dirs="{$dirs}"
117 for path in $PATHS; do
121 if [ "${source#@}" = "$source" ]; then
122 for dir in $(eval echo $dirs/$source{,.pre,.post}); do
123 [ -e "$dir" ] || continue
124 makepath "$var" "$dir"
127 copypath "$var" "${source#@}"
132 unset DIR PATHS dir dirs path var source sanitisepath copypath makepath newpath addpath