Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cc(1)'s __has_include() instead of build-system checks #1118

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Nov 12, 2024

All relevant compilers have had __has_include() since immemorial times (GCC since version 5, according to https://en.cppreference.com/w/c/compiler_support). It's now a C23 standard feature.

This reduces the complexity of the build system.


Revisions:

v1b
  • Rebase
$ git range-diff master..gh/has_include shadow/master..has_include 
1:  f716f558 = 1:  1afc7448 configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  95ca17af = 2:  6107b7f8 configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
3:  3d98527a = 3:  0a32d621 lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  8052bd28 = 4:  fe3a23d3 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  114cfa89 = 5:  3fd1baab lib/idmapping.c: Unconditionally include <sys/prctl.h>
6:  4c72c6c3 = 6:  17eef32a configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
7:  60583eb9 = 7:  c4a55a7a configure.ac: Remove unused AC_CHECK_HEADERS() checks
v2
  • Rebase
$ git range-diff --creation-factor=99 master..gh/has_include shadow/master..has_include 
1:  1afc7448 = 1:  25b8fb8f configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  6107b7f8 ! 2:  6a9992c2 configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
    @@ configure.ac: dnl Checks for libraries.
     
      ## lib/csrand.c ##
     @@
    - #include <stdio.h>
    + #include <stdint.h>
      #include <stdlib.h>
      #include <unistd.h>
     -#if HAVE_SYS_RANDOM_H
    @@ lib/csrand.c
     +#if __has_include(<sys/random.h>)
     +# include <sys/random.h>
      #endif
    -+
    + 
      #include "bit.h"
    - #include "defines.h"
    - #include "prototypes.h"
3:  0a32d621 = 3:  6df8270f lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  fe3a23d3 = 4:  39255d70 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  3fd1baab ! 5:  00f96fc4 lib/idmapping.c: Unconditionally include <sys/prctl.h>
    @@ lib/idmapping.c
      #include <stdlib.h>
      #include <stdio.h>
      #include <strings.h>
    -+#include <sys/prctl.h>
    - 
    - #include "alloc/calloc.h"
    - #include "alloc/x/xmalloc.h"
    -@@
    - #include "string/sprintf/stpeprintf.h"
    - #include "idmapping.h"
    - #if HAVE_SYS_CAPABILITY_H
    --#include <sys/prctl.h>
    +-#if HAVE_SYS_CAPABILITY_H
    + #include <sys/prctl.h>
    ++#if HAVE_SYS_CAPABILITY_H
      #include <sys/capability.h>
      #endif
    - #include "shadowlog.h"
    + 
6:  17eef32a ! 6:  3ace1b19 configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
    @@ lib/idmapping.c
      #include <stdio.h>
      #include <strings.h>
      #include <sys/prctl.h>
    -+#if __has_include(<sys/capability.h>)
    -+# include <sys/capability.h>
    -+#endif
    - 
    - #include "alloc/calloc.h"
    - #include "alloc/x/xmalloc.h"
    -@@
    - #include "prototypes.h"
    - #include "string/sprintf/stpeprintf.h"
    - #include "idmapping.h"
     -#if HAVE_SYS_CAPABILITY_H
     -#include <sys/capability.h>
    --#endif
    - #include "shadowlog.h"
    - #include "sizeof.h"
    ++#if __has_include(<sys/capability.h>)
    ++# include <sys/capability.h>
    + #endif
      
    + #include "alloc/calloc.h"
     @@ lib/idmapping.c: get_map_ranges(int ranges, int argc, char **argv)
       */
      #define ULONG_DIGITS (((WIDTHOF(unsigned long) + 9)/10)*3)
7:  c4a55a7a = 7:  2759f057 configure.ac: Remove unused AC_CHECK_HEADERS() checks

It's a widely available header.

Signed-off-by: Alejandro Colomar <[email protected]>
…HAVE_SYS_CAPABILITY_H

Signed-off-by: Alejandro Colomar <[email protected]>
$ grep -rE 'HAVE_(UTMP)_H'
$ grep -rE 'HAVE_(TERMIO|SGTTY|SYS_IOCTL|PATHS)_H'
$ grep -rE 'HAVE_(LASTLOG|RPC_KEY_PROT|ACL_LIBACL)_H'
$ grep -rE 'HAVE_(ATTR_LIBATTR|ATTR_ERROR_CONTEXT)_H'
$

Signed-off-by: Alejandro Colomar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant