build: Select whether to include funopen() in the build system This makes sure we include it when expected, alongside the man pages, and the test cases, and do not accidentally break the ABI if the system starts providing such interface.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/configure.ac b/configure.ac
index 44717c2..c2bd521 100644
--- a/configure.ac
+++ b/configure.ac
@@ -297,6 +297,7 @@ AC_CHECK_FUNCS([\
flock \
fopencookie \
__fpurge \
+ funopen \
getauxval \
getentropy \
getexecname \
@@ -305,8 +306,31 @@ AC_CHECK_FUNCS([\
pstat_getproc \
sysconf \
])
+
+need_funopen=yes
+AS_CASE([$host_os],
+ [*-musl*], [
+ # On musl >= 1.1.19, fopencookie() got implemented, and because we were
+ # checking for its presence to decide whether to build funopen(), it got
+ # included in builds even when previously it had not been included, which
+ # is partially an ABI issue, but given that disabling it now would be
+ # worse, we'll ignore this as this is only a problem with downgrades. And
+ # enable it explicitly
+ need_funopen=yes
+ ],
+ [darwin*], [
+ # On macOS we do not have fopencookie(), and cannot implement it.
+ need_funopen=no
+ ],
+)
+
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
-AM_CONDITIONAL([HAVE_FOPENCOOKIE], [test "x$ac_cv_func_fopencookie" = "xyes"])
+AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
+AS_IF([test "x$need_funopen" = "xno" && \
+ test "x$ac_cv_func_funopen" != "xyes" && \
+ test "x$ac_cv_func_fopencookie" = "xyes"], [
+ AC_MSG_WARN([[can implement funopen() now based on newly added fopencooke(), report upstream]])
+])
AC_SUBST([MD5_LIBS])
AC_SUBST([LIBBSD_LIBS])
diff --git a/man/Makefile.am b/man/Makefile.am
index 961d2f5..6d1c86a 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -178,7 +178,6 @@ dist_man_MANS = \
fmtcheck.3bsd \
fparseln.3bsd \
fpurge.3bsd \
- funopen.3bsd \
getbsize.3bsd \
getmode.3bsd \
getpeereid.3bsd \
@@ -252,3 +251,9 @@ dist_man_MANS = \
wcslcat.3bsd \
wcslcpy.3bsd \
# EOL
+
+if NEED_FUNOPEN
+dist_man_MANS += \
+ funopen.3bsd \
+ # EOL
+endif
diff --git a/src/Makefile.am b/src/Makefile.am
index bc1add6..4781bdb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,7 +95,6 @@ libbsd_la_SOURCES = \
fmtcheck.c \
fparseln.c \
fpurge.c \
- funopen.c \
getbsize.c \
getpeereid.c \
heapsort.c \
@@ -137,6 +136,12 @@ libbsd_la_SOURCES += \
# EOL
endif
+if NEED_FUNOPEN
+libbsd_la_SOURCES += \
+ funopen.c \
+ # EOL
+endif
+
if NEED_TRANSPARENT_LIBMD
CLEANFILES += \
format.ld \
diff --git a/src/funopen.c b/src/funopen.c
index 0513e38..fdcdcba 100644
--- a/src/funopen.c
+++ b/src/funopen.c
@@ -138,5 +138,5 @@ funopen(const void *cookie,
return fopencookie(cookiewrap, mode, funcswrap);
}
#else
-#warning "Function funopen() is not provided on this platform."
+#error "Function funopen() needs to be ported."
#endif
diff --git a/test/Makefile.am b/test/Makefile.am
index 458a4e9..985e3e1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -55,7 +55,7 @@ check_PROGRAMS = \
vis-openbsd \
# EOL
-if HAVE_FOPENCOOKIE
+if NEED_FUNOPEN
check_PROGRAMS += funopen
endif