I'm going to guess, though I've never done this myself, that you'd do that through preprocessor directives in your source code. I'm thinking it would look something like:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
#include <whatever_header.h>
#else
#include <a_different_header.h>
#endif
Of course, you'll want to change the version in KERNEL_VERSION, but beyond that it should work.
Check out this post:
kernel version in C preprocessor