summary refs log tree commit diff
path: root/pkgs/os-specific/linux/qemu-kvm/fix-librt-check.patch
blob: 57de288723e82460624a70b62d772d076d8ead84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
commit 8bacde8d86a09699207d85d4bab06162aed18dc4
Author: Natanael Copa <natanael.copa@gmail.com>
Date:   Wed Sep 12 09:06:51 2012 +0000

    configure: properly check if -lrt and -lm is needed
    
    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>
    Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

diff --git a/configure b/configure
index 7656c32..9ab13db 100755
--- a/configure
+++ b/configure
@@ -2671,17 +2671,44 @@ 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"
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \