diff --git a/configure b/configure index c9296e6c6d548ed521a8dd4422db1f42db01d040..50c00480b866d4c8a0d633e4a42cc56e84ff631a 100755 --- a/configure +++ b/configure @@ -23,6 +23,36 @@ error() { exit 1 } +cleanup-path() { #1 path + local dir="$1" + local motif rep dir2 + if [ -z "$dir" ]; then + return; + fi + dir="$dir/" + motif="//" + rep="/" + dir2="${dir/$motif/$rep}" + while test "$dir2" != "$dir"; do + dir="$dir2" + dir2=${dir/$motif/$rep} + done + motif="/./" + rep="/" + dir2="${dir/$motif/$rep}" + while test "$dir2" != "$dir"; do + dir="$dir2" + dir2=${dir/$motif/$rep} + done + dir2="$(echo "$dir" | sed -E -e 's,[^/]+/\.\./,,')" + while test "$dir2" != "$dir"; do + dir="$dir2" + dir2="$(echo "$dir" | sed -E -e 's,[^/]+/\.\./,,')" + done + dir="${dir%/}" + echo "$dir" +} + getopt -T >/dev/null 2>&1 if [ $? == 4 ]; then TMP="$(getopt --shell bash --options h \ @@ -38,6 +68,7 @@ fi cur_prefix="$(make --no-print-directory --quiet -f detect-current-prefix.mk)" TDS_current="$(kpsewhich -format texmfscripts LaTeX.mk | sed -e 's,/scripts/latex-make/LaTeX.mk$,,p;d')" +TDS_current="$(cleanup-path "$TDS_current")" SETUP= @@ -72,40 +103,51 @@ if [ $# != 0 ]; then error "Invalid argument '$1'" fi -if [ "$(uname -s)" == Linux -a -z "$SETUP" ]; then +if [ "$(uname -s)" != Linux -a -z "$SETUP" ]; then update fi +find-default-TDS() { + local dir + local TDS_default= + local TDS_default_fb= + for dir in "$@"; do + case "$dir" in + *-local) + if [ -z "$TDS_default" ]; then + TDS_default="$dir" + else + if [ "$(echo "$dir" | wc -c)" -lt "$(echo "$TDS_default" | wc -c)" ]; then + TDS_default="$dir" + fi + fi ;; + *) + if [ -z "$TDS_default_fb" ]; then + TDS_default_fb="$dir" + else + if [ "$(echo "$dir" | wc -c)" -lt "$(echo "$TDS_default_fb" | wc -c)" ]; then + TDS_default_fb="$dir" + fi + fi ;; + esac + done + if [ -z "$TDS_default" ]; then + TDS_default="$TDS_default_fb" + fi + echo "$TDS_default" +} + print-TDS() { # 1:starttoken declare -a loc declare -a home declare -a mid declare -a end declare -a all - declare -a defs + declare -a defs1 + declare -a defs2 while read dir; do - dir="$dir/" - motif="//" - rep="/" - dir2="${dir/$motif/$rep}" - while test "$dir2" != "$dir"; do - dir="$dir2" - dir2=${dir/$motif/$rep} - done - motif="/./" - rep="/" - dir2="${dir/$motif/$rep}" - while test "$dir2" != "$dir"; do - dir="$dir2" - dir2=${dir/$motif/$rep} - done - dir2="$(echo "$dir" | sed -e 's,[^/]\+/\.\./,,')" - while test "$dir2" != "$dir"; do - dir="$dir2" - dir2="$(echo "$dir" | sed -e 's,[^/]\+/\.\./,,')" - done - dir="${dir%/}" + dir="$(cleanup-path "$dir/")" case "$dir" in "") ;; *"/."*) end=("${end[@]}" "$dir");; @@ -132,37 +174,41 @@ print-TDS() { # 1:starttoken IFS=" " all=( $(trie loc) $(trie mid) $(trie home) $(trie end) ) - defs=( $(trie loc) $(trie mid) ) + defs1=( $(trie loc) ) + defs2=( $(trie mid) ) IFS="$OLD_IFS" - TDS_default= - for dir in "${defs[@]}"; do - case "$dir" in - *-local) - if [ -z "$TDS_default" ]; then - TDS_default="$dir" - else - if [ "$(echo "$dir" | wc -c)" -lt "$(echo "$TDS_default" | wc -c)" ]; then - TDS_default="$dir" - fi - fi ;; - esac - done + TDS_default="$(find-default-TDS "${defs1[@]}")" + if [ -z "$TDS_default" ]; then + TDS_default="$(find-default-TDS "${defs2[@]}")" + fi if [ -z "$TDS_default" ]; then TDS_default="${texmf_prefix:-$prefix/share/texmf}" fi if [ -z "$texmf_prefix" ]; then texmf_prefix="$TDS_default" fi - local rflag uflag cflag dflag pdir - for dir in "${all[@]}"; do + local rflag uflag cflag dflag aflag pdir + local cur="$(cleanup-path "$texmf_prefix")" + for dir in "${all[@]}" // ; do rflag="" uflag="" cflag="" dflag="" + aflag="" + if [ "$dir" == '//' ]; then + if [ "$cur" == '//' ]; then + continue + fi + dir="$cur" + fi if [ "$dir" == "$TDS_default" ]; then dflag="*" fi + if [ "$dir" == "$cur" ]; then + aflag="@" + cur='//' + fi if [ "$dir" == "$TDS_current" ]; then cflag="+" fi @@ -178,11 +224,11 @@ print-TDS() { # 1:starttoken if [ ! -w "$pdir" ]; then rflag="R" fi - printf "%s[%1s%1s%1s%1s] %s\n" "$1" "$dflag" "$cflag" "$rflag" "$uflag" "$dir" + printf "%s[%1s%1s%1s%1s%1s] %s\n" "$1" "$aflag" "$dflag" "$cflag" "$rflag" "$uflag" "$dir" done echo "### Current configuration" > config.mk echo "prefix=$prefix" >> config.mk - echo "texmf_prefix=$TDS_default" >> config.mk + echo "texmf_prefix=$texmf_prefix" >> config.mk } cat <<EOF @@ -213,6 +259,7 @@ print-TDS " " cat <<EOF Flags meaning: + @: current configuration *: default auto choice (not always the best one...) +: current installation (if an old installation is detected) R: read-only TDS. Use 'sudo' for 'make install' if choosen