Patchwork [v4] configure: properly check if -lrt and -lm is needed

login
register
mail settings
Submitter Natanael Copa
Date Aug. 22, 2012, 11:23 a.m.
Message ID <1345634595-9960-1-git-send-email-ncopa@alpinelinux.org>
Download mbox | patch
Permalink /patch/179301/
State New
Headers show

Comments

Natanael Copa - Aug. 22, 2012, 11:23 a.m.
Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
Changes v3->v4:
 - Use $pthread_lib from previous pthread test
   We don't need to add it to $LIBS since it should be there already

 configure | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
Natanael Copa - Aug. 28, 2012, 7:33 a.m.
On Tue, 21 Aug 2012 18:12:05 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:
> 
> Now I get this on mingw32:
> config-host.mak is out-of-date, running configure
> 
> Error: librt check failed

Any news on the v4 patch, which should fix this?

Thanks!
Blue Swirl - Aug. 28, 2012, 5:16 p.m.
On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Tue, 21 Aug 2012 18:12:05 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>>
>> Now I get this on mingw32:
>> config-host.mak is out-of-date, running configure
>>
>> Error: librt check failed
>
> Any news on the v4 patch, which should fix this?

No change:
config-host.mak is out-of-date, running configure

Error: librt check failed

>
> Thanks!
>
Natanael Copa - Aug. 29, 2012, 6:41 a.m.
On Tue, 28 Aug 2012 17:16:18 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:

> On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa
> <ncopa@alpinelinux.org> wrote:
> > On Tue, 21 Aug 2012 18:12:05 +0000
> > Blue Swirl <blauwirbel@gmail.com> wrote:
> >>
> >> Now I get this on mingw32:
> >> config-host.mak is out-of-date, running configure
> >>
> >> Error: librt check failed
> >
> > Any news on the v4 patch, which should fix this?
> 
> No change:
> config-host.mak is out-of-date, running configure
> 
> Error: librt check failed

I have run out of guesses. Could I please have the last lines from your
config.log?

Thanks!

-nc
Blue Swirl - Sept. 1, 2012, 9:13 a.m.
On Wed, Aug 29, 2012 at 6:41 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Tue, 28 Aug 2012 17:16:18 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>
>> On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa
>> <ncopa@alpinelinux.org> wrote:
>> > On Tue, 21 Aug 2012 18:12:05 +0000
>> > Blue Swirl <blauwirbel@gmail.com> wrote:
>> >>
>> >> Now I get this on mingw32:
>> >> config-host.mak is out-of-date, running configure
>> >>
>> >> Error: librt check failed
>> >
>> > Any news on the v4 patch, which should fix this?
>>
>> No change:
>> config-host.mak is out-of-date, running configure
>>
>> Error: librt check failed
>
> I have run out of guesses. Could I please have the last lines from your
> config.log?

i586-mingw32msvc-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1
-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes
-fno-strict-aliasing -fstack-protector-all -Wendif-labels
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration
-Wold-style-definition -Wtype-limits -o
/tmp/qemu-conf-7196-16398-8534.exe /tmp/qemu-conf-21413-16398-5412.c
-m32 -g
/tmp/qemu-conf-21413-16398-5412.c: In function 'main':
/tmp/qemu-conf-21413-16398-5412.c:4: warning: implicit declaration of
function 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: warning: nested extern
declaration of 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: error: 'CLOCK_REALTIME'
undeclared (first use in this function)
/tmp/qemu-conf-21413-16398-5412.c:4: error: (Each undeclared
identifier is reported only once
/tmp/qemu-conf-21413-16398-5412.c:4: error: for each function it appears in.)
/tmp/qemu-conf-21413-16398-5412.c:5: warning: implicit declaration of
function 'clock_gettime'
/tmp/qemu-conf-21413-16398-5412.c:5: warning: nested extern
declaration of 'clock_gettime'
i586-mingw32msvc-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1
-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes
-fno-strict-aliasing -fstack-protector-all -Wendif-labels
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration
-Wold-style-definition -Wtype-limits -o
/tmp/qemu-conf-7196-16398-8534.exe /tmp/qemu-conf-21413-16398-5412.c
-m32 -g -lrt -lpthreadGC2
/tmp/qemu-conf-21413-16398-5412.c: In function 'main':
/tmp/qemu-conf-21413-16398-5412.c:4: warning: implicit declaration of
function 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: warning: nested extern
declaration of 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: error: 'CLOCK_REALTIME'
undeclared (first use in this function)
/tmp/qemu-conf-21413-16398-5412.c:4: error: (Each undeclared
identifier is reported only once
/tmp/qemu-conf-21413-16398-5412.c:4: error: for each function it appears in.)
/tmp/qemu-conf-21413-16398-5412.c:5: warning: implicit declaration of
function 'clock_gettime'
/tmp/qemu-conf-21413-16398-5412.c:5: warning: nested extern
declaration of 'clock_gettime'

>
> Thanks!
>
> -nc

Patch

diff --git a/configure b/configure
index edf9da4..31eee91 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,49 @@  fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
-elif compile_prog "" "-lrt" ; then
+# we need pthread for static linking. use previous pthread test result 
+elif compile_prog "" "-lrt $pthread_lib" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \