xref: /spdk/rpmbuild/rpm-deps.sh (revision cc6920a4763d4b9a43aa40583c8397d8f14fa100)
1#!/usr/bin/env bash
2# This script simply iterates over all libs SPDK binaries link
3# to and returns a list of .rpm packages SPDK may depend on. At
4# the end, the list strictly relates to how the SPDK build was
5# ./configure'd.
6
7shopt -s nullglob
8
9rpmdir=$(readlink -f "$(dirname "$0")")
10rootdir=$(readlink -f "$rpmdir/../")
11rc=0
12
13bins=("$rootdir/"build/{bin,examples}/*)
14(($#)) && bins=("$@")
15
16((${#bins[@]} > 0)) || exit 0
17
18source /etc/os-release
19
20id_ok=no
21
22for id in $ID $ID_LIKE; do
23	[[ "$id" =~ ^(fedora|centos|rhel) ]] && id_ok=yes
24done
25
26if [[ "$id_ok" != "yes" ]]; then
27	exit 0
28fi
29
30declare -A deps=()
31for bin in "${bins[@]}"; do
32	if ! type -P "$bin"; then
33		printf '%s is missing\n' "$bin" >&2
34		rc=1
35		continue
36	fi
37	while read -r name _ lib _; do
38		[[ -n $lib ]] || continue
39		[[ -z ${deps["$lib"]} ]] || continue
40		if [[ ! -e $lib ]]; then
41			lib=$name pkg="missing"
42			rc=1
43		elif ! pkg=$(rpm -qf "$lib"); then
44			pkg=${lib##*/}
45		fi
46		deps["$lib"]=$pkg
47	done < <(LD_TRACE_LOADED_OBJECTS=1 "$bin")
48done
49
50if [[ -n $LIST_LIBS ]]; then
51	for lib in "${!deps[@]}"; do
52		echo "$lib:${deps["$lib"]}"
53	done
54else
55	printf '%s\n' "${deps[@]}"
56fi | sort -u
57
58((rc == 0))
59