[GD-General] Minor rant - cross-platform configuration
Brought to you by:
vexxed72
From: brian h. <bri...@py...> - 2002-11-06 09:15:09
|
In the process of working on some of our internal source that I will eventually be open sourcing, I needed to come up with a "config.h" that handles per-platform dependencies. Looking at the plethora of open source libraries I use -- zlib, libpng, ijg, Lua, SDL, etc. -- I was appalled at the amount of repeated work done for the most basic task: configuring your build environment and targets. This is something that should have been mostly figured out years ago, and yet everyone rolls their own. Every project has a header file that basically is chock full of this kind of loveliness: #if defined _WIN32 || defined __WIN32__ #if defined __BORLANDC__ || defined _MSC_VER #if EXPORTING_DLL #define PUBLIC_API __declspec(dllexport) #elif IMPORTING_DLL #define PUBLIC_API __declspec(dllimport) #endif #endif #endif #ifndef PUBLIC_API #define PUBLIC_API #endif . . . PUBLIC_API void MyLib_SomeFunction( void ); And then we have similar drills for type sizes, compile time assertions, operating system, compiler, CPU, endianess, you name it. Configuring 64-bit types; calling conventions; etc. It's not rocket science. It's just tedious crap that everyone has to write from scratch and learn the hard way. Simple things aren't so simple -- "How do I know if I'm compiling for MacOS?" or "What kind of endianess is this architecture?" For example, if "__sun" is defined, you cannot assume Solaris nor can you assume Sparc. You have to look at the __sparc/sparc and __SVR4 constants, because you may be on Solaris/x86 or SunOS for Sparc or even 68K/x86. A lot of people assume that __MWERKS__ means "MacOS", but that's not true either. There's no universal constant for MacOS X, so you have to looked __APPLE__ and __APPLE_CC__ or something else if __MWERKS__ is defined. If __mips is defined, it may mean many different things, but a lot of people will assume immediately "Irix" and "big endian". Can't do that. Borland defines __WIN32__, but not _WIN32. MSVC is the opposite. God knows what's going on with Watcom these days, but sadly enough, people still use it. And don't get me started on MingW and Cygwin. Bah. It's depressing. Anyway, I'm writing a single generic header file that's going to be used by all of our ANSI C libraries, and I'll open source that hopefully to help others avoid the frustration as well. Current working name is "gosh.h" for Generic Open Source Header. I'm trying very hard to make it "plug and play" -- simply including it will automagically setup everything, so you don't have to deal with a bunch of -DMAGIC_CONSTANT=x or "./configure" and what not. Adjunct to this rant -- so far I've only found one site (off sourceforge) that even tries to catalog all the various compiler definitions for different operating systems, compilers, and architectures. -Hook |