Guess the kernel and platform the code is compiling on
Hi there. I'm wondering if my source code (by means of gcc, of course) can guess the kind of kernel my machine is using and the platform it's being currently running on.
Something that looks like this: Code:
#ifdef X86 Any ideas? Thanks in advance. |
You can use GCC-specific predefined macros. This will work on all platforms, but only under gcc. To get a list, run
Code:
touch /tmp/foo.h gcc -dH /tmp/foo.h Code:
if(X86) { As an alternative, you could use a makefile, and define some constants: Code:
CCFLAGS=-DKERN=`uname -s` -DKERN_VER=`uname -v` -DKERN_REL=`uname -r`-DHARDWARE=`uname -m` -DPROC=`uname -p`-DPLATFORM=`uname -p` -DOS=`uname -o` |
Thanks a lot rjlee. Do you know something more about the first method (gcc method)? A link or anything is appreciated. Thanks ever so much.
|
A quick search on google yields up a list with descriptions at http://gcc.gnu.org/onlinedocs/gcc-4....defined-Macros
|
All times are GMT -5. The time now is 12:19 PM. |