-
Notifications
You must be signed in to change notification settings - Fork 10
/
gen_libraries
30 lines (25 loc) · 1.46 KB
/
gen_libraries
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
#!/bin/bash
# Get dependencies of a single ELF executable
get_deps()
{
ldd "$1" | grep -v "/lib64" | grep -v 'not a dynamic' | grep -v "linux-vdso" | grep -v '/usr/lib/.*/.*/.*.so' | grep -v "not found" | grep '^ ' | awk -F '=>' '{ print $1; };' | sed 's/(.*//g' | sort | uniq
}
# Get folders in output of ldd
get_folders()
{
ldd "$1" | grep '/usr/lib/.*/.*/.*.so' | grep -o '/.*/' | sed 's/\/usr\/lib\///g' | sed 's/\/$//g' | sort | uniq
}
compile_list()
{
# If $PRIMARY is a folder, this will find all files and run ldd on them (which will fail for files which aren't ELF executables)
PRIMARY="$1"
# $SECONDARY is an explicit list of additional libraries the program needs (beyond the ones that show up in ldd)
SECONDARY="$2"
mapfile -t LIBS < <(find "$PRIMARY" -type f -print0 | while IFS= read -r -d '' file; do get_deps "$file"; done | sort | uniq | tr -d '^\t' | tr -d ' $')
# LIBS=($(find "$PRIMARY" -type f -print0 | while IFS= read -r -d '' file; do get_deps "$file"; done | sort | uniq))
mapfile -t LIBFLDRS < <(find "$PRIMARY" -type f -print0 | while IFS= read -r -d '' file; do get_folders "$file"; done | sort | uniq | tr -d '^\t' | tr -d ' $')
# LIBFLDRS=($(find "$PRIMARY" -type f -print0 | while IFS= read -r -d '' file; do get_folders "$file"; done | sort | uniq))
mapfile -d ',' -t LIBS2 < <(echo -n "$SECONDARY")
# LIBS2=($(echo "$SECONDARY" | tr ',' ' '))
echo "${LIBS[@]}" "${LIBFLDRS[@]}" "${LIBS2[@]}" | tr ' ' ','
}