change_prefix.sh 2.53 KB
Newer Older
1 2 3 4
#!/bin/sh
# ***************************************************************************
# change_prefix.sh : allow to transfer a contrib dir
# ***************************************************************************
5
# Copyright (C) 2003 the VideoLAN team
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
6
# $Id$
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#
# Authors: Christophe Massiot <massiot@via.ecp.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29 30 31 32 33 34 35 36
# ***************************************************************************

usage="Usage: $0 <directory> <prefix> <new_prefix>"

LANG=C
export LANG

if test .$1 = .-h -o .$1 = .--help -o $# != 3; then
  echo $usage
  exit 1
fi

top_dir=`cd $1; pwd`
prefix=$2
37 38
new_prefix2=$3
new_prefix=/$new_prefix2
39 40 41 42 43 44 45

if test -z $prefix -o -z $new_prefix; then
  echo $usage
  exit 1
fi

cd $top_dir
46
pwd
47
files=`find . -type f`
48
for file in $files; do
49 50
 if test ".`file $file | grep Mach-O`" != "." ; then
    echo "Changing prefixes of '$file'"
51
    islib=n
52
    if test ".`file $file | grep 'dynamically linked shared library'`" != "." ; then
53 54
      islib=y
    fi
Christophe Massiot's avatar
Christophe Massiot committed
55
    libs=`otool -L $file 2>/dev/null | grep $prefix | cut -d\  -f 1`
56
    first=y
Christophe Massiot's avatar
Christophe Massiot committed
57
    for i in "" $libs; do
58 59
      if ! test -z $i; then
        if test $islib = y -a $first = y; then
60 61 62 63
            install_name_tool -id `echo $i | sed -e "s,$prefix,$new_prefix,"` $file
            first=n
        else
            install_name_tool -change $i `echo $i | sed -e "s,$prefix,$new_prefix,"` $file
64
        fi
Christophe Massiot's avatar
Christophe Massiot committed
65 66
      fi
    done
67 68
  elif test ".`file $file | grep \"text\|shell\"`" != "." -o ".`echo $file | grep pc$`" != "."; then
   echo "Fixing up shell/text/pc file "$file""
69
    cp $file $file.tmp
Christophe Massiot's avatar
Christophe Massiot committed
70 71
    sed -e "s,$prefix,$new_prefix,g" < $file > $file.tmp
    mv -f $file.tmp $file
72 73
  else
    echo "Not doing anything with $file"
Christophe Massiot's avatar
Christophe Massiot committed
74
  fi
75
done
76

77
files=`find . -name *.la`
78
for file in $files; do
79
   echo "Fixing up .la $file"
80
   cp $file $file.tmp
81 82 83 84
   sed -e "s,$prefix,$new_prefix,g" < $file > $file.tmp
   mv -f $file.tmp $file
done