1  #!/usr/bin/python3
       2  # Check if glibc provided sys/mount.h can be used along related kernel
       3  # headers.
       4  # Copyright (C) 2022-2023 Free Software Foundation, Inc.
       5  # This file is part of the GNU C Library.
       6  #
       7  # The GNU C Library is free software; you can redistribute it and/or
       8  # modify it under the terms of the GNU Lesser General Public
       9  # License as published by the Free Software Foundation; either
      10  # version 2.1 of the License, or (at your option) any later version.
      11  #
      12  # The GNU C Library is distributed in the hope that it will be useful,
      13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
      14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15  # Lesser General Public License for more details.
      16  #
      17  # You should have received a copy of the GNU Lesser General Public
      18  # License along with the GNU C Library; if not, see
      19  # <https://www.gnu.org/licenses/>.
      20  
      21  import argparse
      22  import sys
      23  
      24  import glibcextract
      25  
      26  
      27  def main():
      28      """The main entry point."""
      29      parser = argparse.ArgumentParser(
      30          description='Check if glibc provided sys/mount.h can be '
      31                      ' used along related kernel headers.')
      32      parser.add_argument('--cc', metavar='CC',
      33                          help='C compiler (including options) to use')
      34      args = parser.parse_args()
      35  
      36      if glibcextract.compile_c_snippet(
      37              '#include <linux/mount.h>',
      38              args.cc).returncode != 0:
      39          sys.exit (77)
      40  
      41      def check(testname, snippet):
      42          # Add -Werror to catch macro redefinitions and _ISOMAC to avoid
      43          # internal glibc definitions.
      44          r = glibcextract.compile_c_snippet(snippet, args.cc,
      45                  '-Werror -D_ISOMAC')
      46          if r.returncode != 0:
      47              print('error: test {}:\n{}'.format(testname, r.output.decode()))
      48          return r.returncode
      49  
      50      status = max(
      51          check("sys/mount.h + linux/mount.h",
      52                "#include <sys/mount.h>\n"
      53                "#include <linux/mount.h>"),
      54          check("sys/mount.h + linux/fs.h",
      55                "#include <sys/mount.h>\n"
      56                "#include <linux/fs.h>"),
      57          check("linux/mount.h + sys/mount.h",
      58                "#include <linux/mount.h>\n"
      59                "#include <sys/mount.h>"),
      60          check("linux/fs.h + sys/mount.h",
      61                "#include <linux/fs.h>\n"
      62                "#include <sys/mount.h>"))
      63      sys.exit(status)
      64  
      65  if __name__ == '__main__':
      66      main()