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.
pull/10469/head
Jason Ish 3 years ago committed by Victor Julien
parent 1fdf3f644e
commit 6d792f017b

@ -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

@ -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]*

@ -1,2 +1,3 @@
!/Makefile.in
*.so
*.la

@ -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

@ -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 *~

@ -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:

@ -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:

Loading…
Cancel
Save