forked from FunkyM/install_name_prefix_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_name_prefix_tool.sh
executable file
·72 lines (63 loc) · 1.9 KB
/
install_name_prefix_tool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# install_name_prefix_tool
#
# Copyright (c) 2013 Martin Szulecki <[email protected]>
#
# Licensed under the GNU General Public License Version 2
#
# This script 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 script 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 profile.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
if [ $# -lt 3 ]
then
echo "Usage: ${0##*/} <DIR|FILE> <OLD> <NEW>"
echo "Changes the library prefix from OLD to NEW for each <DIR>/*.dylib or executable <FILE>."
exit 1
fi
TARGETS=$1
PREFIX=$2
NEWPREFIX=$3
if [[ -d $TARGETS ]]; then
TARGETS=$TARGETS/*.dylib
elif [[ -f $TARGETS ]]; then
TARGETS="$TARGETS"
else
echo "Error: \"$TARGETS\" does not exist."
exit 1
fi
if [ ! -d $PREFIX ]
then
echo "Warning: Prefix \"$PREFIX\" does not exist."
exit 1
fi
INSTALL_NAME_TOOL_BIN=$(which install_name_tool)
OTOOL_BIN=$(which otool)
GREP_BIN=$(which egrep)
for lib in $TARGETS;
do
echo "Modifing library \"$lib\"..."
lib_basename=$(basename $lib)
for entry in $($OTOOL_BIN -L $lib | $GREP_BIN -o "$PREFIX/([^[:space:]]*)");
do
entry_basename=$(basename $entry)
entry_target="$NEWPREFIX/$entry_basename"
ID_ADD=""
if [ "$lib_basename" = "$entry_basename" ];
then
ID_ADD="-id $entry_basename"
fi
echo "Changing prefix \"$entry\" to \"$entry_target\"..."
$INSTALL_NAME_TOOL_BIN -change $entry $entry_target $ID_ADD $lib
done
done