From 755acfaa09e08a355b29081b75f9d547d264ce53 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 29 Dec 2022 13:28:42 +0100
Subject: Refactor Makefiles to exclude cURL on demand.

---
 configure.ac           | 25 ++++++++++++++++++++++---
 src/Makefile.am        |  8 +++++++-
 src/common/Makefile.am | 16 ++++++++++++++--
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 62ccef5..492634b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -218,6 +218,10 @@ AC_ARG_ENABLE([gtk-support],
               AS_HELP_STRING([--disable-gtk-support], [disable GTK support [default=no]]),
               [], [enable_gtk_support=yes])
 
+AC_ARG_ENABLE([curl-support],
+              AS_HELP_STRING([--disable-curl-support], [disable cURL support [default=no]]),
+              [], [enable_curl_support=yes])
+
 AC_ARG_ENABLE([python-bindings],
               AS_HELP_STRING([--disable-python-bindings], [disable Python bindings [default=no]]),
               [], [enable_python_bindings=yes])
@@ -328,7 +332,7 @@ AC_SUBST(DESKTOP_DATADIR)
 
 
 #--- Checks for GTK 3.0 / GObject 2.0
-
+R
 AM_CONDITIONAL([BUILD_GTK_SUPPORT], [test "x$enable_gtk_support" = "xyes"])
 
 if test "x$BUILD_GTK_SUPPORT_TRUE" = "x"; then
@@ -448,6 +452,14 @@ AC_SUBST(LIBSSL_LIBS)
 
 #--- Checks for libcurl
 
+AM_CONDITIONAL([BUILD_CURL_SUPPORT], [test "x$enable_curl_support" = "xyes"])
+
+if test "x$BUILD_CURL_SUPPORT_TRUE" = "x"; then
+   AC_DEFINE(HAVE_CURL_SUPPORT, 1,
+             [Define to 1 if the cURL support is available and enabled.])
+fi
+
+
 PKG_CHECK_MODULES(LIBCURL,libcurl >= 7.64,[libcurl_found=yes],[libcurl_found=no])
 
 if test "$libcurl_found" = "yes"; then
@@ -456,8 +468,14 @@ else
    libcurl_version='-'
 fi
 
-AC_SUBST(LIBCURL_CFLAGS)
-AC_SUBST(LIBCURL_LIBS)
+if test "x$enable_curl_support" = "xyes"; then
+
+   AC_SUBST(LIBCURL_CFLAGS)
+   AC_SUBST(LIBCURL_LIBS)
+
+   true # empty if/then body not allowed
+
+fi
 
 
 #--- Checks for Python
@@ -725,6 +743,7 @@ echo
 echo Print debugging messages..................... : $enable_debug
 echo Consider local resources..................... : $with_local_resources
 echo Disable GTK support.......................... : $disable_gtk_support
+echo Disable cURL support......................... : $disable_curl_support
 echo Disable Python bindings...................... : $disable_python_bindings
 echo Build a Python binary distribution........... : $build_python_package
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 55a8f05..8f746d6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,7 +46,13 @@ libchrysacore_la_LDFLAGS =					\
 	-avoid-version -ldl						\
 	$(TOOLKIT_LIBS) $(LIBXML_LIBS)			\
 	$(LIBSQLITE_LIBS) $(LIBARCHIVE_LIBS)	\
-	$(LIBCURL_LIBS)
+	$(LIBSSL_LIBS)
+
+if BUILD_CURL_SUPPORT
+
+libchrysacore_la_LDFLAGS += $(LIBCURL_LIBS)
+
+endif
 
 libchrysacore_la_LIBADD =					\
 	analysis/libanalysis.la					\
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 9a8fdf2..638eee0 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -9,7 +9,6 @@ libcommon_la_SOURCES =					\
 	bits.h bits.c						\
 	compression.h compression.c			\
 	cpp.h								\
-	curl.h curl.c						\
 	dllist.h dllist.c					\
 	endianness.h endianness.c			\
 	environment.h environment.c			\
@@ -31,7 +30,20 @@ libcommon_la_SOURCES =					\
 	xdg.h xdg.c							\
 	xml.h xml.c
 
-libcommon_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBCURL_CFLAGS)
+if BUILD_CURL_SUPPORT
+
+libcommon_la_SOURCES +=					\
+	curl.h curl.c
+
+endif
+
+libcommon_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS)
+
+if BUILD_CURL_SUPPORT
+
+libcommon_la_CFLAGS += $(LIBCURL_CFLAGS)
+
+endif
 
 
 devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
-- 
cgit v0.11.2-87-g4458