Browse code

fix building of openvpnsrvmsg.dll from eventmsg.mc in mingw builds

commit 06919a60ae61 introduces .mc files that need to be compiled to
.h and .bin by the windows "mc.exe" tool, and from there into a new
.dll. This worked for MSVC builds, did nothing for cmake/mingw builds,
and broke compilation on autoconf/mingw builds.

This patch consists of two parts:

1. add building of openvpnsrvmsg.dll to autoconf/mingw builds

Add logic to configure.ac to find the "windmc" binary in the linux or
mingw variants, add rules to src/openvpnserv/Makefile.am so make knows
what to do.

Libtool is getting in the way when "openvpnsrvmsg.dll" is created as
anything listed in ...BIN or ...LIB, so decare it as "DATA" and make
the necessary rules explicit.

2. fix building of openvpnsrvmsg.dll on cmake/mingw builds

Fix "find_program()" invocation to avoid using "midnight commander"
binary (mc) on Linux (called "windmc" there).

Change from "-Wl,--noentry" to linker invocation that works.

See also:
https://learn.microsoft.com/en-us/cpp/build/creating-a-resource-only-dll?view=msvc-170

Change-Id: I071e8190dac28f429257b8af1c6f9e68f8896bc0
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1197
Message-Id: <20250919112424.24728-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33083.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 744a2bd556833cf5e65d737e1bcffd2cb89a6d2f)

Gert Doering authored on 2025/09/19 20:24:19
Showing 3 changed files
... ...
@@ -417,6 +417,7 @@ AC_DEFINE_UNQUOTED([IFCONFIG_PATH], ["$IFCONFIG"], [Path to ifconfig tool])
417 417
 AC_DEFINE_UNQUOTED([IPROUTE_PATH], ["$IPROUTE"], [Path to iproute tool])
418 418
 AC_DEFINE_UNQUOTED([ROUTE_PATH], ["$ROUTE"], [Path to route tool])
419 419
 AC_DEFINE_UNQUOTED([SYSTEMD_ASK_PASSWORD_PATH], ["$SYSTEMD_ASK_PASSWORD"], [Path to systemd-ask-password tool])
420
+AC_CHECK_TOOLS([WINDMC], [windmc mc.exe],[no])
420 421
 
421 422
 #
422 423
 #  man page generation - based on python-docutils
... ...
@@ -40,7 +40,7 @@ endif ()
40 40
 file(MAKE_DIRECTORY ${MC_GEN_DIR})
41 41
 set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc)
42 42
 
43
-find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc)
43
+find_program(MC_COMPILER NAMES mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc)
44 44
 
45 45
 if (NOT MC_COMPILER)
46 46
     message(FATAL_ERROR "No message compiler found.")
... ...
@@ -57,12 +57,17 @@ add_custom_command(
57 57
 add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h)
58 58
 
59 59
 add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc)
60
+add_dependencies(openvpnservmsg msg_mc_gen)
60 61
 
61 62
 if (MSVC)
62 63
     set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY")
63 64
 else()
64
-    target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry")
65
+    set_target_properties(openvpnservmsg PROPERTIES LINKER_LANGUAGE C OUTPUT_NAME "openvpnservmsg")
66
+    target_link_options(openvpnservmsg PRIVATE
67
+        -Wl,--entry=0
68
+        -nostdlib
69
+        -nostartfiles
70
+    )
65 71
 endif()
66 72
 
67
-add_dependencies(openvpnservmsg msg_mc_gen)
68 73
 add_dependencies(openvpnserv msg_mc_gen)
... ...
@@ -26,6 +26,10 @@ openvpnserv_CFLAGS = \
26 26
 	-UNTDDI_VERSION -U_WIN32_WINNT \
27 27
 	-D_WIN32_WINNT=_WIN32_WINNT_VISTA
28 28
 openvpnserv_LDADD = -ladvapi32 -luserenv -liphlpapi -lfwpuclnt -lrpcrt4 -lshlwapi -lnetapi32 -lws2_32 -lntdll
29
+noinst_DATA = \
30
+	MSG00409.bin eventmsg.h eventmsg.rc openvpnservmsg.dll
31
+BUILT_SOURCES = \
32
+	eventmsg.h
29 33
 endif
30 34
 
31 35
 openvpnserv_SOURCES = \
... ...
@@ -36,3 +40,11 @@ openvpnserv_SOURCES = \
36 36
 	$(top_srcdir)/src/openvpn/block_dns.c $(top_srcdir)/src/openvpn/block_dns.h \
37 37
 	openvpnserv_resources.rc \
38 38
 	$(top_srcdir)/src/openvpn/ring_buffer.h
39
+
40
+openvpnservmsg.dll: eventmsg.o
41
+	$(CC) -shared -Wl,--entry=0 -nostdlib -nostartfiles -o $@ $<
42
+
43
+eventmsg.o: eventmsg.rc
44
+
45
+eventmsg.h: eventmsg.mc
46
+	$(WINDMC) -U $<