build: On macOS do not build functions provided by the system

We have never built before on macOS, so we can exclude all the functions
that are currently provided in the system.

Closes: #1
Closes: !3
This commit is contained in:
Guillem Jover 2023-04-04 23:59:05 +02:00
parent bc65806ce2
commit 21d12b0211
11 changed files with 177 additions and 36 deletions

View File

@ -148,9 +148,6 @@ AC_SEARCH_LIBS([SHA512Update], [md], [
])
LIBS="$saved_LIBS"
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
[test "x$need_transparent_libmd" = "xyes"])
AS_CASE([$host_os],
[*-gnu*], [
# In old glibc versions (< 2.17) clock_gettime() is in librt.
@ -305,8 +302,19 @@ AC_CHECK_FUNCS([\
open_memstream \
pstat_getproc \
sysconf \
uid_from_user \
gid_from_group \
user_from_uid \
group_from_gid \
])
need_arc4random=yes
need_md5=yes
need_nlist=yes
need_strl=yes
need_strmode=yes
need_pwcache=yes
need_fpurge=yes
need_funopen=yes
AS_CASE([$host_os],
[*-musl*], [
@ -319,12 +327,31 @@ AS_CASE([$host_os],
need_funopen=yes
],
[darwin*], [
# On macOS these are provided by the system, and libbsd has never built
# there, so we can avoid providing these with no ABI breakage.
need_arc4random=no
need_transparent_libmd=no
need_md5=no
need_nlist=no
need_strl=no
need_strmode=no
need_pwcache=no
need_fpurge=no
# 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([NEED_ARC4RANDOM], [test "x$need_arc4random" = "xyes"])
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD], [test "x$need_transparent_libmd" = "xyes"])
AM_CONDITIONAL([NEED_MD5], [test "x$need_md5" = "xyes"])
AM_CONDITIONAL([NEED_NLIST], [test "x$need_nlist" = "xyes"])
AM_CONDITIONAL([NEED_STRL], [test "x$need_strl" = "xyes"])
AM_CONDITIONAL([NEED_STRMODE], [test "x$need_strmode" = "xyes"])
AM_CONDITIONAL([NEED_PWCACHE], [test "x$need_pwcache" = "xyes"])
AM_CONDITIONAL([NEED_FPURGE], [test "x$need_fpurge" = "xyes"])
AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
AS_IF([test "x$need_funopen" = "xno" && \
test "x$ac_cv_func_funopen" != "xyes" && \

View File

@ -17,8 +17,6 @@ nobase_include_HEADERS = \
bsd/grp.h \
bsd/inttypes.h \
bsd/libutil.h \
bsd/md5.h \
bsd/nlist.h \
bsd/pwd.h \
bsd/readpassphrase.h \
bsd/stdio.h \
@ -30,3 +28,15 @@ nobase_include_HEADERS = \
bsd/vis.h \
bsd/wchar.h \
# EOL
if NEED_MD5
nobase_include_HEADERS += \
bsd/md5.h \
# EOL
endif
if NEED_NLIST
nobase_include_HEADERS += \
bsd/nlist.h \
# EOL
endif

View File

@ -44,8 +44,10 @@
__BEGIN_DECLS
int
gid_from_group(const char *, gid_t *);
#ifndef __APPLE__
const char *
group_from_gid(gid_t, int);
#endif
__END_DECLS
#endif

View File

@ -44,8 +44,10 @@
__BEGIN_DECLS
int
uid_from_user(const char *, uid_t *);
#ifndef __APPLE__
const char *
user_from_uid(uid_t, int);
#endif
__END_DECLS
#endif

View File

@ -51,6 +51,7 @@
#include <stdint.h>
__BEGIN_DECLS
#if !defined(__APPLE__)
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 36) || \
!defined(_DEFAULT_SOURCE)
@ -60,6 +61,7 @@ uint32_t arc4random_uniform(uint32_t upper_bound);
#endif
void arc4random_stir(void);
void arc4random_addrandom(unsigned char *dat, int datlen);
#endif
int dehumanize_number(const char *str, int64_t *size);

View File

@ -41,10 +41,14 @@
#include <sys/types.h>
__BEGIN_DECLS
#ifndef __APPLE__
size_t strlcpy(char *dst, const char *src, size_t siz);
size_t strlcat(char *dst, const char *src, size_t siz);
#endif
char *strnstr(const char *str, const char *find, size_t str_len);
#ifndef __APPLE__
void strmode(mode_t mode, char *str);
#endif
#if !defined(__GLIBC__) || \
!__GLIBC_PREREQ(2, 25) || \

View File

@ -177,13 +177,10 @@ dist_man_MANS = \
freezero.3bsd \
fmtcheck.3bsd \
fparseln.3bsd \
fpurge.3bsd \
getbsize.3bsd \
getmode.3bsd \
getpeereid.3bsd \
getprogname.3bsd \
gid_from_group.3bsd \
group_from_gid.3bsd \
heapsort.3bsd \
humanize_number.3bsd \
le16dec.3bsd \
@ -193,15 +190,12 @@ dist_man_MANS = \
le64dec.3bsd \
le64enc.3bsd \
libbsd.7 \
md5.3bsd \
mergesort.3bsd \
nlist.3bsd \
pidfile.3bsd \
pidfile_close.3bsd \
pidfile_open.3bsd \
pidfile_remove.3bsd \
pidfile_write.3bsd \
pwcache.3bsd \
queue.3bsd \
radixsort.3bsd \
readpassphrase.3bsd \
@ -219,9 +213,6 @@ dist_man_MANS = \
sl_init.3bsd \
sradixsort.3bsd \
stringlist.3bsd \
strlcat.3bsd \
strlcpy.3bsd \
strmode.3bsd \
strnstr.3bsd \
strnunvis.3bsd \
strnvis.3bsd \
@ -244,14 +235,53 @@ dist_man_MANS = \
timespecsub.3bsd \
timeval.3bsd \
tree.3bsd \
uid_from_user.3bsd \
unvis.3bsd \
user_from_uid.3bsd \
vis.3bsd \
wcslcat.3bsd \
wcslcpy.3bsd \
# EOL
if NEED_MD5
dist_man_MANS += \
md5.3bsd \
# EOL
endif
if NEED_NLIST
dist_man_MANS += \
nlist.3bsd \
# EOL
endif
if NEED_STRL
dist_man_MANS += \
strlcat.3bsd \
strlcpy.3bsd \
# EOL
endif
if NEED_STRMODE
dist_man_MANS += \
strmode.3bsd \
# EOL
endif
if NEED_PWCACHE
dist_man_MANS += \
pwcache.3bsd \
uid_from_user.3bsd \
user_from_uid.3bsd \
gid_from_group.3bsd \
group_from_gid.3bsd \
# EOL
endif
if NEED_FPURGE
dist_man_MANS += \
fpurge.3bsd \
# EOL
endif
if NEED_FUNOPEN
dist_man_MANS += \
funopen.3bsd \

View File

@ -75,14 +75,7 @@ EXTRA_libbsd_la_DEPENDENCIES += \
# EOL
endif
libbsd_la_SOURCES = \
arc4random.c \
arc4random.h \
arc4random_linux.h \
arc4random_uniform.c \
arc4random_unix.h \
arc4random_win.h \
bsd_getopt.c \
chacha_private.h \
closefrom.c \
dehumanize_number.c \
err.c \
@ -94,7 +87,6 @@ libbsd_la_SOURCES = \
flopen.c \
fmtcheck.c \
fparseln.c \
fpurge.c \
getbsize.c \
getpeereid.c \
heapsort.c \
@ -102,12 +94,9 @@ libbsd_la_SOURCES = \
inet_net_pton.c \
local-elf.h \
local-link.h \
md5.c \
merge.c \
nlist.c \
pidfile.c \
progname.c \
pwcache.c \
radixsort.c \
readpassphrase.c \
reallocarray.c \
@ -115,10 +104,7 @@ libbsd_la_SOURCES = \
recallocarray.c \
setmode.c \
setproctitle.c \
strlcat.c \
strlcpy.c \
stringlist.c \
strmode.c \
strnstr.c \
strtoi.c \
strtonum.c \
@ -130,11 +116,59 @@ libbsd_la_SOURCES = \
wcslcpy.c \
# EOL
if NEED_ARC4RANDOM
if !HAVE_GETENTROPY
libbsd_la_SOURCES += \
getentropy.c \
# EOL
endif
libbsd_la_SOURCES += \
arc4random.c \
arc4random.h \
arc4random_linux.h \
arc4random_uniform.c \
arc4random_unix.h \
arc4random_win.h \
chacha_private.h \
# EOL
endif
if NEED_MD5
libbsd_la_SOURCES += \
md5.c \
# EOL
endif
if NEED_NLIST
libbsd_la_SOURCES += \
nlist.c \
# EOL
endif
if NEED_STRL
libbsd_la_SOURCES += \
strlcat.c \
strlcpy.c \
# EOL
endif
if NEED_STRMODE
libbsd_la_SOURCES += \
strmode.c \
# EOL
endif
if NEED_PWCACHE
libbsd_la_SOURCES += \
pwcache.c \
# EOL
endif
if NEED_FPURGE
libbsd_la_SOURCES += \
fpurge.c \
# EOL
endif
if NEED_FUNOPEN
libbsd_la_SOURCES += \

View File

@ -103,6 +103,7 @@ st_hash(const char *name, size_t len, int tabsz)
return key % tabsz;
}
#ifndef HAVE_USER_FROM_UID
/*
* uidtb_start
* creates an an empty uidtb
@ -124,7 +125,9 @@ uidtb_start(void)
}
return 0;
}
#endif
#ifndef HAVE_GROUP_FROM_GID
/*
* gidtb_start
* creates an an empty gidtb
@ -146,6 +149,7 @@ gidtb_start(void)
}
return 0;
}
#endif
/*
* usrtb_start
@ -191,6 +195,7 @@ grptb_start(void)
return 0;
}
#ifndef HAVE_USER_FROM_UID
/*
* user_from_uid()
* caches the name (if any) for the uid. If noname clear, we always
@ -251,7 +256,9 @@ user_from_uid(uid_t uid, int noname)
}
return ptr->name;
}
#endif
#ifndef HAVE_GROUP_FROM_GID
/*
* group_from_gid()
* caches the name (if any) for the gid. If noname clear, we always
@ -312,6 +319,7 @@ group_from_gid(gid_t gid, int noname)
}
return ptr->name;
}
#endif
/*
* uid_from_user()

View File

@ -40,30 +40,46 @@ check_PROGRAMS = \
humanize \
fgetln \
fparseln \
fpurge \
md5 \
nlist \
proctitle-init \
progname \
pwcache \
setmode \
strl \
strmode \
strnstr \
strtonum \
vis \
vis-openbsd \
# EOL
if NEED_NLIST
check_PROGRAMS += nlist
endif
if NEED_STRL
check_PROGRAMS += strl
endif
if NEED_STRMODE
check_PROGRAMS += strmode
endif
if NEED_PWCACHE
check_PROGRAMS += pwcache
endif
if NEED_FPURGE
check_PROGRAMS += fpurge
endif
if NEED_FUNOPEN
check_PROGRAMS += funopen
endif
if NEED_ARC4RANDOM
if HAVE_LIBTESTU01
arc4random_LDADD = $(LDADD) $(TESTU01_LIBS)
check_PROGRAMS += arc4random
endif
endif
if BUILD_LIBBSD_CTOR
proctitle_LDFLAGS = \
@ -75,10 +91,14 @@ proctitle_LDFLAGS = \
check_PROGRAMS += proctitle
endif
if NEED_MD5
check_PROGRAMS += md5
if NEED_TRANSPARENT_LIBMD
# On the installed system this is handled via the ld script.
md5_LDADD = $(LDADD) $(MD5_LIBS)
endif
endif
fgetln_SOURCES = test-stream.c test-stream.h fgetln.c
fgetln_CFLAGS = -Wno-deprecated-declarations

View File

@ -28,12 +28,14 @@
* other headers through magic macros, to check that the overlay is working
* properly. */
#include <errno.h>
#ifndef __APPLE__
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#endif
#include <stdint.h>
/* Include libbsd overlayed headers that might get partially included. */