Phobos posix.mak -> D file using reggae: round 2

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 19 13:43:11 PDT 2016


Am Tue, 19 Apr 2016 17:02:43 +0000
schrieb Atila Neves <atila.neves at gmail.com>:

> > DC_FLAGS=-O5  (flags for that compiler)
> > LDFLAGS=-L=-O1  (flags for the linker)
> > PREFIX=/usr  (installation prefix)  
> 
> These I need to add. Well, if there's enough of a use-case anyway.

It's just normal on Gentoo, to be able to set all the compiler
and linker flags and have atypical configurations for their
software. One guy with a security enhanced Linux and GCC
installation required -fPIC to be passed. This is easy when
the build system provides a facility for it as otherwise I
need to maintain patches.

> > Dlang projects already have some make files that handle linker
> > flag prefixes while others will pass them verbatim to gcc and
> > some make files accept a DMD (ldmd2, gdmd, dmd) and others a
> > DC (ldc2, gdc, dmd). The more things we can override, the
> > better.  
> 
> The phobos makefile only has DMD.

Well, it has the compiler that ships with the sources anyways.
Point taken.

> > As a practical example, on Gentoo, the package management sets
> > all kinds of environment variables, most importantly PREFIX,
> > LDFLAGS, CFLAGS and CXXFLAGS. It would be great if any
> > replacement system would also honor those (translated to D).  
> 
> I didn't even know CFLAGS was a default!

It is for makefiles. These conventions that grew over time
make them convenient to the expert. But they are hardly
visible so easily missed when seeking to replace make files.
https://en.wikipedia.org/wiki/CFLAGS
On a typical Gentoo "ricer" system they'd include e.g.
  -O3 -flto -march=native

> > Even better if it could handle GDC and LDC2 directly (since
> > gdmd and ldmd2 don't do all the way).  
> 
> Here it'd be better to improve gdmd and ldmd2, I think. In any 
> case it's a leaky abstraction. I've never seen a CMake build that 
> doesn't have ifs for what compiler is being used in order to 
> choose the appropriate flags.

Maybe you are right. I hope passing "native" arguments to gdc
and ldc2 through their wrappers works reliably and gdmd stops
reading dmd.conf.

> > LDFLAGS need translation from the default (GCC) syntax to DMD
> > and LDC2. I currently do this in a helper script and would not
> > depend on the build script doing that.  
> 
> Why does it need translating? If you use the system linker 
> directly, use LDFLAGS as is. If not, use whatever linker flags 
> are appropriate for the compiler being used (-L-l... for 
> instance).

I can only speak for Gentoo, where this env. variable is
assumed to be passed as flags to GCC in the linking step, so
the options are already prefixed with "-Wl,". For passing them
to the linker the prefixes needs to be stripped and for passing
them to ldc2 they need to be replaced by -L=. I have code in
place in the compiler selection logic for Dlang packages that
performs this translation. I don't know how exactly you plan
to handle this in your script. E.g. translate LDFLAGS form GCC
to DMD style, expect the user to set them in DMD style or
handle all three compilers by translating to each of them.

-- 
Marco



More information about the Digitalmars-d mailing list