]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lib: build shared library on Linux
authorJason Ish <jason.ish@oisf.net>
Thu, 11 Feb 2021 22:07:30 +0000 (16:07 -0600)
committerJason Ish <jason.ish@oisf.net>
Tue, 16 Feb 2021 17:43:26 +0000 (11:43 -0600)
Building the shared library on Linux is not something by default.
Instead a user must opt-in to building by running the
"make libsuricata.so" target in the src/ directory.

Currently shared library support is only available on Linux. More
OSs will be supported as we can test them.

configure.ac
src/Makefile.am

index 64f94251d241f4b1c8b65358b34f456bacbb8891..4662fc64e32777696e239610ba487f610102095c 100644 (file)
             LDFLAGS="${LDFLAGS} -L/opt/local/lib"
             ;;
         *-*-linux*)
+            # Always compile with -fPIC on Linux for shared library support.
+            CFLAGS="${CFLAGS} -fPIC"
             RUST_LDADD="-ldl -lrt -lm"
+            can_build_shared_library="yes"
             ;;
         *-*-mingw32*|*-*-msys)
             CFLAGS="${CFLAGS} -DOS_WIN32"
@@ -2678,6 +2681,8 @@ AC_SUBST(PACKAGE_VERSION)
 AC_SUBST(RUST_FEATURES)
 AC_SUBST(RUST_SURICATA_LIBDIR)
 
+AM_CONDITIONAL([BUILD_SHARED_LIBRARY], [test "x$enable_shared" = "xyes"] && [test "x$can_build_shared_library" = "xyes"])
+
 AC_CONFIG_FILES(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config)
 AC_CONFIG_FILES(qa/Makefile qa/coccinelle/Makefile)
 AC_CONFIG_FILES(rules/Makefile doc/Makefile doc/userguide/Makefile doc/devguide/Makefile)
index 8620840548b3f3bed8a9803905272b6516ac99d2..27577ec1c739b274d33f4943393228744010f86c 100755 (executable)
@@ -595,6 +595,19 @@ suricata_LDFLAGS = $(all_libraries) ${SECLDFLAGS}
 suricata_LDADD = libsuricata_c.a $(HTP_LDADD) $(RUST_LDADD)
 suricata_DEPENDENCIES = libsuricata_c.a
 
+if BUILD_SHARED_LIBRARY
+libsuricata.so.$(VERSION): libsuricata_c.a
+       $(CC) -shared -o $@ -Wl,-soname,$@ -Wl,--whole-archive \
+               libsuricata_c.a \
+               $(RUST_SURICATA_LIB) \
+               -Wl,--no-whole-archive
+libsuricata.so: libsuricata.so.$(VERSION)
+else
+libsuricata.so:
+       @echo "shared library support not enabled"
+       @exit 1
+endif
+
 if BUILD_FUZZTARGETS
 
 LDFLAGS_FUZZ = $(all_libraries) $(SECLDFLAGS)