check-kernel-headers.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. CC="${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="/tmp/br.check-headers.$(uuidgen)"
  9. # By the time we get here, we do not always have the staging-dir
  10. # already populated (think external toolchain), so we can not use
  11. # it.
  12. # So we just ask the cross compiler what its default sysroot is.
  13. # For multilib-aware toolchains where we should use a non-default
  14. # sysroot, it's not really a problem since the version of the kernel
  15. # headers is the same for all sysroots.
  16. SYSROOT=$(${CC} -print-sysroot)
  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}"
  41. ret=${?}
  42. rm -f "${EXEC}"
  43. exit ${ret}