diff mbox

[OpenWrt-Devel,1/2] fix building with json-c.0.12

Message ID 1424965962-16298-2-git-send-email-william.holland@codethink.co.uk
State Superseded
Headers show

Commit Message

William Holland Feb. 26, 2015, 3:52 p.m. UTC
---
 CMakeLists.txt     |    7 +++++++
 plug/hotplug.c     |    6 +++++-
 service/validate.c |    6 +++++-
 3 files changed, 17 insertions(+), 2 deletions(-)

Comments

Yousong Zhou Feb. 27, 2015, 11:01 a.m. UTC | #1
On 26 February 2015 at 23:52, William Holland
<william.holland@codethink.co.uk> wrote:
> ---
>  CMakeLists.txt     |    7 +++++++
>  plug/hotplug.c     |    6 +++++-
>  service/validate.c |    6 +++++-
>  3 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 5414677..058d774 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -14,6 +14,13 @@ SET(SOURCES procd.c signal.c watchdog.c state.c      inittab.c rcS.c ubus.c system.c
>         service/service.c service/instance.c service/validate.c service/trigger.c service/watch.c
>         plug/coldplug.c plug/hotplug.c utils/utils.c)
>
> +INCLUDE(FindPkgConfig)
> +PKG_CHECK_MODULES(JSONC json-c)
> +IF(JSONC_FOUND)
> +  ADD_DEFINITIONS(-DJSONC)
> +  INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
> +ENDIF()
> +
>  find_library(json NAMES json-c json)
>  SET(LIBS ubox ubus ${json} blobmsg_json json_script)
>

The above only detects the cinclude path for json-c and is not version specific.

> diff --git a/plug/hotplug.c b/plug/hotplug.c
> index 061833a..3bf6253 100644
> --- a/plug/hotplug.c
> +++ b/plug/hotplug.c
> @@ -22,7 +22,11 @@
>  #include <libubox/blobmsg_json.h>
>  #include <libubox/json_script.h>
>  #include <libubox/uloop.h>
> -#include <json/json.h>
> +#ifdef JSONC
> +       #include <json.h>
> +#else
> +       #include <json/json.h>
> +#endif
>

Original code compiles in OpenWrt because exact copy of json-c header
files are copied to usr/include/json/ in addition to
usr/include/json-c/.  I suggest we drop this JSONC convention in
procd, libubox, etc.  and stick to pkg-config and "#include <json.h>".

Regards

               yousong


>  #include <fcntl.h>
>  #include <unistd.h>
> diff --git a/service/validate.c b/service/validate.c
> index a33a48e..0e45493 100644
> --- a/service/validate.c
> +++ b/service/validate.c
> @@ -13,7 +13,11 @@
>
>  #include <libubox/blobmsg_json.h>
>  #include <libubox/avl-cmp.h>
> -#include <json/json.h>
> +#ifdef JSONC
> +       #include <json.h>
> +#else
> +       #include <json/json.h>
> +#endif
>
>  #include "../procd.h"
>
> --
> 1.7.10.4
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Karl Palsson Feb. 27, 2015, 2:20 p.m. UTC | #2
Yousong Zhou <yszhou4tech@gmail.com> wrote:
> >
> 
> The above only detects the cinclude path for json-c and is not version
> specific.

json-c is the name going forward, and has been the name for two releases
of the library already.

> 
> > diff --git a/plug/hotplug.c b/plug/hotplug.c
> > index 061833a..3bf6253 100644
> > --- a/plug/hotplug.c
> > +++ b/plug/hotplug.c
> > @@ -22,7 +22,11 @@
> >  #include <libubox/blobmsg_json.h>
> >  #include <libubox/json_script.h>
> >  #include <libubox/uloop.h>
> > -#include <json/json.h>
> > +#ifdef JSONC
> > +       #include <json.h>
> > +#else
> > +       #include <json/json.h>
> > +#endif
> >
> 
> Original code compiles in OpenWrt because exact copy of json-c header
> files are copied to usr/include/json/ in addition to
> usr/include/json-c/.  I suggest we drop this JSONC convention in
> procd, libubox, etc.  and stick to pkg-config and "#include <json.h>".
> 

Don't do that, <json.h> is the legacy installation path.  procd is new,
and uses new json-c library, just always use the new path.  Don't patch
to allow procd to keep using a style of include that hasn't been current
or standard for as long as procd has existed.

#include <json-c/json.h>

is the way it should be used.

Sincerely,
Karl Palsson
diff mbox

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5414677..058d774 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,13 @@  SET(SOURCES procd.c signal.c watchdog.c state.c	inittab.c rcS.c	ubus.c system.c
 	service/service.c service/instance.c service/validate.c service/trigger.c service/watch.c
 	plug/coldplug.c plug/hotplug.c utils/utils.c)
 
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(JSONC json-c)
+IF(JSONC_FOUND)
+  ADD_DEFINITIONS(-DJSONC)
+  INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
+ENDIF()
+
 find_library(json NAMES json-c json)
 SET(LIBS ubox ubus ${json} blobmsg_json json_script)
 
diff --git a/plug/hotplug.c b/plug/hotplug.c
index 061833a..3bf6253 100644
--- a/plug/hotplug.c
+++ b/plug/hotplug.c
@@ -22,7 +22,11 @@ 
 #include <libubox/blobmsg_json.h>
 #include <libubox/json_script.h>
 #include <libubox/uloop.h>
-#include <json/json.h>
+#ifdef JSONC
+	#include <json.h>
+#else
+	#include <json/json.h>
+#endif
 
 #include <fcntl.h>
 #include <unistd.h>
diff --git a/service/validate.c b/service/validate.c
index a33a48e..0e45493 100644
--- a/service/validate.c
+++ b/service/validate.c
@@ -13,7 +13,11 @@ 
 
 #include <libubox/blobmsg_json.h>
 #include <libubox/avl-cmp.h>
-#include <json/json.h>
+#ifdef JSONC
+	#include <json.h>
+#else
+	#include <json/json.h>
+#endif
 
 #include "../procd.h"