[15282] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | # script to extract and create aliases from source files |
---|
| 4 | |
---|
[15761] | 5 | # $Id: install-aliases,v 1.1.1.2 2001-03-13 16:43:31 ghudson Exp $ |
---|
[15282] | 6 | |
---|
| 7 | verbose=no |
---|
| 8 | dry_run=no |
---|
| 9 | |
---|
| 10 | # copy a .la file, editing the `dlname=' line to the new stem |
---|
| 11 | copy_la_file () { |
---|
| 12 | la_src="$1"; la_dest="$2"; shift 2 |
---|
| 13 | |
---|
| 14 | old_stem=`echo "$la_src" | sed -e 's|^.*/\([^/]*\)\.[^/]*$|\1|'` |
---|
| 15 | new_stem=`echo "$la_dest" | sed -e 's|^.*/\([^/]*\)\.[^/]*$|\1|'` |
---|
| 16 | |
---|
| 17 | sed -e '/^dlname=/ s/'"${old_stem}"'/'"${new_stem}"'/' \ |
---|
| 18 | < "$la_src" > "$la_dest" |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | # return the outermost directory of the filename |
---|
| 22 | prefix () { |
---|
| 23 | case "$1" in |
---|
| 24 | */*) |
---|
| 25 | echo "$1" | sed -e 's|^\([^/]*\)/.*$|\1|' |
---|
| 26 | ;; |
---|
| 27 | *) |
---|
| 28 | echo "" |
---|
| 29 | ;; |
---|
| 30 | esac |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | # return the filename without its outermost directory |
---|
| 34 | postfix () { |
---|
| 35 | echo "$1" | sed -e 's|^[^/]*/\(.*\)$|\1|' |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | # strip common leading directories from $2 |
---|
| 39 | strip_common_prefix () { |
---|
| 40 | str1="$1"; str2="$2"; shift 2 |
---|
| 41 | pfx=`prefix "$str1"`; str1=`postfix "$str1"` |
---|
| 42 | while [ x"$pfx" != x ]; do |
---|
| 43 | case "$str2" in |
---|
| 44 | $pfx*) |
---|
| 45 | str2=`postfix "$str2"` |
---|
| 46 | ;; |
---|
| 47 | *) |
---|
| 48 | break |
---|
| 49 | ;; |
---|
| 50 | esac |
---|
| 51 | pfx=`prefix "$str1"`; str1=`postfix "$str1"` |
---|
| 52 | done |
---|
| 53 | echo "$str2" |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | # turns `FOO/BAR/BAZ' into `FOO/BAR/libBAZ' |
---|
| 57 | lib_prefixed () { |
---|
| 58 | echo "$1" | sed -e 's|\([^/]*\)$|lib\1|' |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | dosome () { |
---|
| 62 | destroot="$1"; src="$2"; dest="$3"; shift 3 |
---|
| 63 | |
---|
| 64 | for g in `echo "${destroot}/${src}.*"`; do |
---|
| 65 | if [ -r "$g" ]; then |
---|
| 66 | suf=`echo "$g" | sed -e 's|^'"${destroot}/${src}"'\(.*\)$|\1|'` |
---|
| 67 | if [ $verbose = yes ]; then |
---|
| 68 | echo "${src}${suf} -> ${dest}${suf}" |
---|
| 69 | fi |
---|
| 70 | if [ $dry_run = no ]; then |
---|
| 71 | rm -f "${destroot}/${dest}${suf}" |
---|
| 72 | case "$suf" in |
---|
| 73 | .la) |
---|
| 74 | copy_la_file "${destroot}/${src}${suf}" \ |
---|
| 75 | "${destroot}/${dest}${suf}" |
---|
| 76 | ;; |
---|
| 77 | *) |
---|
| 78 | # make sure links are relative to their own directory |
---|
[15761] | 79 | local_src=`strip_common_prefix "$dest" "$src"` |
---|
| 80 | ln -s "${local_src}${suf}" "${destroot}/${dest}${suf}" |
---|
[15282] | 81 | ;; |
---|
| 82 | esac |
---|
| 83 | fi |
---|
| 84 | fi |
---|
| 85 | done |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | doit () { |
---|
| 89 | destroot="$1"; shift |
---|
| 90 | for f in $*; do |
---|
| 91 | src=`echo "$f" | sed -e 's/^\(.*\)#\(.*\)$/\1/'` |
---|
| 92 | dest=`echo "$f" | sed -e 's/^\(.*\)#\(.*\)$/\2/'` |
---|
| 93 | dosome "$destroot" "$src" "$dest" |
---|
| 94 | |
---|
| 95 | # libtool sometimes needs to prefix module libraries with a `lib' |
---|
| 96 | # prefix; this will try to pick up such libraries |
---|
| 97 | dosome "$destroot" `lib_prefixed "$src"` `lib_prefixed "$dest"` |
---|
| 98 | done |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | while [ x"$1" != x ]; do |
---|
| 102 | case $1 in |
---|
| 103 | -l) |
---|
| 104 | files=`find "$2" -name '*.jl' -print` |
---|
| 105 | aliases=`grep '(define-structure-alias' $files | |
---|
| 106 | sed -e 's/^.*(define-structure-alias \([^ ]*\) \([^ ]*\)).*$/\2#\1/' | |
---|
| 107 | tr . /` |
---|
| 108 | doit "$3" $aliases |
---|
| 109 | shift 3 |
---|
| 110 | ;; |
---|
| 111 | |
---|
| 112 | -c) |
---|
| 113 | files=`find "$2" -name '*.c' -print` |
---|
| 114 | aliases=`grep '::alias:' $files | |
---|
| 115 | sed -e 's/^.*::alias:\([^ ]*\) \(.*\)::.*$/\2#\1/' | |
---|
| 116 | tr . /` |
---|
| 117 | doit "$3" $aliases |
---|
| 118 | shift 3 |
---|
| 119 | ;; |
---|
| 120 | |
---|
| 121 | -v) verbose=yes; shift ;; |
---|
| 122 | -n) dry_run=yes; verbose=yes; shift ;; |
---|
| 123 | |
---|
| 124 | *) |
---|
| 125 | echo "usage [-v] [-n] [-l LISP-SRC-DIR LISP-INST-DIR] [-c C-SRC-DIR LA-INST-DIR]" |
---|
| 126 | exit 1 |
---|
| 127 | ;; |
---|
| 128 | esac |
---|
| 129 | done |
---|