check-kernel-headers.sh 1.1 KB

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