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.
This commit is contained in:
Guillem Jover 2023-04-06 23:05:27 +02:00
parent 8b7a4d9d3b
commit bc65806ce2
5 changed files with 39 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@ check_PROGRAMS = \
vis-openbsd \
# EOL
if HAVE_FOPENCOOKIE
if NEED_FUNOPEN
check_PROGRAMS += funopen
endif