automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ifdef ... endif issue


From: Stefano Lattarini
Subject: Re: ifdef ... endif issue
Date: Fri, 19 Aug 2011 11:04:45 +0200
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

On Thursday 18 August 2011, Daniel Neuberger wrote:
> On 08/18/11 13:24, Stefano Lattarini wrote:
> > Do you have a link to that thread, by chance?  I think I can point out
> > other workarounds, but before doing so I want to be sure they are
> > appropriate to the issue under discussions.
> 
> Sure, it's 
> http://thread.gmane.org/gmane.comp.sysutils.automake.general/8584/focus=8586.
> 
> Also, I should note that using the method I described (which I saw used 
> in another thread about an unrelated issue), doesn't cause portability 
> problems by itself that I'm aware of.  It just opens up the door for 
> portability issues since the file won't be processed by automake.
> 
> Thanks.
> 
> - Daniel
> 

Thanks for the link.  Quoting from the original message:
 
> Hi,
> I wanted to use this code in one of my Makefiles:
>
> ifdef WIN32_EXTRA_LDFLAGS
> WIN32_EXTRA_LDFLAGS += -export-symbols $(srcdir)/entities.def
> endif
>
The problem here is that the original poster was mixing Automake and GNU
make constructs in an unsupported way.  If the value of WIN32_EXTRA_LDFLAGS
is completely determined at configure time, he could have used an automake
conditional instead, e.g., inserted this in configure.ac:

 AM_CONDITIONAL([NEEDS_WIN32_LDFLAGS], [..check if we are on win32..])

and then used something like this in Makefile.am:

 if NEEDS_WIN32_LDFLAGS
 AM_LDFLAGS += -export-symbols $(srcdir)/entities.def
 endif

On the other hand, if the OP was OK with assuming the use of GNU make on
the final user's part, and wanted to keep the tweaking of AM_LDFLAGS
overridable at make time, he could have gone for something like this:

 AM_LDFLAGS = ... $(maybe_win32_ldflags)
 ifdef USE_WIN32_LDFLAGS
 maybe_win32_ldflags = -export-symbols $(srcdir)/entities.def
 endif

... Only that the above will confuse automake in thinking that there is
a badly specified automake conditional:

 Makefile.am:...: endif without if

So a further workaround is required to please automake; the simplest one
that comes to mind is adding this to configure.ac:

  AC_SUBST([protect], [""])

and the editing Makefile.am to read like:

 AM_LDFLAGS = ... $(maybe_win32_ldflags)
 @address@hidden USE_WIN32_LDFLAGS
 @address@hidden = -export-symbols $(srcdir)/entities.def
 @address@hidden

BUT this doesn't work either!  That's because automake reorders the input
so that variable definitions appear early in the generated Makefile, and
yes, it is smart enough to look beyond leading @substitutions@; this it
will effectively make the `maybe_win32_ldflags' definition unconditional
in our case :-(

So we need a further level of indirection, either using Daniel's idea of
an inclusion with the help of AC_SUBST:

 $ cat win32flags.mk 
 maybe_win32_ldflags = -export-symbols $(srcdir)/entities.def
 $ cat Makefile.am
 ...
 @address@hidden USE_WIN32_LDFLAGS
 @address@hidden $(srcdir)/win32flags.mk
 @address@hidden
 ...

or adding another hacky AC_SUBST:

 $ cat configure.ac
 ...
 AC_SUBST([protect], [""])
 AC_SUBST([equal], ["="])
 ...
 $ cat Makefile.am
 ...
 AM_LDFLAGS = ... $(maybe_win32_ldflags)
 @address@hidden USE_WIN32_LDFLAGS
 @address@hidden @equal@ -export-symbols $(srcdir)/entities.def
 @address@hidden

Either way, yikes!  But it works.

Regards,
  Stefano




reply via email to

[Prev in Thread] Current Thread [Next in Thread]