check-kernel-headers.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. SYSROOT="${1}"
  3. # Make sure we have enough version components
  4. HDR_VER="${2}.0.0"
  5. HDR_M="${HDR_VER%%.*}"
  6. HDR_V="${HDR_VER#*.}"
  7. HDR_m="${HDR_V%%.*}"
  8. EXEC="$(mktemp -t check-headers.XXXXXX)"
  9. # We do not want to account for the patch-level, since headers are
  10. # not supposed to change for different patchlevels, so we mask it out.
  11. # This only applies to kernels >= 3.0, but those are the only one
  12. # we actually care about; we treat all 2.6.x kernels equally.
  13. ${HOSTCC} -imacros "${SYSROOT}/usr/include/linux/version.h" \
  14. -x c -o "${EXEC}" - <<_EOF_
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. int main(int argc __attribute__((unused)),
  18. char** argv __attribute__((unused)))
  19. {
  20. if((LINUX_VERSION_CODE & ~0xFF)
  21. != KERNEL_VERSION(${HDR_M},${HDR_m},0))
  22. {
  23. printf("Incorrect selection of kernel headers: ");
  24. printf("expected %d.%d.x, got %d.%d.x\n", ${HDR_M}, ${HDR_m},
  25. ((LINUX_VERSION_CODE>>16) & 0xFF),
  26. ((LINUX_VERSION_CODE>>8) & 0xFF));
  27. return 1;
  28. }
  29. return 0;
  30. }
  31. _EOF_
  32. "${EXEC}"
  33. ret=${?}
  34. rm -f "${EXEC}"
  35. exit ${ret}