2
1

check-kernel-headers.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. BUILDDIR="${1}"
  3. SYSROOT="${2}"
  4. # Make sure we have enough version components
  5. HDR_VER="${3}.0.0"
  6. HDR_M="${HDR_VER%%.*}"
  7. HDR_V="${HDR_VER#*.}"
  8. HDR_m="${HDR_V%%.*}"
  9. # Exit on any error, so we don't try to run an unexisting program if the
  10. # compilation fails.
  11. set -e
  12. # Set the clean-up trap in advance to prevent a race condition in which we
  13. # create the file but get a SIGTERM before setting it. Notice that we don't
  14. # need to care about EXEC being empty, since 'rm -f ""' does nothing.
  15. trap 'rm -f "${EXEC}"' EXIT
  16. EXEC="$(mktemp -p "${BUILDDIR}" -t .check-headers.XXXXXX)"
  17. # We do not want to account for the patch-level, since headers are
  18. # not supposed to change for different patchlevels, so we mask it out.
  19. # This only applies to kernels >= 3.0, but those are the only one
  20. # we actually care about; we treat all 2.6.x kernels equally.
  21. ${HOSTCC} -imacros "${SYSROOT}/usr/include/linux/version.h" \
  22. -x c -o "${EXEC}" - <<_EOF_
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. int main(int argc __attribute__((unused)),
  26. char** argv __attribute__((unused)))
  27. {
  28. if((LINUX_VERSION_CODE & ~0xFF)
  29. != KERNEL_VERSION(${HDR_M},${HDR_m},0))
  30. {
  31. printf("Incorrect selection of kernel headers: ");
  32. printf("expected %d.%d.x, got %d.%d.x\n", ${HDR_M}, ${HDR_m},
  33. ((LINUX_VERSION_CODE>>16) & 0xFF),
  34. ((LINUX_VERSION_CODE>>8) & 0xFF));
  35. return 1;
  36. }
  37. return 0;
  38. }
  39. _EOF_
  40. "${EXEC}"