OSDN Git Service

Incorporate user-customized <features.h> configuration.
[mingw/mingw-org-wsl.git] / mingwrt / include / _mingw.h.in
index 8328298..b72b853 100644 (file)
@@ -1,4 +1,3 @@
-#ifndef __MINGW_H
 /*
  * _mingw.h
  *
@@ -8,7 +7,7 @@
  * $Id$
  *
  * Written by Mumit Khan  <khan@xraylith.wisc.edu>
- * Copyright (C) 1999, 2001-2011, 2014-2016, MinGW.org Project
+ * Copyright (C) 1999, 2001-2011, 2014-2019, MinGW.org Project
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -31,6 +30,7 @@
  * DEALINGS IN THE SOFTWARE.
  *
  */
+#ifndef __MINGW_H
 #define __MINGW_H
 
 /* In previous versions, __MINGW32_VERSION was expressed as a dotted
  *                                     character which is either included
  *                                     in, or excluded from the group.
  *
- *    __CRT_GLOB_CASE_SENSITIVE__      enable case sensitive matching for
+ * The following options, which may also be specified within _CRT_glob,
+ * are specified in terms of their glob() flags, as defined in <glob.h>
+ *
+ *    GLOB_CASEMATCH                   enable case sensitive matching for
  *                                     globbing patterns; this is default
  *                                     behaviour for POSIX, but because of
  *                                     the case insensitive nature of the
  *                                     appropriate to use case insensitive
  *                                     globbing as the MinGW default.
  *
+ *    GLOB_BRACE                       enable expansion of GNU style brace
+ *                                     delimited expression groups within
+ *                                     the globbing pattern.
+ *
  */
 #define __CRT_GLOB_USE_SINGLE_QUOTE__  0x0010
 #define __CRT_GLOB_BRACKET_GROUPS__    0x0020
-#define __CRT_GLOB_CASE_SENSITIVE__    0x0040
 
 /* The MinGW globbing algorithm uses the ASCII DEL control code as a marker
  * for globbing characters which were embedded within quoted arguments; (the
 #define __CRT_GLOB_ESCAPE_CHAR__       (char)(127)
 
 
+/* Load any user-customized features configuration...
+ */
+#ifdef _MINGW_FEATURES_HEADER
+/* ...from a user-specified, or project-specified alternative file...
+ */
+#include _MINGW_FEATURES_HEADER
+#else
+/* ...or fall back to the default configuration file, (which may,
+ * or may not have been customized).
+ */
+#include <features.h>
+#endif
+
+#ifndef __MINGW_FEATURES__
+/* Regardless of how the preceding features configuration header was
+ * identified, we normally expect that will have defined this, but we
+ * supply this fall-back, just in case it is needed.
+ */
+#define __MINGW_FEATURES__             0ULL
+#endif
+
+/* Define macros to facilitate the user-specified configuration.
+ */
+#define __MINGW_FEATURE_ENABLE__(__FEATURE__) | (__FEATURE__)
+#define __MINGW_FEATURE_IGNORE__(__FEATURE__)
+
+#define __MINGW_FEATURES_BEGIN__       0x0000000000000000ULL
+#define __MINGW_FEATURES_UNSET__       0x0000000000000000ULL
+#define __MINGW_FEATURES_END__
+
 /* Manifest definitions identifying the flag bits, controlling activation
  * of MinGW features, as specified by the user in __MINGW_FEATURES__.
  */
@@ -368,33 +404,62 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
 
 /* Activation of MinGW specific extended features:
  */
-#ifndef __USE_MINGW_ANSI_STDIO
+#ifdef __USE_MINGW_ANSI_STDIO
 /* Users should not set this directly; rather, define one (or more)
  * of the feature test macros (tabulated below), or specify any of the
  * compiler's command line options, (e.g. -posix, -ansi, or -std=c...),
  * which cause _POSIX_SOURCE, or __STRICT_ANSI__ to be defined.
- *
- * We must check this BEFORE we specifiy any implicit _POSIX_C_SOURCE,
+ */
+# warning "Direct definition of __USE_MINGW_ANSI_STDIO is deprecated."
+# pragma message "See <_mingw.h> for preferred feature activation methods."
+
+#else  /* ! defined __USE_MINGW_ANSI_STDIO */
+/* We must check this BEFORE we specifiy any implicit _POSIX_C_SOURCE,
  * otherwise we would always implicitly choose __USE_MINGW_ANSI_STDIO,
  * even if none of these selectors are specified explicitly...
  */
