Blame SOURCES/glibc-rh1505492-undef-49.patch

c6d234
commit 4a6aca7bf8a70f1dc66a07c04aba2d7fd837602d
c6d234
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
c6d234
Date:   Mon Dec 29 17:37:54 2014 +0530
c6d234
c6d234
    Remove Wundef warnings for specification macros
c6d234
    
c6d234
    This patch adds a file posix-conf-vars.list that is used to generate
c6d234
    macros to determine if a macro is defined as set, unset or not
c6d234
    defined.  gen-posix-conf-vars.awk processes this file and generates a
c6d234
    header (posix-conf-vars-def.h) with these macros.  A new header
c6d234
    posix-conf-vars.h includes this generated header and defines accessor
c6d234
    macros for the generated macros.
c6d234
    
c6d234
    Tested on x86_64.
c6d234
    
c6d234
            * posix/Makefile (before-compile): Add posix-conf-vars-def.h.
c6d234
            ($(objpfx)posix-conf-vars-def.h): New target.
c6d234
            * posix/posix-conf-vars.list: New file.
c6d234
            * posix/posix-conf-vars.h: New file.
c6d234
            * posix/confstr.c: Include posix-conf-vars.h.
c6d234
            (confstr): Use CONF_IS_* macros.
c6d234
            * posix/posix-envs.def: Include posix-conf-vars.h.  Use
c6d234
            CONF_IS_* macros.
c6d234
            * scripts/gen-posix-conf-vars.awk: New file.
c6d234
c6d234
diff --git a/posix/Makefile b/posix/Makefile
c6d234
index 4034282866139aaa..c272e87a480f5254 100644
c6d234
--- a/posix/Makefile
c6d234
+++ b/posix/Makefile
c6d234
@@ -96,7 +96,7 @@ others		:= getconf
c6d234
 install-bin	:= getconf
c6d234
 install-others-programs	:= $(inst_libexecdir)/getconf
c6d234
 
c6d234
-before-compile	+= testcases.h ptestcases.h
c6d234
+before-compile	+= testcases.h ptestcases.h posix-conf-vars-def.h
c6d234
 
c6d234
 # So they get cleaned up.
c6d234
 generated := $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
c6d234
@@ -288,3 +288,9 @@ $(objpfx)getconf.speclist: getconf-speclist.c posix-envs.def
c6d234
 # be built both makes it available for eyeball inspection and avoids the
c6d234
 # surprise of things that look like compilation being done by 'make install'.
c6d234
 others: $(objpfx)getconf.speclist
c6d234
+
c6d234
+$(objpfx)posix-conf-vars-def.h: $(..)scripts/gen-posix-conf-vars.awk \
c6d234
+				posix-conf-vars.list Makefile
c6d234
+	$(make-target-directory)
c6d234
+	$(AWK) -f $(filter-out Makefile, $^) > $@.tmp
c6d234
+	mv -f $@.tmp $@
c6d234
diff --git a/posix/confstr.c b/posix/confstr.c
c6d234
index 7d86d60bc177c32d..5b03986a3678e007 100644
c6d234
--- a/posix/confstr.c
c6d234
+++ b/posix/confstr.c
c6d234
@@ -21,6 +21,7 @@
c6d234
 #include <string.h>
c6d234
 #include <confstr.h>
c6d234
 #include "../version.h"
c6d234
+#include <posix-conf-vars.h>
c6d234
 
c6d234
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
c6d234
    of BUF with the value corresponding to NAME and zero-terminate BUF.
c6d234
@@ -100,9 +101,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
c6d234
     case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
c6d234
 #ifdef __ILP32_OFF32_CFLAGS
c6d234
-# if _POSIX_V7_ILP32_OFF32 == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
c6d234
 #  error "__ILP32_OFF32_CFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_ILP32_OFF32
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
c6d234
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -115,9 +116,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
c6d234
     case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
c6d234
 #ifdef __ILP32_OFFBIG_CFLAGS
c6d234
-# if _POSIX_V7_ILP32_OFFBIG == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
c6d234
 #  error "__ILP32_OFFBIG_CFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_ILP32_OFFBIG
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
c6d234
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -130,9 +131,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
c6d234
     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
c6d234
 #ifdef __LP64_OFF64_CFLAGS
