support/script/check-bin-arch: ignore /usr/share
[buildroot-gz.git] / support / scripts / check-bin-arch
blobe1c99e6e7adb31d008450290b943e820c62a1577
1 #!/bin/bash
3 while getopts p:l:r:a: OPT ; do
4 case "${OPT}" in
5 p) package="${OPTARG}";;
6 l) pkg_list="${OPTARG}";;
7 r) readelf="${OPTARG}";;
8 a) arch_name="${OPTARG}";;
9 :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
10 \?) error "unknown option '%s'\n" "${OPTARG}";;
11 esac
12 done
14 if test -z "${package}" -o -z "${pkg_list}" -o -z "${readelf}" -o -z "${arch_name}" ; then
15 echo "Usage: $0 -p <pkg> -l <pkg-file-list> -r <readelf> -a <arch name>"
16 exit 1
19 exitcode=0
21 # Only split on new lines, for filenames-with-spaces
22 IFS="
25 while read f; do
26 # Skip firmware files, they could be ELF files for other
27 # architectures
28 if [[ "${f}" =~ ^\./(usr/)?lib/firmware/.* ]]; then
29 continue
32 # Skip files in /usr/share, several packages (qemu,
33 # pru-software-support) legitimately install ELF binaries that
34 # are not for the target architecture
35 if [[ "${f}" =~ ^\./usr/share/.* ]]; then
36 continue
39 # Get architecture using readelf. We pipe through 'head -1' so
40 # that when the file is a static library (.a), we only take
41 # into account the architecture of the first object file.
42 arch=$(LC_ALL=C ${readelf} -h "${TARGET_DIR}/${f}" 2>&1 | \
43 sed -r -e '/^ Machine: +(.+)/!d; s//\1/;' | head -1)
45 # If no architecture found, assume it was not an ELF file
46 if test "${arch}" = "" ; then
47 continue
50 # Architecture is correct
51 if test "${arch}" = "${arch_name}" ; then
52 continue
55 printf 'ERROR: architecture for "%s" is "%s", should be "%s"\n' \
56 "${f}" "${arch}" "${arch_name}"
58 exitcode=1
59 done < <( sed -r -e "/^${package},\.(.+)$/!d; s//\1/;" ${pkg_list} )
61 exit ${exitcode}