From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alex Myczko <tar@debian.org>
Date: Mar, 16 2026 15:33:12 +0000
Subject: [PATCH] <short summary of the patch>

TODO: Put a short summary on the line above and replace this paragraph
with a longer explanation of this change. Complete the meta-information
with other relevant fields (see below for details). To make it easier, the
information below has been extracted from the changelog. Adjust it or drop
it.

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-<Vendor>: <vendor-bugtracker-url>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>

--- openseachest-26.03.0+ds.orig/meson.build
+++ openseachest-26.03.0+ds/meson.build
@@ -473,19 +473,55 @@ if get_option('json_outputformat')
     opensea_jsonformat = subproject('opensea-jsonformat',
         default_options: jsonformat_options
     )
-    opensea_jsonformat_dep = opensea_jsonformat.get_variable('opensea_jsonformat_dep')
 
-    jsonc = subproject(
-        'json-c',
-        default_options: [
-            'default_library=static',
-            'build_apps=false',
-            'disable_extra_libs=true',
-            'disable_json_pointer=false',
-            'disable_json_patch=false',
-        ],
-    )
-    jsonc_dep = jsonc.get_variable('jsonc_dep')
+    # Determine whether to use system json-c or subproject
+    use_system_json = get_option('use_system_json')
+    
+    if use_system_json
+        message('use_system_json=true: Attempting to detect system json-c library')
+        
+        # Step 1: Try pkg-config
+        jsonc_dep = dependency('json-c', required: false)
+        if jsonc_dep.found()
+            message('Found system json-c via pkg-config')
+        else
+            # Step 2: Try find_library + has_header
+            message('pkg-config not available, trying find_library')
+            jsonc_lib = c.find_library('json-c', required: false)
+            has_json_headers = c.has_header('json-c/json_object.h', required: false)
+            
+            if jsonc_lib.found() and has_json_headers
+                message('Found system json-c library and headers')
+                jsonc_dep = declare_dependency(
+                    dependencies: jsonc_lib,
+                    compile_args: ['-I/usr/include/json-c', '-I/usr/local/include/json-c']
+                )
+            else
+                message('System json-c not fully available, falling back to subproject')
+                jsonc_dep = disabler()
+            endif
+        endif
+    else
+        message('use_system_json=false: Using bundled json-c subproject')
+        jsonc_dep = disabler()
+    endif
+    
+    # Step 3: If system json-c not found/used, build from subproject
+    if not jsonc_dep.found()
+        message('Building json-c from subproject')
+        jsonc = subproject(
+            'json-c',
+            default_options: [
+                'default_library=static',
+                'build_apps=false',
+                'disable_extra_libs=true',
+                'disable_json_pointer=false',
+                'disable_json_patch=false',
+            ],
+        )
+        jsonc_dep = jsonc.get_variable('jsonc_dep')
+    endif
+    opensea_jsonformat_dep = opensea_jsonformat.get_variable('opensea_jsonformat_dep')
 endif
 
 incdir = include_directories('include')
