]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
build: On macOS do not build functions provided by the system
authorGuillem Jover <guillem@hadrons.org>
Tue, 4 Apr 2023 21:59:05 +0000 (23:59 +0200)
committerGuillem Jover <guillem@hadrons.org>
Mon, 17 Apr 2023 02:12:42 +0000 (04:12 +0200)
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
configure.ac
include/Makefile.am
include/bsd/grp.h
include/bsd/pwd.h
include/bsd/stdlib.h
include/bsd/string.h
man/Makefile.am
src/Makefile.am
src/pwcache.c
test/Makefile.am
test/overlay.c

index c2bd521e8e94e6cdbb4ba5c1477d667d4434d46e..d6446a06347983d34ef17dae09e7e6ddcef770c7 100644 (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" && \
index ca0d06f86b732b54e15bf43719dc5c06512067fe..31d86b41559743e13a03afd3bfe4821636c917cf 100644 (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
index b2705e5ee3b36a77c98483d3bf05481c683b323d..acf3d256323edb17c4c8dfef44d84a9cb2e68fb7 100644 (file)
 __BEGIN_DECLS
 int
 gid_from_group(const char *, gid_t *);
+#ifndef __APPLE__
 const char *
 group_from_gid(gid_t, int);
+#endif
 __END_DECLS
 
 #endif
index 798af4b2932bc29730dbaeabf517983e51362105..38214ae04f0c3ca22fa638b24952063f268208d4 100644 (file)
 __BEGIN_DECLS
 int
 uid_from_user(const char *, uid_t *);
+#ifndef __APPLE__
 const char *
 user_from_uid(uid_t, int);
+#endif
 __END_DECLS
 
 #endif
index 5732fd1c4c942b89d68ec0fe05a3774815d657e7..bba13af2e532c092743fa20ed88f6729e8f1cae2 100644 (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);
 
index 4f2b71c60d8913d1e522c165ab716904c82eba8b..1996697d2a3305da4635c29a0bf84c0451a1ea4b 100644 (file)
 #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) || \
index 6d1c86a89933120fa54271dc23197fa3949c0007..bc30c87de4665fe9527a606916993f5e36bd239a 100644 (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 \
index 4781bdb1d6c0fef60f87223731b3bd762af31049..c02561eb271a2a113437afb1a7c83f1a5b3f1cce 100644 (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 += \
index d54daa08cc7843d3310481e96ab74b1c130274bb..99609d9b301111262e65eb723c493098336afd55 100644 (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()
index 985e3e133175f256e929d7074fe7f98f311ef245..7d220f703556fafa57ff42a939cf515cf8282721 100644 (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
index d82f14ec0e1ac9876e775abfc197c2d1bd6fd377..af8323215f43d9565f1e546253178d1abcc114f9 100644 (file)
  * 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. */