Browse code

sample-plugins: Partially autotoolize the sample-plugins build

The sample-plugins have their own set of build/winbuild scripts in each
of these plugin directories. This does not give a good way to reuse
various macros the autoconf/automake/configure process enables; which
can contain important macros to make some code build without errors or
warnings.

Normally we would embrace the full autoconf/automake approach. But this
is sample code which we only want to build per request and the built
code should not be installed anywhere via 'make install'. But since we
do use libtool other plug-ins being installed and automake gets kind of
cranky when it comes to define certain build targets not following the
expected use cases, we try to only embrace just enough of automake to
get our main goals achieved.

This changeset kicks out the build scripts and replaces them with a
single Makefile.plugins file, which defines the plugins we want to build
by default when running 'make from the sample-plugins directory.
Neither of these plugins are otherwise built by default. No sample-plugins
are being installed. But we have enough strings attached to automake
to grab the CFLAGS and LDFLAGS used by the rest of the code. This also
makes it easy to use #include "config.h" in sample code, to also get
various macros defined by the ./configure run.

This patch does not touch the winbuild scripts, as it seems building
these sample-plugins on Windows requires a bit different compile and
linking steps than *nix systems in general.

Signed-off-by: David Sommerseth <davids@openvpn.net>

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20200916141956.1277-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21020.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0b5141d8f946a274bf27b3592ac07dc9c6b0ee71)