c6d234
-# if _POSIX_V7_LP64_OFF64 == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
c6d234
 #  error "__LP64_OFF64_CFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_LP64_OFF64
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
c6d234
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -145,9 +146,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
c6d234
     case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
c6d234
 #ifdef __ILP32_OFF32_LDFLAGS
c6d234
-# if _POSIX_V7_ILP32_OFF32 == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32 )
c6d234
 #  error "__ILP32_OFF32_LDFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_ILP32_OFF32
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
c6d234
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -160,9 +161,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
c6d234
     case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
c6d234
 #ifdef __ILP32_OFFBIG_LDFLAGS
c6d234
-# if _POSIX_V7_ILP32_OFFBIG == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
c6d234
 #  error "__ILP32_OFFBIG_LDFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_ILP32_OFFBIG
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
c6d234
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -175,9 +176,9 @@ confstr (name, buf, len)
c6d234
     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
c6d234
     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
c6d234
 #ifdef __LP64_OFF64_LDFLAGS
c6d234
-# if _POSIX_V7_LP64_OFF64 == -1
c6d234
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
c6d234
 #  error "__LP64_OFF64_LDFLAGS should not be defined"
c6d234
-# elif !defined _POSIX_V7_LP64_OFF64
c6d234
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
c6d234
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
c6d234
 	break;
c6d234
 # endif
c6d234
@@ -188,7 +189,8 @@ confstr (name, buf, len)
c6d234
 
c6d234
     case _CS_LFS_CFLAGS:
c6d234
     case _CS_LFS_LINTFLAGS:
c6d234
-#if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
c6d234
+#if (CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32) \
c6d234
+     && CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG))
c6d234
 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
c6d234
       /* Signal that we want the new ABI.  */
c6d234
       string = __LFS_CFLAGS;
c6d234
diff --git a/posix/posix-conf-vars.h b/posix/posix-conf-vars.h
c6d234
new file mode 100644
c6d234
index 0000000000000000..6faf29f56b55b7e8
c6d234
--- /dev/null
c6d234
+++ b/posix/posix-conf-vars.h
c6d234
@@ -0,0 +1,48 @@
c6d234
+/* Macros to check if a POSIX configuration variable is defined or set.
c6d234
+
c6d234
+   Copyright (C) 1991-2014 Free Software Foundation, Inc.
c6d234
+   This file is part of the GNU C Library.
c6d234
+
c6d234
+   The GNU C Library is free software; you can redistribute it and/or
c6d234
+   modify it under the terms of the GNU Lesser General Public
c6d234
+   License as published by the Free Software Foundation; either
c6d234
+   version 2.1 of the License, or (at your option) any later version.
c6d234
+
c6d234
+   The GNU C Library is distributed in the hope that it will be useful,
c6d234
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
c6d234
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c6d234
+   Lesser General Public License for more details.
c6d234
+
c6d234
+   You should have received a copy of the GNU Lesser General Public
c6d234
+   License along with the GNU C Library; if not, see
c6d234
+   <http://www.gnu.org/licenses/>.  */
c6d234
+
c6d234
+#ifndef _POSIX_CONF_VARS_H
c6d234
+#define _POSIX_CONF_VARS_H
c6d234
+
c6d234
+/* The script gen-posix-conf-vars.awk generates the header
c6d234
+   posix-conf-vars-def.h from the list file posix-conf-vars.list and defines
c6d234
+   CONF_DEF_* macros for each entry in the list file set to either of
c6d234
+   CONF_DEF_UNDEFINED, CONF_DEF_DEFINED_SET or CONF_DEF_DEFINED_UNSET.  To
c6d234
+   check configuration variables within glibc code, use the configuration macro
c6d234
+   functions instead of checking for definitions of the macros.  */
c6d234
+
c6d234
+#include <posix-conf-vars-def.h>
c6d234
+
c6d234
+#define CONF_DEF_UNDEFINED	1
c6d234
+#define CONF_DEF_DEFINED_SET	2
c6d234
+#define CONF_DEF_DEFINED_UNSET	3
c6d234
+
c6d234
+/* The configuration variable is not defined.  */
c6d234
+#define CONF_IS_UNDEFINED(conf) (CONF_DEF##conf == CONF_DEF_UNDEFINED)
c6d234
+
c6d234
+/* The configuration variable is defined.  It may or may not be set.  */
c6d234
+#define CONF_IS_DEFINED(conf) (CONF_DEF##conf != CONF_DEF_UNDEFINED)
c6d234
+
c6d234
+/* The configuration variable is defined and set.  */
c6d234
+#define CONF_IS_DEFINED_SET(conf) (CONF_DEF##conf == CONF_DEF_DEFINED_SET)
c6d234
+
c6d234
+/* The configuration variable is defined but not set.  */
c6d234
+#define CONF_IS_DEFINED_UNSET(conf) (CONF_DEF##conf == CONF_DEF_DEFINED_UNSET)
c6d234
+
c6d234
+#endif
c6d234
diff --git a/posix/posix-conf-vars.list b/posix/posix-conf-vars.list
c6d234
new file mode 100644
c6d234
index 0000000000000000..8f308c216626c59c
c6d234
--- /dev/null
c6d234
+++ b/posix/posix-conf-vars.list
c6d234
@@ -0,0 +1,22 @@
c6d234
+# Configuration variables identified by getconf.  The heading of each section
c6d234
+# is of the format TYPE PREFIX with the opening curly brace on the same line.
c6d234
+# TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  Variable names are
c6d234
+# put one on each line with a curly brace on its own line ending the section.
c6d234
+
c6d234
+SPEC POSIX {
c6d234
+  V6_ILP32_OFF32
c6d234
+  V6_ILP32_OFFBIG
c6d234
+  V6_LP64_OFF64
c6d234
+  V6_LPBIG_OFFBIG
c6d234
+  V7_ILP32_OFF32
c6d234
+  V7_ILP32_OFFBIG
c6d234
+  V7_LP64_OFF64
c6d234
+  V7_LPBIG_OFFBIG
c6d234
+}
c6d234
+
c6d234
+SPEC XBS5 {
c6d234
+  ILP32_OFF32
c6d234
+  ILP32_OFFBIG
c6d234
+  LP64_OFF64
c6d234
+  LPBIG_OFFBIG
c6d234
+}
c6d234
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
c6d234
index c32ea8acfcfebb78..e820e6dbe3fa3b61 100644
c6d234
--- a/posix/posix-envs.def
c6d234
+++ b/posix/posix-envs.def
c6d234
@@ -42,35 +42,37 @@
c6d234
    defined.  These are called with arguments V5, V6, V7 before and
