]> err.no Git - yubikey-personalization/commitdiff
Build with both new and old libjson.
authorSimon Josefsson <simon@josefsson.org>
Fri, 19 Apr 2013 10:02:50 +0000 (12:02 +0200)
committerSimon Josefsson <simon@josefsson.org>
Fri, 19 Apr 2013 10:02:50 +0000 (12:02 +0200)
configure.ac
ykpers-json.c

index 49d5a828f626824266197e7832bd08db1085582b..093f4b0fb501173c9ddeda780efbc0ce8cb45919 100644 (file)
@@ -1,5 +1,5 @@
 # Written by Richard Levitte <richard@levitte.org>.
-# Copyright (c) 2008-2012 Yubico AB
+# Copyright (c) 2008-2013 Yubico AB
 # All rights reserved.
 # 
 # Redistribution and use in source and binary forms, with or without
@@ -125,7 +125,17 @@ AM_CONDITIONAL([BACKEND_LIBUSB_1_0], test x$with_backend = xlibusb-1.0)
 AM_CONDITIONAL([BACKEND_OSX], test x$with_backend = xosx)
 AM_CONDITIONAL([BACKEND_WINDOWS], test x$with_backend = xwindows)
 
-PKG_CHECK_MODULES([libjson], [json-c], [], [PKG_CHECK_MODULES([libjson], [json])])
+PKG_CHECK_MODULES([libjson], [json-c], [], [
+  PKG_CHECK_MODULES([libjson], [json])])
+
+# Check for json_object_to_json_string_ext, needed for pretty printing.
+am_save_CFLAGS="$CFLAGS"
+am_save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $libjson_CFLAGS"
+LIBS="$LIBS $libjson_LIBS"
+AC_CHECK_FUNCS([json_object_to_json_string_ext])
+CFLAGS=$am_save_CFLAGS
+LIBS=$am_save_LIBS
 
 AC_ARG_WITH([udevrulesdir],
   AS_HELP_STRING([--with-udevrulesdir=DIR], [Install udev rules into this directory]),
@@ -199,6 +209,8 @@ AC_MSG_NOTICE([summary of build options:
   Compiler:         ${CC}
   Library types:    Shared=${enable_shared}, Static=${enable_static}
   USB backend:      ${with_backend}
+  JSON library:     CFLAGS: $libjson_CFLAGS LIBS: $libjson_LIBS
+   pretty printing: $ac_cv_func_json_object_to_json_string_ext
   udev rules dir:   ${with_udevrulesdir:-N/A}
   udev rules file:  ${udevrulesfile:-N/A}
 ])
index 2a3790dd8fcfa79b806ff61f47d6d2b4dcdab6af..06965f1d8793630ce16212b0b4b6ad0075c3f618 100644 (file)
@@ -158,7 +158,11 @@ int _ykp_json_export_cfg(const YKP_CONFIG *cfg, char *json, size_t len) {
                }
        }
 
+#ifdef HAVE_JSON_OBJECT_TO_JSON_STRING_EXT
        strncpy(json, json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PRETTY), len);
+#else
+       strncpy(json, json_object_to_json_string(jobj), len);
+#endif
 
        /* free the root object, will free all children */
        json_object_put(jobj);