David Sommerseth authored on 2020/09/16 23:19:56
Showing 10 changed files
... ...
@@ -1433,6 +1433,7 @@ AC_CONFIG_FILES([
1433 1433
 	doc/doxygen/Makefile
1434 1434
 	doc/doxygen/openvpn.doxyfile
1435 1435
 	include/Makefile
1436
+	sample/sample-plugins/Makefile
1436 1437
 	src/Makefile
1437 1438
 	src/compat/Makefile
1438 1439
 	src/openvpn/Makefile
1439 1440
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+#
1
+#  OpenVPN -- An application to securely tunnel IP networks
2
+#             over a single UDP port, with support for SSL/TLS-based
3
+#             session authentication and key exchange,
4
+#             packet encryption, packet authentication, and
5
+#             packet compression.
6
+#
7
+#  Copyright (C) 2002-2020 OpenVPN Inc <sales@openvpn.net>
8
+#
9
+
10
+MAINTAINERCLEANFILES = \
11
+	$(srcdir)/Makefile.in
12
+
13
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir) \
14
+	-I$(top_srcdir)/include -I$(top_builddir)/include
15
+
16
+# We don't want automake to pull in libtool for building these
17
+# sample-plugins.  Even though this breaks the conceptual ideas
18
+# around autoconf/automake/libtools ... these sample plug-ins
19
+# are just sample code, not to be installed or distributed outside
20
+# of the source tarball.  Not even built by default, by design.
21
+#
22
+# We only add this as a simple and convenient way to build all
23
+# these plug-ins with the same build parameters as the rest
24
+# of the OpenVPN code.
25
+#
26
+# All the plugins which will be built are processed in this
27
+# separate Makefile, which disconnects everything just enough
28
+# to achieve our goal.
29
+include Makefile.plugins
30
+
31
+
32
+dist-hook :
33
+	make -f Makefile.plugins clean
0 34
new file mode 100644
... ...
@@ -0,0 +1,36 @@
0
+#  SPDX-License-Identifier: GPL-2.0-only
1
+#
2
+#  Copyright (C) 2020 OpenVPN Inc <sales@openvpn.net>
3
+#
4
+
5
+#
6
+# Plug-ins to build - listed entries should not carry any extensions
7
+#
8
+PLUGINS = \
9
+	defer/simple \
10
+	keying-material-exporter-demo/keyingmaterialexporter \
11
+	log/log log/log_v3 \
12
+	simple/base64 \
13
+	simple/simple
14
+
15
+# All the plugins to build - rewritten with .so extension
16
+all : $(foreach var, $(PLUGINS), $(var).so)
17
+
18
+# Do not automatically remove object files
19
+# This is a special Make setting, to avoid adding an implicit
20
+# 'rm' command on object files - due to the .c.o/%.so rules below
21
+.PRECIOUS: %.o
22
+
23
+# Compile step
24
+.c.o :
25
+	test -d `dirname $@` || $(MKDIR_P) `dirname $@`; \
26
+	$(CC) -c -o $@ $(CFLAGS) $(AM_CPPFLAGS) -fPIC $<
27
+
28
+# Link step
29
+%.so : %.o
30
+	$(CC) $(LDFLAGS) -shared -fPIC -o $@ $<
31
+
32
+# Clean up all build object and shared object files
33
+clean :
34
+	rm -f $(foreach var, $(PLUGINS), $(var).o) \
35
+	$(foreach var, $(PLUGINS), $(var).so)
0 36
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+OpenVPN plug-in examples.
1
+
2
+Examples provided:
3
+
4
+* authentication and logging
5
+simple/simple.c -- using the --auth-user-pass-verify callback, verify
6
+                   that the username/password is "foo"/"bar".
7
+defer/simple.c  -- using the --auth-user-pass-verify callback,
8
+                   test deferred authentication.
9
+log/log.c       -- Extended variant of simple/simple.c which adds more
10
+                   logging of what is happening inside the plug-in
11
+log/log_v3.c    -- A variant of log/log.c, which makes use of the
12
+                   OpenVPN plug-in v3 API.  This will also log even more
13
+                   information related to certificates in use.
14
+
15
+* cryptography related
16
+simple/base64.c -- Example using the OpenVPN exported base64 encode/decode
17
+                   functions
18
+keying-material-exporter-demo/keyingmaterialexporter.c
19
+                -- Example based on TLS Keying Material Exporters over HTTP [RFC-5705]
20
+                   (openvpn/doc/keying-material-exporter.txt).  For more details, see
21
+                   keying-material-exporter-demo/README
22
+
23
+
24
+To build on *BSD/Linux platforms (requires GNU Make):
25
+
26
+   gmake                   (builds a default set of plug-ins)
27
+   gmake simple/simple.so
28
+
29
+To build on Windows platform (MinGW):
30
+
31
+   cd simple; ./winbuild simple.so
32
+
33
+To use in OpenVPN, add to config file:
34
+
35
+  plugin simple.so (Linux/BSD/etc.)
36
+  plugin simple.dll
0 37
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-OpenVPN plugin examples.
2
-
3
-Examples provided:
4
-
5
-simple.c -- using the --auth-user-pass-verify callback,
6
-            test deferred authentication.
7
-
8
-To build:
9
-
10
-  ./build simple (Linux/BSD/etc.)
11
-  ./winbuild simple (MinGW on Windows)
12
-
13
-To use in OpenVPN, add to config file:
14
-
15
-  plugin simple.so (Linux/BSD/etc.)
16
-  plugin simple.dll (MinGW on Windows)
17 1
deleted file mode 100755
... ...
@@ -1,15 +0,0 @@
1
-#!/bin/sh
2
-
3
-#
4
-# Build an OpenVPN plugin module on *nix.  The argument should
5
-# be the base name of the C source file (without the .c).
6
-#
7
-
8
-# This directory is where we will look for openvpn-plugin.h
9
-CPPFLAGS="${CPPFLAGS:--I../../../include}"
10
-
11
-CC="${CC:-gcc}"
12
-CFLAGS="${CFLAGS:--O2 -Wall -g}"
13
-
14
-$CC $CPPFLAGS $CFLAGS -fPIC -c $1.c && \
15
-$CC $CFLAGS -fPIC -shared ${LDFLAGS} -Wl,-soname,$1.so -o $1.so $1.o -lc
16 1
deleted file mode 100755
... ...
@@ -1,15 +0,0 @@
1
-#!/bin/sh
2
-
3
-#
4
-# Build an OpenVPN plugin module on *nix.  The argument should
5
-# be the base name of the C source file (without the .c).
6
-#
7
-
8
-# This directory is where we will look for openvpn-plugin.h
9
-CPPFLAGS="${CPPFLAGS:--I../../..}"
10
-
11
-CC="${CC:-gcc}"
12
-CFLAGS="${CFLAGS:--O2 -Wall -g}"
13
-
14
-$CC $CPPFLAGS $CFLAGS -fPIC -c $1.c && \
15
-$CC $CFLAGS -fPIC -shared $LDFLAGS -Wl,-soname,$1.so -o $1.so $1.o -lc
16 1
deleted file mode 100755
... ...
@@ -1,15 +0,0 @@
1
-#!/bin/sh
2
-
3
-#
4
-# Build an OpenVPN plugin module on *nix.  The argument should
5
-# be the base name of the C source file (without the .c).
6
-#
7
-
8
-# This directory is where we will look for openvpn-plugin.h
9
-CPPFLAGS="${CPPFLAGS:--I../../../include}"
10
-
11
-CC="${CC:-gcc}"
12
-CFLAGS="${CFLAGS:--O2 -Wall -g}"
13
-
14
-$CC $CPPFLAGS $CFLAGS -fPIC -c $1.c && \
15
-$CC $CFLAGS -fPIC -shared $LDFLAGS -Wl,-soname,$1.so -o $1.so $1.o -lc
16 1
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-OpenVPN plugin examples.
2
-
3
-Examples provided:
4
-
5
-simple.c -- using the --auth-user-pass-verify callback, verify
6
-            that the username/password is "foo"/"bar".
7
-
8
-To build:
9
-
10
-  ./build simple (Linux/BSD/etc.)
11
-  ./winbuild simple (MinGW on Windows)
12
-
13
-To use in OpenVPN, add to config file:
14
-
15
-  plugin simple.so (Linux/BSD/etc.)
16
-  plugin simple.dll (MinGW on Windows)
17 1
deleted file mode 100755
... ...
@@ -1,15 +0,0 @@
1
-#!/bin/sh
2
-
3
-#
4
-# Build an OpenVPN plugin module on *nix.  The argument should
5
-# be the base name of the C source file (without the .c).
6
-#
7
-
8
-# This directory is where we will look for openvpn-plugin.h
9
-CPPFLAGS="${CPPFLAGS:--I../../..}"
10
-
11
-CC="${CC:-gcc}"
12
-CFLAGS="${CFLAGS:--O2 -Wall -g}"
13
-
14
-$CC $CPPFLAGS $CFLAGS -fPIC -c $1.c && \
15
-$CC $CFLAGS -fPIC -shared $LDFLAGS -Wl,-soname,$1.so -o $1.so $1.o -lc