]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
examples/plugin: simplify Makefile
authorJason Ish <jason.ish@oisf.net>
Wed, 14 Feb 2024 21:23:44 +0000 (15:23 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 20 Feb 2024 12:51:25 +0000 (13:51 +0100)
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.

.github/workflows/builds.yml
Makefile.am
examples/plugins/c-json-filetype/.gitignore
examples/plugins/c-json-filetype/Makefile.am [deleted file]
examples/plugins/c-json-filetype/Makefile.example [deleted file]
examples/plugins/c-json-filetype/Makefile.in [new file with mode: 0644]
examples/plugins/c-json-filetype/README.md

index c40a92788b5113082420f8a58a5c5da07fba3d35..e91392a8dabe372692ed047ebb64116fd48b4ebf 100644 (file)
@@ -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
index b7a221f4929915cb9eabbd0561643213828b297d..00503e21f9a411939b83f30f3e451d48b9c7d4fc 100644 (file)
@@ -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]*
 
index f5bb3af73f70ec00df9a5501022c77951620b919..20be8dc1057195e59dc13a43e739c228397e7b49 100644 (file)
@@ -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 (file)
index d5e912b..0000000
+++ /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 (file)
index 6d514aa..0000000
+++ /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 (file)
index 0000000..0d4ec38
--- /dev/null
@@ -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:
index 2f7978977dbd60109de5dc7a4ee50901ef68df45..fa0ae8adf618c4246d465c55a7ba7d09b297ed9a 100644 (file)
@@ -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: