From: Jason Ish Date: Wed, 14 Feb 2024 21:23:44 +0000 (-0600) Subject: examples/plugin: simplify Makefile X-Git-Tag: suricata-8.0.0-beta1~1737 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d792f017b62ca9ec6c260d0fae788a91aebc4e7;p=thirdparty%2Fsuricata.git examples/plugin: simplify Makefile Simplify the Makefile by avoiding automake and providing our own Makefile.in that is suitable for in-tree builds of the plugin and can also serve as an example for standalone plugins. But the bigger benefit of this is to allow building the example plugin even with --disable-shared provided to configure, as this is just a phony limitation imposed by automake/libtool. --- diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index c40a92788b..e91392a8da 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -295,14 +295,24 @@ jobs: working-directory: examples/plugins/c-json-filetype run: make - name: Check C json filetype plugin - run: test -e examples/plugins/c-json-filetype/.libs/json-filetype.so.0.0.0 + run: test -e examples/plugins/c-json-filetype/filetype.so - name: Installing headers and library run: | make install-headers make install-library - - name: Test plugin build with Makefile.example + - name: Cleaning source directory for standalone plugin test. + run: make clean + - name: Test plugin against installed headers working-directory: examples/plugins/c-json-filetype - run: PATH=/usr/local/bin:$PATH make -f Makefile.example + run: | + # First use sed to pretend we are q user following our + # directions for building a standalone plugin. + sed -i 's/^#LIBSURICATA_CONFIG/LIBSURICATA_CONFIG/' Makefile + sed -i 's/^#CPPFLAGS/CPPFLAGS/' Makefile + sed -i 's/^CPPFLAGS.*HAVE_CONFIG_H//' Makefile + + # And build. + PATH=/usr/local/bin:$PATH make almalinux-9-templates: name: AlmaLinux 9 Test Templates diff --git a/Makefile.am b/Makefile.am index b7a221f492..00503e21f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,10 +7,10 @@ EXTRA_DIST = ChangeLog COPYING LICENSE suricata.yaml.in \ $(SURICATA_UPDATE_DIR) \ lua \ acsite.m4 \ - scripts/generate-images.sh + scripts/generate-images.sh \ + examples SUBDIRS = $(HTP_DIR) rust src qa rules doc contrib etc python ebpf \ $(SURICATA_UPDATE_DIR) -DIST_SUBDIRS = examples/plugins/c-json-filetype $(SUBDIRS) CLEANFILES = stamp-h[0-9]* diff --git a/examples/plugins/c-json-filetype/.gitignore b/examples/plugins/c-json-filetype/.gitignore index f5bb3af73f..20be8dc105 100644 --- a/examples/plugins/c-json-filetype/.gitignore +++ b/examples/plugins/c-json-filetype/.gitignore @@ -1,2 +1,3 @@ +!/Makefile.in *.so *.la diff --git a/examples/plugins/c-json-filetype/Makefile.am b/examples/plugins/c-json-filetype/Makefile.am deleted file mode 100644 index d5e912b8a4..0000000000 --- a/examples/plugins/c-json-filetype/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -plugindir = ${libdir}/suricata/plugins - -if BUILD_SHARED_LIBRARY -plugin_LTLIBRARIES = json-filetype.la -json_filetype_la_LDFLAGS = -module -shared -json_filetype_la_SOURCES = filetype.c - -json_filetype_la_CPPFLAGS = -I$(abs_top_srcdir)/rust/gen -I$(abs_top_srcdir)/rust/dist - -else - -all-local: - @echo - @echo "Shared library support must be enabled to build plugins." - @echo - -endif diff --git a/examples/plugins/c-json-filetype/Makefile.example b/examples/plugins/c-json-filetype/Makefile.example deleted file mode 100644 index 6d514aab14..0000000000 --- a/examples/plugins/c-json-filetype/Makefile.example +++ /dev/null @@ -1,18 +0,0 @@ -SRCS := filetype.c - -LIBSURICATA_CONFIG ?= libsuricata-config - -CPPFLAGS += `$(LIBSURICATA_CONFIG) --cflags` -CPPFLAGS += -DSURICATA_PLUGIN -I. -CPPFLAGS += "-D__SCFILENAME__=\"$(*F)\"" - -OBJS := $(SRCS:.c=.o) - -filetype.so: $(OBJS) - $(CC) -fPIC -shared -o $@ $(OBJS) - -%.o: %.c - $(CC) -fPIC $(CPPFLAGS) -c -o $@ $< - -clean: - rm -f *.o *.so *~ diff --git a/examples/plugins/c-json-filetype/Makefile.in b/examples/plugins/c-json-filetype/Makefile.in new file mode 100644 index 0000000000..0d4ec381ee --- /dev/null +++ b/examples/plugins/c-json-filetype/Makefile.in @@ -0,0 +1,32 @@ +# If building a plugin out of the Suricata source tree, you can use +# libsuricata-config --cflags. +#LIBSURICATA_CONFIG ?= libsuricata-config +#CPPFLAGS += `$(LIBSURICATA_CONFIG) --cflags` + +# But as this is an example in the Suricata source tree we'll look for +# includes in the source tree. +CPPFLAGS += -I@top_srcdir@/src -DHAVE_CONFIG_H + +# Currently the Suricata logging system requires this to be even for +# plugins. +CPPFLAGS += "-D__SCFILENAME__=\"$(*F)\"" + +all: Makefile filetype.so + +filetype.so: filetype.c + $(CC) $(CPPFLAGS) -fPIC -shared -o $@ $^ + +clean: + rm -f *.so *.o *.lo + rm -rf .deps + +distclean: clean + rm -f Makefile.am + +# Regenerate Makefile on change of Makefile.in since we're not using +# Makefile.am. +Makefile: Makefile.in + cd @top_builddir@ && ./config.status examples/plugins/c-json-filetype/Makefile + +# Dummy rules to satisfy make dist. +dist distdir: diff --git a/examples/plugins/c-json-filetype/README.md b/examples/plugins/c-json-filetype/README.md index 2f7978977d..fa0ae8adf6 100644 --- a/examples/plugins/c-json-filetype/README.md +++ b/examples/plugins/c-json-filetype/README.md @@ -3,16 +3,14 @@ ## Building If in the Suricata source directory, this plugin can be built by -running `make` and installed with `make install`. - -Note that Suricata must have been built without `--disable-shared`. +running `make`. ## Building Standalone -The file `Makefile.example` is an example of how you might build a -plugin that is distributed separately from the Suricata source code. +This Makefile is not generated by automake so it can serve as an +example for plugins created outside of the Suricata source tree. -It has the following dependencies: +Building a standalone plugin has the following dependencies: - Suricata is installed - The Suricata library is installed: `make install-library` @@ -20,7 +18,7 @@ It has the following dependencies: - The program `libsuricata-config` is in your path (installed with `make install-library`) -The run: `make -f Makefile.example` +Modify the Makefile to use `libsuricata-config`. Before building this plugin you will need to build and install Suricata from the git master branch and install the development tools and headers: