3 while getopts p
:l
:r
:a
: OPT
; do
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}";;
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>"
21 # Only split on new lines, for filenames-with-spaces
26 # Skip firmware files, they could be ELF files for other
28 if [[ "${f}" =~ ^\.
/(usr
/)?lib
/firmware
/.
* ]]; then
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
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
50 # Architecture is correct
51 if test "${arch}" = "${arch_name}" ; then
55 printf 'ERROR: architecture for "%s
" is "%s
", should be "%s
"\n' \
56 "${f}" "${arch}" "${arch_name}"
59 done < <( sed -r -e "/^
${package},\.
(.
+)$
/!d
; s
//\
1/;" ${pkg_list} )