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