blob: b2d7dc0e2495931e7e691e016786add0dfe7f4b2 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From b859ab1b211d348b46eca9158b7742f050c8115e Mon Sep 17 00:00:00 2001
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002From: Eric Blake <eblake@redhat.com>
3Date: Wed, 14 Sep 2016 08:17:06 -0500
4Subject: [PATCH] AC_HEADER_MAJOR: port to glibc 2.25
5
6glibc 2.25 is deprecating the namespace pollution of <sys/types.h>
7injecting major(), minor(), and makedev() into the compilation
8environment, with a warning that insists that users include
9<sys/sysmacros.h> instead. However, because the expansion of
10AC_HEADER_MAJOR didn't bother checking sys/sysmacros.h until
11after probing whether sys/types.h pollutes the namespace, it was
12not defining MAJOR_IN_SYSMACROS, with the result that code
13compiled with -Werror chokes on the deprecation warnings because
14it was not including sysmacros.h.
15
16In addition to fixing autoconf (which only benefits projects
17that rebuild configure after this fix is released), we can also
18give a hint to distros on how they can populate config.site with
19a cache variable to force pre-existing configure scripts without
20the updated macro to behave sanely in the presence of glibc 2.25
21(the documentation is especially useful since that cache variable
22is no longer present in autoconf after this patch).
23
24Note that mingw lacks major/minor/makedev in any of its standard
25headers; for that platform, the behavior of this macro is unchanged
26(code using the recommended include formula will get a compile error
27when trying to use major(), whether before or after this patch); but
28for now, it is assumed that programs actually concerned with
29creating devices are not worried about portability to mingw. If
30desired, a later patch could tighten AC_HEADER_MAJOR to fail at
31configure time if the macros are unavailable in any of the three
32system headers, but that semantic change is not worth mixing into
33this patch.
34
35* lib/autoconf/headers.m4 (AC_HEADER_MAJOR): Drop check for
36major within sys/types.h; it interferes with the need to check
37sysmacros.h first.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038
39Signed-off-by: Eric Blake <eblake@redhat.com>
Brad Bishop19323692019-04-05 15:28:33 -040040
41Remove the documentation change from the patch
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042Upstream-Status: Backport
43
Brad Bishop19323692019-04-05 15:28:33 -040044Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
45---
46 lib/autoconf/headers.m4 | 30 ++++++++++++++----------------
47 1 file changed, 14 insertions(+), 16 deletions(-)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048
Brad Bishop19323692019-04-05 15:28:33 -040049diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
50index 81a7fa2..a57d0d3 100644
51--- a/lib/autoconf/headers.m4
52+++ b/lib/autoconf/headers.m4
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053@@ -502,31 +502,29 @@ fi
54
55 # AC_HEADER_MAJOR
56 # ---------------
57+# Thanks to glibc 2.25 deprecating macros in sys/types.h, coupled with
58+# back-compat to autoconf 2.69, we need the following logic:
59+# Check whether <sys/types.h> compiles.
60+# If <sys/mkdev.h> compiles, assume it provides major/minor/makedev.
61+# Otherwise, if <sys/sysmacros.h> compiles, assume it provides the macros.
62+# Otherwise, either the macros were provided by <sys/types.h>, or do
63+# not exist on the platform. Code trying to use these three macros is
64+# assumed to not care about platforms that lack the macros.
65 AN_FUNCTION([major], [AC_HEADER_MAJOR])
66 AN_FUNCTION([makedev], [AC_HEADER_MAJOR])
67 AN_FUNCTION([minor], [AC_HEADER_MAJOR])
68 AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
69 AC_DEFUN([AC_HEADER_MAJOR],
70-[AC_CACHE_CHECK(whether sys/types.h defines makedev,
71- ac_cv_header_sys_types_h_makedev,
72-[AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/types.h>]],
73- [[return makedev(0, 0);]])],
74- [ac_cv_header_sys_types_h_makedev=yes],
75- [ac_cv_header_sys_types_h_makedev=no])
76-])
77-
78-if test $ac_cv_header_sys_types_h_makedev = no; then
79+[AC_CHECK_HEADERS_ONCE([sys/types.h])
80 AC_CHECK_HEADER(sys/mkdev.h,
81 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
82 [Define to 1 if `major', `minor', and `makedev' are
83 declared in <mkdev.h>.])])
84-
85- if test $ac_cv_header_sys_mkdev_h = no; then
86- AC_CHECK_HEADER(sys/sysmacros.h,
87- [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
88- [Define to 1 if `major', `minor', and `makedev'
89- are declared in <sysmacros.h>.])])
90- fi
91+if test $ac_cv_header_sys_mkdev_h = no; then
92+ AC_CHECK_HEADER(sys/sysmacros.h,
93+ [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
94+ [Define to 1 if `major', `minor', and `makedev'
95+ are declared in <sysmacros.h>.])])
96 fi
97 ])# AC_HEADER_MAJOR
98
Brad Bishop19323692019-04-05 15:28:33 -040099--
1002.7.4
101