-# if   defined __STRICT_ANSI__  ||  defined _ISOC99_SOURCE \
-   ||  defined _POSIX_SOURCE    ||  defined _POSIX_C_SOURCE \
-   ||  defined _XOPEN_SOURCE    ||  defined _XOPEN_SOURCE_EXTENDED \
-   ||  defined _GNU_SOURCE      ||  defined _BSD_SOURCE \
-   ||  defined _SVID_SOURCE
-   /*
-    * but where any of these source code qualifiers are specified,
-    * then assume ANSI I/O standards are preferred over Microsoft's...
-    */
-#  define __USE_MINGW_ANSI_STDIO    1
+# if  defined __STRICT_ANSI__  ||  defined _SVID_SOURCE            \
+  ||  defined _ISOC99_SOURCE   ||  defined _ISOC11_SOURCE          \
+  ||  defined _POSIX_SOURCE    ||  defined _POSIX_C_SOURCE         \
+  ||  defined _XOPEN_SOURCE    ||  defined _XOPEN_SOURCE_EXTENDED  \
+  ||  defined _GNU_SOURCE      ||  defined _BSD_SOURCE
+  /*
+   * but where any of these source code qualifiers are specified,
+   * then assume ANSI I/O standards are preferred over Microsoft's...
+   */
+#  define __USE_MINGW_ANSI_STDIO   __MINGW_ANSI_STDIO__
 # else
-   /* otherwise use whatever __MINGW_FEATURES__ specifies...
-    */
-#  define __USE_MINGW_ANSI_STDIO    (__MINGW_FEATURES__ & __MINGW_ANSI_STDIO__)
+  /* otherwise use whatever __MINGW_FEATURES__ specifies...
+   */
+#  define __USE_MINGW_ANSI_STDIO  (__MINGW_FEATURES__ & __MINGW_ANSI_STDIO__)
 # endif
 #endif
 
+/* Some applications may define _XOPEN_SOURCE, without assigning any
+ * value to it.  Such usage may have been permitted in early SUS, but
+ * it became obsolete as of SUSv2.  Attempt to detect obsolete usage,
+ * as it makes an effective evaluation of any _XOPEN_SOURCE version
+ * dependency difficult, (without the use of ugly kludges at EVERY
+ * point of reference which attempts a version comparison).
+ */
+#define __paste(prefix,suffix)  prefix ## suffix
+#define __valueless(token)  ((token - 0) == 0) && (__paste(token,10) == 10)
+
+#if defined _XOPEN_SOURCE && __valueless(_XOPEN_SOURCE)
+/* _XOPEN_SOURCE appears to have been defined without its mandatory
+ * value; diagnose this brain-damaged obsolete usage (verbosely)...
+ */
+#warning "_XOPEN_SOURCE seems to have been improperly defined."
+#warning "Mandatory _XOPEN_SOURCE value assignment appears to be missing."
+#warning "Redefining _XOPEN_SOURCE to mitigate obsolete misuse."
+
+/* ...and redefine, emulating implicit behaviour of -D_XOPEN_SOURCE on
+ * the GCC command line, (which DOES assign an implied value of one).
+ */
+#undef  _XOPEN_SOURCE
+#define _XOPEN_SOURCE  1
+#endif
+
 #ifndef _POSIX_C_SOURCE
  /* Users may define this, either directly or indirectly, to explicitly
   * enable a particular level of visibility for the subset of those POSIX
@@ -430,6 +495,14 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
    */
 #  define _POSIX_C_SOURCE  200809L
 