c6d234
    after the relevant groups of environments.  */
c6d234
 
c6d234
+#include <posix-conf-vars.h>
c6d234
+
c6d234
 START_ENV_GROUP (V7)
c6d234
 
c6d234
-#if _POSIX_V7_ILP32_OFF32 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFF32)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
c6d234
-#elif defined _POSIX_V7_ILP32_OFF32
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFF32)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V7_ILP32_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
c6d234
-#elif defined _POSIX_V7_ILP32_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V7_LP64_OFF64 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LP64_OFF64)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
c6d234
-#elif defined _POSIX_V7_LP64_OFF64
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V7_LP64_OFF64)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V7_LPBIG_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LPBIG_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
c6d234
-#elif defined _POSIX_V7_LPBIG_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V7_LPBIG_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
c6d234
@@ -80,33 +82,33 @@ END_ENV_GROUP (V7)
c6d234
 
c6d234
 START_ENV_GROUP (V6)
c6d234
 
c6d234
-#if _POSIX_V6_ILP32_OFF32 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
c6d234
-#elif defined _POSIX_V6_ILP32_OFF32
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFF32)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V6_ILP32_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
c6d234
-#elif defined _POSIX_V6_ILP32_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V6_LP64_OFF64 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LP64_OFF64)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
c6d234
-#elif defined _POSIX_V6_LP64_OFF64
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V6_LP64_OFF64)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
c6d234
 #endif
c6d234
 
c6d234
-#if _POSIX_V6_LPBIG_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LPBIG_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
c6d234
-#elif defined _POSIX_V6_LPBIG_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_POSIX_V6_LPBIG_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
c6d234
@@ -116,33 +118,33 @@ END_ENV_GROUP (V6)
c6d234
 
c6d234
 START_ENV_GROUP (V5)
c6d234
 
c6d234
-#if _XBS5_ILP32_OFF32 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFF32)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
c6d234
-#elif defined _XBS5_ILP32_OFF32
c6d234
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFF32)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
c6d234
 #endif
