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
v2b
  • Rebase
$ git range-diff master..gh/has_include shadow/master..has_include 
1:  25b8fb8f = 1:  2db33cc3 configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  6a9992c2 = 2:  510f63d8 configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
3:  6df8270f = 3:  5631ed7d lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  39255d70 = 4:  5c845329 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  00f96fc4 = 5:  d127343b lib/idmapping.c: Unconditionally include <sys/prctl.h>
6:  3ace1b19 = 6:  705dc77d configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
7:  2759f057 = 7:  a5510806 configure.ac: Remove unused AC_CHECK_HEADERS() checks
v2c
  • Rebase
$ git range-diff master..gh/has_include shadow/master..has_include 
1:  2db33cc3 = 1:  f2febe08 configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  510f63d8 = 2:  b64be8ee configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
3:  5631ed7d = 3:  4bd80878 lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  5c845329 = 4:  731ee529 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  d127343b = 5:  d5344369 lib/idmapping.c: Unconditionally include <sys/prctl.h>
6:  705dc77d = 6:  7e6aa4cc configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
7:  a5510806 = 7:  8e2ad8cc configure.ac: Remove unused AC_CHECK_HEADERS() checks
v2d
  • Rebase
$ git range-diff master..gh/has_include shadow/master..has_include 
1:  f2febe08 = 1:  f3f3e72b configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  b64be8ee = 2:  88b29038 configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
3:  4bd80878 = 3:  a655dfaf lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  731ee529 = 4:  10331b50 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  d5344369 = 5:  2a2a3770 lib/idmapping.c: Unconditionally include <sys/prctl.h>
6:  7e6aa4cc = 6:  27b5fae8 configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
7:  8e2ad8cc = 7:  36a0b6ed configure.ac: Remove unused AC_CHECK_HEADERS() checks
v2e
  • Rebase
$ git range-diff master..gh/has_include shadow/master..has_include 
1:  f3f3e72b = 1:  f1a28710 configure.ac, lib/: Use __has_include(<crypt.h>) instead of HAVE_CRYPT_H
2:  88b29038 = 2:  087830e9 configure.ac, lib/: Use __has_include(<sys/random.h>) instead of HAVE_SYS_RANDOM_H
3:  a655dfaf = 3:  a839189a lib/: Use __has_include(<security/pam_misc.h>) instead of HAVE_SECURITY_PAM_MISC_H
4:  10331b50 = 4:  b39aecd5 lib/: Use __has_include(<security/openpam.h>) instead of HAVE_SECURITY_OPENPAM_H
5:  2a2a3770 = 5:  f91f5769 lib/idmapping.c: Unconditionally include <sys/prctl.h>
6:  27b5fae8 = 6:  0b111675 configure.ac, lib/: Use __has_include(<sys/capability.h>) instead of HAVE_SYS_CAPABILITY_H
7:  36a0b6ed = 7:  94cbd060 configure.ac: Remove unused AC_CHECK_HEADERS() checks

@alejandro-colomar
Copy link
Collaborator Author

Queued after the release of 4.17.0.

@alejandro-colomar alejandro-colomar marked this pull request as draft December 6, 2024 12:17
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]>
@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 22, 2024 12:01
@alejandro-colomar alejandro-colomar added the Simpler A good issue for a new beginner label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simpler A good issue for a new beginner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant