Makefile tweak for -lm?

Mike Frysinger vapier at gentoo.org
Fri Dec 2 16:28:29 UTC 2005


On Fri, Dec 02, 2005 at 10:15:31AM -0600, Rob Landley wrote:
> On Friday 02 December 2005 07:01, Mike Frysinger wrote:
> > On Thu, Dec 01, 2005 at 03:32:13PM -0600, Rob Landley wrote:
> > > I came up with the following makefile patch via cut and paste.  Would
> > > someone who knows makefiles tell me what I _should_ have done?
> >
> > this should work:
> > needlibm-y :=
> > needlibm-$(CONFIG_FEATURE_SORT_BIG) := -lm
> > LIBRARIES += $(needlibm-y)
> 
> Okay...
> 
> (Much blinking and scratching of head ensues...)
> 
> Ok, I think I understand what it means, but won't it add -lm more than once if 
> more than one applet needs it?

if you move the first line to the top, duplicate the second line for
every applet, and move the third line to the 'end' (basically after
all of the previous settings), then no, it wont add -lm more than once

the $(CONFIG_...) will expand to either 'y' or 'n', so:
needlibm-y :=
...
needlibm-$(CONFIG_FEATURE_SORT_BIG) := -lm
needlibm-$(CONFIG_APPLET_FOO) := -lm
needlibm-$(CONFIG_APPLET_BAR) := -lm
...
LIBRARIES += $(needlibm-y)

if the .config contains:
CONFIG_FEATURE_SORT_BIG=y
CONFIG_APPLET_FOO=y
CONFIG_APPLET_BAR=n

the make foo is expanded to:
needlibm-y :=
...
needlibm-y := -lm
needlibm-y := -lm
needlibm-n := -lm
...
LIBRARIES += $(needlibm-y)
and since the := only ever sets, not increments, it isnt an issue ...

if the .config contains:
CONFIG_FEATURE_SORT_BIG=n
CONFIG_APPLET_FOO=n
CONFIG_APPLET_BAR=n

the make foo is expanded to:
needlibm-y :=
...
needlibm-n := -lm
needlibm-n := -lm
needlibm-n := -lm
...
LIBRARIES += $(needlibm-y)
and since we never set needlibm-y again, LIBRARIES will not contain -lm
-mike



More information about the busybox mailing list