0002-Link-against-libm-when-needed.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From ccb15ee3d7e8c925cb3af9ea805feea2863c4f81 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Fri, 1 May 2015 12:52:18 +0200
  4. Subject: [PATCH] Link against libm when needed
  5. In certain C libraries (e.g uClibc), isnan() and related functions are
  6. implemented in libm, so json-c needs to link against it. This commit
  7. therefore adds an AC_TRY_LINK() test to check whether a program
  8. calling isnan() can be properly linked with no special flags. If not,
  9. we assume linking against libm is needed.
  10. The json-c.pc.in file is also adjusted so that in the case of static
  11. linking against json-c, -lm is also used.
  12. Submitted upstream: https://github.com/json-c/json-c/pull/182
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  14. ---
  15. configure.ac | 4 ++++
  16. json-c.pc.in | 3 ++-
  17. 2 files changed, 6 insertions(+), 1 deletion(-)
  18. diff --git a/configure.ac b/configure.ac
  19. index 99660a4..2a14ccf 100644
  20. --- a/configure.ac
  21. +++ b/configure.ac
  22. @@ -50,6 +50,10 @@ AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
  23. AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
  24. AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])
  25. +if test "$ac_cv_have_decl_isnan" = "yes" ; then
  26. + AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"])
  27. +fi
  28. +
  29. #check if .section.gnu.warning accepts long strings (for __warn_references)
  30. AC_LANG_PUSH([C])
  31. diff --git a/json-c.pc.in b/json-c.pc.in
  32. index 037739d..05bfbc8 100644
  33. --- a/json-c.pc.in
  34. +++ b/json-c.pc.in
  35. @@ -6,6 +6,7 @@ includedir=@includedir@
  36. Name: json-c
  37. Description: JSON implementation in C
  38. Version: @VERSION@
  39. -Requires:
  40. +Requires:
  41. +Libs.private: @LIBS@
  42. Libs: -L${libdir} -ljson-c
  43. Cflags: -I${includedir}/json-c
  44. --
  45. 2.1.0