Thread overview
Converting #ifdef to version statements.
Jan 18, 2006
Chris Sauls
January 18, 2006
Hi.

I'm porting some headers from C that use #ifdef macros that I'm trying to translate to version statements. The macros are #defined in a "features.h" file witch is included in the others:

//features.h
#define FEATURE_A
#define FEATURE_B
#define FEATURE_C

//header_a.h
#include <features.h>
#ifdef FEATURE_A
...
#endif


//header_b.h
#include <features.h>
#ifdef FEATURE_B
...
#endif
#ifdef FEATURE_C
...
#endif

The direct translation using "version = FEATURE_A" doesn't work. I remember Walter saying some time ago that version definitions like this only affected modules imported by the module that defined them. I understand why, but in this case I would at least be able to do something like:

version (features.FEATURE_A)
{
...
}

So in this case, what should I do? Any one knows a work around this limitation?

Thanks
January 18, 2006
Julio César Carrascal Urquijo wrote:

> So in this case, what should I do? Any one knows a work around this limitation?

Include them in the DFLAGS (i.e. set them in your Makefile)

--anders
January 18, 2006
Isn't there a way to accomplish on source code only? (without modifying the command line).

This is a library and I don't want the users to add a bunch of defines to the command line each time they link to it.


Anders F Björklund wrote:
> Julio César Carrascal Urquijo wrote:
> 
>> So in this case, what should I do? Any one knows a work around this limitation?
> 
> Include them in the DFLAGS (i.e. set them in your Makefile)
> 
> --anders
January 18, 2006
Julio César Carrascal Urquijo wrote:

> Isn't there a way to accomplish on source code only? (without modifying the command line).

I haven't really found any... Walter deliberately wants to keep versions
much simpler than #defines. This also means it doesn't work similarly ?

I'm afraid I've resorted to copy/paste and other such dirty workarounds.
No idea how it would work, if one ever wanted to port e.g. "autoconf" ?

--anders
January 18, 2006
I understand and thanks for your help.



Anders F Björklund wrote:
> Julio César Carrascal Urquijo wrote:
> 
>> Isn't there a way to accomplish on source code only? (without modifying the command line).
> 
> I haven't really found any... Walter deliberately wants to keep versions
> much simpler than #defines. This also means it doesn't work similarly ?
> 
> I'm afraid I've resorted to copy/paste and other such dirty workarounds.
> No idea how it would work, if one ever wanted to port e.g. "autoconf" ?
> 
> --anders
January 18, 2006
Julio César Carrascal Urquijo wrote:
> Isn't there a way to accomplish on source code only? (without modifying the command line).
> 
> This is a library and I don't want the users to add a bunch of defines to the command line each time they link to it.

Might be time to start using the Build utility then.
http://trac.dsource.org/projects/build

########## features.d
# module features;
#
# version (build) pragma(export_version,
#   FEATURE_A ,
#   FEATURE_B ,
#   FEATURE_C
# );

Of course the downside is that, assuming the library is recompiled by users, they will also need to use Build.  Unless Walter randomly decides to make pragma(export_version) a standard D'ism.

-- Chris Sauls
January 18, 2006
Chris Sauls wrote:

> Might be time to start using the Build utility then.
> http://trac.dsource.org/projects/build

Build works rather poorly with GDC unfortunately.
Or at least it does when I try it on the Mac...

--anders