check-bin-arch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. while getopts p:l:r:a: OPT ; do
  3. case "${OPT}" in
  4. p) package="${OPTARG}";;
  5. l) pkg_list="${OPTARG}";;
  6. r) readelf="${OPTARG}";;
  7. a) arch_name="${OPTARG}";;
  8. :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
  9. \?) error "unknown option '%s'\n" "${OPTARG}";;
  10. esac
  11. done
  12. if test -z "${package}" -o -z "${pkg_list}" -o -z "${readelf}" -o -z "${arch_name}" ; then
  13. echo "Usage: $0 -p <pkg> -l <pkg-file-list> -r <readelf> -a <arch name>"
  14. exit 1
  15. fi
  16. exitcode=0
  17. # Only split on new lines, for filenames-with-spaces
  18. IFS="
  19. "
  20. while read f; do
  21. # Skip firmware files, they could be ELF files for other
  22. # architectures
  23. if [[ "${f}" =~ ^\./(usr/)?lib/firmware/.* ]]; then
  24. continue
  25. fi
  26. # Get architecture using readelf. We pipe through 'head -1' so
  27. # that when the file is a static library (.a), we only take
  28. # into account the architecture of the first object file.
  29. arch=$(LC_ALL=C ${readelf} -h "${TARGET_DIR}/${f}" 2>&1 | \
  30. sed -r -e '/^ Machine: +(.+)/!d; s//\1/;' | head -1)
  31. # If no architecture found, assume it was not an ELF file
  32. if test "${arch}" = "" ; then
  33. continue
  34. fi
  35. # Architecture is correct
  36. if test "${arch}" = "${arch_name}" ; then
  37. continue
  38. fi
  39. printf 'ERROR: architecture for "%s" is "%s", should be "%s"\n' \
  40. "${f}" "${arch}" "${arch_name}"
  41. exitcode=1
  42. done < <( sed -r -e "/^${package},\.(.+)$/!d; s//\1/;" ${pkg_list} )
  43. exit ${exitcode}