From: Jason Ish Date: Thu, 11 Feb 2021 22:07:30 +0000 (-0600) Subject: lib: build shared library on Linux X-Git-Tag: suricata-7.0.0-beta1~1801 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e227d97e5edd846d0ed794e6d68373ab9def4d0b;p=thirdparty%2Fsuricata.git lib: build shared library on Linux 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. --- diff --git a/configure.ac b/configure.ac index 64f94251d2..4662fc64e3 100644 --- a/configure.ac +++ b/configure.ac @@ -299,7 +299,10 @@ 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) diff --git a/src/Makefile.am b/src/Makefile.am index 8620840548..27577ec1c7 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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)