On 8/31/07, ed <[EMAIL PROTECTED]> wrote: > A small project that I've been working on was buildable for > linux/openbsd through a Makefile. The Makefile would build with one of > two .c files. This worked fine as the same function names were used in > both files. > > Now I'm wanting to add optional mysql/postgres/sqllite etc to the > project but I don't know how I can specify these as optionals, for > example, the libraries may not exist to link to. Is there a way to set > a define value in the Makefile that can be passed to the compiler? > > Ideally in the code, I would have something like: > > #ifdef DATABASE > call_database_routeine(); > #enfif > > .. at bit of a loss here!
Well, gcc uses the -D option for setting pre-processor values... If you are doing stuff on Linux or one of the BSD flavors, I recommend look into something that does dynamic configuration management that can do building and linking based on the specs of your system. 1) The most common option used is the GNU Autotools... you build a metascript that specifies required libraries, build environment, etc, and this generates a 'configure' script that you (or other users compiling your software) can run that builds your makefile. This is the familiar 'configure && make && make install' command for building software. Your system may already have this stuff installed. If you use an IDE like Anjuta on Linux, it uses the autotools stuff underneath. 2) Another option that is getting popular is scons -- it's a similar kind of thing but is based entirely on Python. You create a Python script that defines required libraries, customized build algorithms, etc. I like this one because it's much easier to use than the autotools stuff (which can be pretty daunting for a newbie not familiar with Unix shell scripting); plus you get the benefit of using a programming language that can be debugged and doesn't generate a lot of hidden scripts and config files. http://www.scons.org/ 3) And then there is CMake, is which is a cross-compiler build environment that can be used on many different systems. It is similar to the autotools but much easier to use and, being cross-platform, can be used to target many different compiler environments. http://www.cmake.org/HTML/Index.html Since your project is small, I'd go with SCons, it's the easiest to start with. But I have seen some huge projects on Linux build with SCons (like Ardour and Rosegarden, two GUI-based high-end audio applications written in C++). So it's quite powerful. -- Brett ------------------------------------------------------------ "In the rhythm of music a secret is hidden; If I were to divulge it, it would overturn the world." -- Jelaleddin Rumi
