Post #73,500
1/8/03 7:48:54 PM
|
Determining platform type/OS in gcc via #defines
Is there a .h to include, or some sort of built-in #define that I can use to determine chip type and OS in gcc?
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,505
1/8/03 8:26:13 PM
|
Maybe Mozilla source would help...
Or maybe not. There's a web page with browsable code, and a CPU routine [link|http://lxr.mozilla.org/seamonkey/source/gc/boehm/os_dep.c|here].
It's pretty messy and is likely far more elaborate than you need... Going up the tree to .../boehm/ gives the other files in the build.
Good luck.
Cheers, Scott.
|
Post #73,538
1/8/03 9:34:57 PM
|
Yes, this is the sort of thing I was looking for:
[link|http://lxr.mozilla.org/seamonkey/source/gc/boehm/gcconfig.h#27|http://lxr.mozilla.o...ehm/gcconfig.h#27]
Thanks. I'll try it out tomorrow at work.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,509
1/8/03 8:35:32 PM
|
Is this on Linux?
Make system do a uname -a.
-drl
|
Post #73,519
1/8/03 8:54:28 PM
|
what he said
will work for cash and other incentives [link|http://home.tampabay.rr.com/boxley/resume/Resume.html|skill set]
You think that you can trust the government to look after your rights? ask an Indian
|
Post #73,537
1/8/03 9:33:28 PM
|
I wasn't clear enough.
I need this to happen at compile time. Currently, the build system generates -D entries based on things like uname. I would like to determine OS/platform (endian stuff, really, but I can get that from endian.h on unix platforms) based on built-in #defines produced by the compiler or present in system .h files. I don't want to have to detect the OS in the build system.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,545
1/8/03 9:59:56 PM
|
Gotta be a #pragma right?
You basically tell the compiler "do this if this is the environment..."
-drl
|
Post #73,548
1/8/03 10:03:15 PM
|
#define
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,568
1/8/03 11:17:19 PM
|
/usr/include/machine/cpu.h (like that?)
will work for cash and other incentives [link|http://home.tampabay.rr.com/boxley/resume/Resume.html|skill set]
You think that you can trust the government to look after your rights? ask an Indian
|
Post #73,570
1/8/03 11:21:24 PM
|
Doesn't exist on this box.
Or were you just giving an example of what you thought I was looking for?
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,571
1/8/03 11:27:50 PM
|
osx has 3 entries
/usr/include/machine/cpu.h * @APPLE_LICENSE_HEADER_END@ */
#ifndef _BSD_MACHINE_CPU_H_ #define _BSD_MACHINE_CPU_H_
#if defined (__ppc__) #include "ppc/cpu.h" #elif defined (__i386__) #include "i386/cpu.h" #else #error architecture not supported #endif #endif /* _BSD_MACHINE_CPU_H_ */
as you can see it is a stub so you might be able to write one out and add it to the build. /usr/include/i386/cpu.h * @APPLE_LICENSE_HEADER_END@ */ /* * HISTORY * */
#ifndef _BSD_I386_CPU_H_ #define _BSD_I386_CPU_H_ #include <sys/appleapiopts.h>
#ifdef __APPLE_API_OBSOLETE #define cpu_number() (0) #endif /* __APPLE_API_OBSOLETE */
#endif /* _BSD_I386_CPU_H_ */
hope anything helps, you might want to write one thanx, bill
will work for cash and other incentives [link|http://home.tampabay.rr.com/boxley/resume/Resume.html|skill set]
You think that you can trust the government to look after your rights? ask an Indian
|
Post #73,573
1/8/03 11:39:26 PM
|
Heh. No /usr/include/i386 either.
But yes, that's the sort of thing I'm looking for. Thanks.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,533
1/8/03 9:24:43 PM
|
I don't really have an answer handy...
...but the question is whether you want that information at compile time or at run time?
|
Post #73,539
1/8/03 9:35:48 PM
|
Compile time, without passing -D switches.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,542
1/8/03 9:41:52 PM
|
If memory serves me correct...
...those -D switches are really just macro constants in disguise. So you should be able to use the constants in conditional compilation tests.
|
Post #73,544
1/8/03 9:53:26 PM
|
Right. But I don't want to pass -D switches. :-)
That's what I'm doing now; ie. on Linux I add -D_LINUX to the gcc command line, and look for #ifdef _LINUX in the code. I'm looking for a predefined macro constant so I don't have to pass the -D switches any more.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,588
1/9/03 4:14:56 AM
|
Could autoconf help?
I've seen lot of programs do build-type checks in autoconf.
Wade.
Microsoft are clearly boiling the frogs.
|
Post #73,608
1/9/03 8:19:36 AM
|
We have our own build system; autoconf not a part of it
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,689
1/9/03 1:24:15 PM
|
Autoconf could still be useful
The way it works is that it runs a bunch of tests to figure out what the environment is. Even if you have your own system, you could download autoconf and steal the tricks they are using.
|
Post #73,691
1/9/03 1:34:45 PM
|
Autoconf does so at runtime.
ie. through uname, etc.
Which isn't particularly useful during compile time. :-)
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,712
1/9/03 3:42:14 PM
|
Are we talking about "configure" script?
As used by scores of Open Source apps? It works _before_ compile time.
--
We have only 2 things to worry about: That things will never get back to normal, and that they already have.
|
Post #73,714
1/9/03 3:46:40 PM
|
You misunderstand me.
The techniques that configure/autoconf use are runtime techniques, and hence useless to my goal of doing the configuration at compile time. :-) Basically, I ended up using stuff like: \n#if defined(MSC_VER)\n// windows stuff\n#elif defined(linux) || defined(__linux__)\n// linux stuff\n#elif defined(sun) || defined(__sun__)\n// solaris stuff\n#else\n#error Unknown or unsupported OS\n#endif\n
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,717
1/9/03 4:04:20 PM
|
One man's compile time...
...is another man's run time. How about having the make file run a configuration procedure that generates a header file with the constants in it. Something with pipes or grep or awk or.... :-)
|
Post #73,724
1/9/03 4:38:25 PM
|
I already do that; I don't want to. :-)
Or at least, something similar. I want the entire detection to happen in the source code, not as the result of something that runs before the compile.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #73,728
1/9/03 4:46:21 PM
|
So what you're really wanting is...
...to know if the compiler itself is autodetecting the environment and whether that detection is available in the conditional compilation?
|
Post #73,735
1/9/03 5:01:51 PM
|
s/wanting/using
Here's what I came up with, which seems to work fine:
[link|http://z.iwethey.org/forums/render/content/show?contentid=73714|http://z.iwethey.org...w?contentid=73714]
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|