forked from ghc-ios/ghc-ios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 8
/
libtool-lite
executable file
·72 lines (64 loc) · 1.5 KB
/
libtool-lite
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
# This script pretends to be libtool. And supports
# only a limited set of flags.
#
# It is supposed to be a stand in for libtool -static, whic
# creates a static archive. This is done by locating all -l<lib>
# libs in the provied -L<lib path> library paths, and building an
# MRI script to create the final archive from all the libraries, and
# other provided inputs.
#
name=${0##*/}
target=${name%-*}
set -e
ldflags_L=()
ldflags_l=()
output=""
inputs=()
STATIC=0
DYNAMIC=1
mode=$DYNAMIC
verbose=0
# find_lib <name> path path path path
function find_lib () {
lib=$1; shift 1;
for dir in $@; do
if [ -f "$dir/$lib" ]; then
echo "$dir/$lib"
break
fi
done
}
while [ "$#" -gt 0 ]; do
case "$1" in
-v|--verbose) verbose=1; shift 1;;
-o) output="$2"; shift 2;;
-L*) ldflags_L+=("${1:2:${#1}-2}"); shift 1;;
-l*) ldflags_l+=("lib${1:2:${#1}-2}.a"); shift 1;;
-static) mode=$STATIC; shift 1;;
-dynamic) mode=$DYNAMIC; shift 1;;
-Wl,*) ldflags+=("${1#*,}"); shift 1;;
-*) echo "unknown option: $1" >&2; exit 1;;
*) inputs+=("$1"); shift 1;;
esac
done
if [ ! $mode == $STATIC ]; then
echo "-dynamic not supported!" >&2; exit 1;
fi
MRI="create ${output}\n"
for input in "${ldflags_l[@]}"; do
lib=$(find_lib $input ${ldflags_L[@]})
if [ -z $lib ]; then
echo "Failed to find lib $input" >&2
exit 1
else
MRI+="addlib $lib\n"
continue
fi
done
for input in "${inputs[@]}"; do
MRI+="addmod $input\n"
done
MRI+="save\nend\n"
echo -e "$MRI" | $target-ar -M
$target-ranlib $output