+#  if ! defined _EMULATE_GLIBC && ! defined _POSIX_SOURCE
+   /* For this default case, unless it has already been specified
+    * otherwise, we enable some GNU glibc extensions, which may be
+    * considered as violations of strict POSIX.1 conformance.
+    */
+#   define _EMULATE_GLIBC  1
+#  endif
+
 # elif defined _POSIX_SOURCE
   /* Now formally deprecated by POSIX, some old code may specify this;
    * it will enable a minimal level of POSIX support, in addition to the
@@ -439,22 +512,109 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
 # endif
 #endif
 
+#if _POSIX_C_SOURCE >= 199506L
+/* Conformance with POSIX.1-1996 has been requested; ensure that any
+ * interfaces which have been marked as "obsolescent", from this POSIX
+ * version onwards, will be reported as "deprecated", at point of use.
+ */
+# define __POSIX_1996_DEPRECATED  __MINGW_ATTRIB_DEPRECATED
+#else
+/* POSIX.1-1996 conformance is NOT required; do not object to use of
+ * interfaces which became "obsolescent" in this POSIX version, but
+ * were still fully supported in earlier versions.
+ */
+# define __POSIX_1996_DEPRECATED
+#endif
+
+#if _POSIX_C_SOURCE >= 200112L
+/* Conformance with POSIX.1-2001 has been requested; ensure that any
+ * interfaces which have been marked as "obsolescent", from this POSIX
+ * version onwards, will be reported as "deprecated", at point of use.
+ */
+# define __POSIX_2001_DEPRECATED  __MINGW_ATTRIB_DEPRECATED
+#else
+/* POSIX.1-2001 conformance is NOT required; do not object to use of
+ * interfaces which became "obsolescent" in this POSIX version, but
+ * were still fully supported in earlier versions.
+ */
+# define __POSIX_2001_DEPRECATED
+#endif
+
+#if _POSIX_C_SOURCE >= 200809L
+/* Conformance with POSIX.1-2008 has been requested; ensure that any
+ * interfaces which have been marked as "obsolescent", from this POSIX
+ * version onwards, will be reported as "deprecated", at point of use.
+ */
+# define __POSIX_2008_DEPRECATED  __MINGW_ATTRIB_DEPRECATED
+#else
+/* POSIX.1-2008 conformance is NOT required; do not object to use of
+ * interfaces which became "obsolescent" in this POSIX version, but
+ * were still fully supported in earlier versions.
+ */
+# define __POSIX_2008_DEPRECATED
+#endif
+
 #ifndef _ISOC99_SOURCE
  /* libmingwex.a provides free-standing implementations for many of the
   * functions which were introduced in C99; MinGW headers do not expose
   * prototypes for these, unless this feature test macro is defined, by
-  * the user, or implied by other standards...
+  * the user, or implied by other standards.  We will use a bit-mapped
+  * representation, comprising the bit-wise sum of:
+  *
+  *   0x08  user declared
+  *   0x04  required by C compiler, supporting ISO-C99
+  *   0x02  required by C++ compiler, supporting ISO-C++11
+  *   0x01  required to support recent POSIX.1 features
+  *
+  * to ensure that we can identify the reason for implicit declaration,
+  * (in the event that we may need to discriminate).
   */
-# if __STDC_VERSION__ >= 199901L || _POSIX_C_SOURCE >= 200112L
-#  define _ISOC99_SOURCE  1
+# if __STDC_VERSION__ >= 199901L
+  /* This represents a compiler supporting ISO-C99; enable all potential
+   * use of ISO-C99 features, (to the maximum extent supportable), which
+   * presumably also covers all C++11 and POSIX.1 usage.
+   */
+#  define _ISOC99_SOURCE  0x07
+
+# elif __cplusplus >= 201103L
+  /* C++11 also incorporates many (if not all) of the ISO-C99 features,
+   * which we have guarded by _ISOC99_SOURCE; enable such features, to
+   * the required extent, (which is likely also sufficient to support
+   * any POSIX.1 dependencies).
+   */
+#  define _ISOC99_SOURCE  0x03
+
+# elif _POSIX_C_SOURCE >= 200112L
+  /* This represents the minimum level of ISO-C99 support, which may be
+   * required by POSIX.1, (and which may be no less than full support).
+   */
+#  define _ISOC99_SOURCE  0x01
 # endif
+
+#else
+ /* The the user has explicitly declared a source level dependency on
+  * ISO-C99 features; regardless of how it was declared, redefine it to
+  * ensure that any plausible dependency is covered.
+  */
+# undef _ISOC99_SOURCE
+# define _ISOC99_SOURCE  0x0F
+
+#endif /* _ISOC99_SOURCE */
+
+#if _ISOC99_SOURCE && __cplusplus >= 201103L && __GNUC__ < 6
+ /* Due to a configuration defect in GCC versions prior to GCC-6, when
+  * compiling C++11 code, the ISO-C99 functions may not be incorporated
+  * into the appropriate namespace(s); we may be able to mitigate this,
+  * by ensuring that these GCC configuration macros are defined.
+  */
+# define _GLIBCXX_USE_C99      1
+# define _GLIBCXX_HAVE_WCSTOF  1
 #endif
 
 #if ! defined _MINGW32_SOURCE_EXTENDED && ! defined __STRICT_ANSI__
-/*
- * Enable mingw32 extensions by default, except when __STRICT_ANSI__
- * conformity mode has been enabled.
- */
+ /* Enable mingw32 extensions by default, except when __STRICT_ANSI__
+  * conformity mode has been enabled.
+  */
 # define _MINGW32_SOURCE_EXTENDED  1
 #endif