-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolve-libs
executable file
·83 lines (71 loc) · 1.39 KB
/
resolve-libs
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
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Author: Ivan Perez - Keera Studios (c) 2014
declare -A all_deps
declare -a all_libs
pending=0
GHC_PKG=$1
shift
function add_lib {
if [ "${all_deps[$1]}" == "" ] ; then
if [ "$1" != "builtin_rts" ] ; then
all_deps[$1]='0';
((pending+=1))
else
all_deps['rts']='1';
fi
fi
}
function add_top {
var=$($GHC_PKG --simple-output field $1 id | awk '{gsub("-[^-]+$"," "); print $0 ; }')
add_lib $var
}
function list_deps {
# One less dep
((pending-=1))
all_deps[$1]='1';
# Find deps
var=($($GHC_PKG --simple-output field $1 depends | awk '{gsub("-[^-]+( |$)"," ");print $0 ; }'))
# Add to array
for i in "${var[@]}"
do
add_lib $i
done
}
function next_lib {
for i in "${!all_deps[@]}"
do
if [ "${all_deps[$i]}" == "0" ]; then
echo $i;
break;
fi
done
}
function find_lib {
path=$($GHC_PKG --simple-output field $1 library-dirs | awk '{print $1}')
libs=($($GHC_PKG --simple-output field $1 hs-libraries))
for lib in "${libs[@]}"
do
all_libs+=("$path/lib$lib.a")
done
}
function find_all_libs {
for i in "${!all_deps[@]}"
do
find_lib $i
done
}
add_top "$1"
while [ "$pending" != "0" ]; do
lib=$(next_lib)
if [[ "$lib" == "" ]]; then
echo "Error"
break
else
list_deps $lib
fi
done
find_all_libs
for i in "${all_libs[@]}"
do
echo $i # ${all_deps[$i]}
done