check-bin-arch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. pkg_files=$(sed -r -e "/^${package},(.+)$/!d; s//\1/;" ${pkg_list})
  18. for f in ${pkg_files} ; do
  19. # Skip firmware files, they could be ELF files for other
  20. # architectures
  21. if [[ "${f}" =~ ^\./(usr/)?lib/firmware/.* ]]; then
  22. continue
  23. fi
  24. # Get architecture using readelf. We pipe through 'head -1' so
  25. # that when the file is a static library (.a), we only take
  26. # into account the architecture of the first object file.
  27. arch=$(LC_ALL=C ${readelf} -h "${TARGET_DIR}/${f}" 2>&1 | \
  28. sed -r -e '/^ Machine: +(.+)/!d; s//\1/;' | head -1)
  29. # If no architecture found, assume it was not an ELF file
  30. if test "${arch}" = "" ; then
  31. continue
  32. fi
  33. # Architecture is correct
  34. if test "${arch}" = "${arch_name}" ; then
  35. continue
  36. fi
  37. printf 'ERROR: architecture for %s is %s, should be %s\n' \
  38. "${f}" "${arch}" "${arch_name}"
  39. exitcode=1
  40. done
  41. exit ${exitcode}