c6d234
 
c6d234
-#if _XBS5_ILP32_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
c6d234
-#elif defined _XBS5_ILP32_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
c6d234
 #endif
c6d234
 
c6d234
-#if _XBS5_LP64_OFF64 > 0
c6d234
+#if CONF_IS_DEFINED_SET (_XBS5_LP64_OFF64)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
c6d234
-#elif defined _XBS5_LP64_OFF64
c6d234
+#elif CONF_IS_DEFINED (_XBS5_LP64_OFF64)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
c6d234
 #endif
c6d234
 
c6d234
-#if _XBS5_LPBIG_OFFBIG > 0
c6d234
+#if CONF_IS_DEFINED_SET (_XBS5_LPBIG_OFFBIG)
c6d234
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
c6d234
-#elif defined _XBS5_LPBIG_OFFBIG
c6d234
+#elif CONF_IS_DEFINED (_XBS5_LPBIG_OFFBIG)
c6d234
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
c6d234
 #else
c6d234
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
c6d234
diff --git a/scripts/gen-posix-conf-vars.awk b/scripts/gen-posix-conf-vars.awk
c6d234
new file mode 100644
c6d234
index 0000000000000000..16e20fc1007bd2f5
c6d234
--- /dev/null
c6d234
+++ b/scripts/gen-posix-conf-vars.awk
c6d234
@@ -0,0 +1,61 @@
c6d234
+# Generate posix-conf-vars-def.h with definitions for CONF_DEF{CONF} for each
c6d234
+# configuration variable that getconf or sysconf may use.  Currently it is
c6d234
+# equipped only to generate such macros for specification macros and for
c6d234
+# SYSCONF macros in the _POSIX namespace.
c6d234
+
c6d234
+BEGIN {
c6d234
+  prefix = ""
c6d234
+}
c6d234
+
c6d234
+$1 ~ /^#/ || $0 ~ /^\s*$/ {
c6d234
+  next
c6d234
+}
c6d234
+
c6d234
+# Begin a new prefix.
c6d234
+$NF == "{" {
c6d234
+  type = $1
c6d234
+  prefix = $2
c6d234
+  next
c6d234
+}
c6d234
+
c6d234
+$1 == "}" {
c6d234
+  prefix = ""
c6d234
+  type = ""
c6d234
+  next
c6d234
+}
c6d234
+
c6d234
+{
c6d234
+  if (prefix == "" && type == "" && sc_prefix == "") {
c6d234
+    printf ("Syntax error at %s:%d\n", FILENAME, FNR) > "/dev/stderr"
c6d234
+    exit 1
c6d234
+  }
c6d234
+
c6d234
+  # The prefix and variable names are indices and the value indicates what type
c6d234
+  # of variable it is.  The possible options are:
c6d234
+  # CONFSTR: A configuration string
c6d234
+  # SYSCONF: A numeric value
c6d234
+  # SPEC: A specification
c6d234
+  conf[prefix][$1] = type
c6d234
+}
c6d234
+
c6d234
+END {
c6d234
+  print "/* AUTOGENERATED by gen-posix-conf-vars.awk.  DO NOT EDIT.  */\n"
c6d234
+
c6d234
+  # Generate macros that specify if a sysconf macro is defined and/or set.
c6d234
+  for (p in conf) {
c6d234
+    for (c in conf[p]) {
c6d234
+      printf "#ifndef _%s_%s\n", p, c
c6d234
+      printf "# define CONF_DEF_%s_%s CONF_DEF_UNDEFINED\n", p, c
c6d234
+      # CONFSTR have string values and they are not set or unset.
c6d234
+      if (conf[p][c] != "CONFSTR") {
c6d234
+	printf "#else\n"
c6d234
+	printf "# if _%s_%s > 0\n", p, c
c6d234
+	printf "#  define CONF_DEF_%s_%s CONF_DEF_DEFINED_SET\n", p, c
c6d234
+	printf "# else\n"
c6d234
+	printf "#  define CONF_DEF_%s_%s CONF_DEF_DEFINED_UNSET\n", p, c
c6d234
+	printf "# endif\n"
c6d234
+      }
c6d234
+      printf "#endif\n\n"
c6d234
+    }
c6d234
+  }
c6d234
+}