1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-06-09 19:20:43 +00:00

Move redefinition of _XOPEN_SOURCE into its own Autoconf macro and header

This makes the main source code look a little cleaner, at the expense of
background magic happening in the configure-generated config.h.  But this
magic was already happening for _GNU_SOURCE, __EXTENSIONS__ and the like.

The only wrinkle is that newer versions of NcursesW cause ./configure to
include "-D_XOPEN_SOURCE=600" as part of the compilation command line--on
systems that support _XOPEN_SOURCE=700.  The AC_DEFINE/AC_DEFINE_UNQUOTED
macros automatically comment out any "#undef" lines in config.h, so the
file lib/xopen_source.h works around this limitation.  It is
automatically included by config.h.
This commit is contained in:
John Zaitseff 2018-08-09 18:05:39 +10:00
parent e578802ac6
commit 2032f6de8a
9 changed files with 133 additions and 11 deletions

2
.gitattributes vendored
View File

@ -6,6 +6,8 @@ Makefile.am ident
/data/trader.svg ident
/doc/trader.* ident
/lib/obsolete-strings.c ident
/lib/xopen_source.h ident
/m4/xopen_source.m4 ident
/po/LINGUAS ident
/po/Makevars ident
/po/POTFILES.in ident

View File

@ -34,4 +34,5 @@ SUBDIRS = lib src po data doc m4
EXTRA_DIST = \
build-aux/bootstrap \
build-aux/msgfmt-desktop \
lib/obsolete-strings.c
lib/obsolete-strings.c \
lib/xopen_source.h

View File

@ -62,6 +62,11 @@ AS_IF([test "x$ac_cv_header_monetary_h" != xyes], [
AC_MSG_ERROR([requires <monetary.h> to exist in the C library])
])
USE_LATEST_XOPEN_SOURCE
AS_IF([test "x$x_cv_latest_xopen_source" = xunknown], [
AC_MSG_ERROR([requires X/Open SUSv4/XPG7 or SUSv3/XPG6])
])
AX_WITH_CURSES
AS_IF([test "x$ax_cv_curses" != xyes || test "x$ax_cv_curses_color" != xyes], [
AC_MSG_ERROR([requires an X/Open-compatible Curses library with colour])

View File

@ -9,6 +9,11 @@ This directory, lib, contains source code as generated by the Gnulib GNU
Portability Library "gnulib-tool" script. See the project web site at
https://www.gnu.org/software/gnulib/ for more information.
The following file is used by xopen_source.m4 to redefine _XOPEN_SOURCE
appropriately. It is not part of the GNU Portability Library:
xopen_source.h
The following file provides translatable strings for obsolete versions of
various libraries. It is not part of the GNU Portability Library:

44
lib/xopen_source.h Normal file
View File

@ -0,0 +1,44 @@
/************************************************************************
* *
* Star Traders: A Game of Interstellar Trading *
* Copyright (C) 1990-2018, John Zaitseff *
* *
************************************************************************/
/*
Author: John Zaitseff <J.Zaitseff@zap.org.au>
$Id$
This file, xopen_source.h, redefines _XOPEN_SOURCE to be the latest
version that is supported by the operating system's C library. It is
used by the Autoconf macro in m4/xopen_source.m4.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
*/
#ifndef included_XOPEN_SOURCE_H
#define included_XOPEN_SOURCE_H
#ifdef LATEST_XOPEN_SOURCE
# if ! defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < LATEST_XOPEN_SOURCE
# undef _XOPEN_SOURCE
# define _XOPEN_SOURCE LATEST_XOPEN_SOURCE
# endif
#endif
#endif /* included_XOPEN_SOURCE_H */

View File

@ -35,4 +35,5 @@ EXTRA_DIST = \
ax_prepend_flag.m4 \
ax_require_defined.m4 \
ax_with_curses.m4 \
gnulib-cache.m4
gnulib-cache.m4 \
xopen_source.m4

View File

@ -7,6 +7,10 @@
This directory, m4, contains M4 macros used by Autoconf.
The following macros are custom-defined for Star Traders:
xopen_source.m4
The following macros are from the Autoconf Archive project, as detailed on
that project's web site, https://www.gnu.org/software/autoconf-archive/:
@ -18,7 +22,7 @@ that project's web site, https://www.gnu.org/software/autoconf-archive/:
ax_with_curses.m4
The following macro was generated by running the GNU Portability Library
"gnulib-tool" with appropriate command line options, as detailed on that
"gnulib-tool" with appropriate command line options, as detailed on that
project's web site, https://www.gnu.org/software/gnulib/:
gnulib-cache.m4

64
m4/xopen_source.m4 Normal file
View File

@ -0,0 +1,64 @@
#########################################################################
# #
# Star Traders: A Game of Interstellar Trading #
# Copyright (C) 1990-2018, John Zaitseff #
# #
#########################################################################
# Author: John Zaitseff <J.Zaitseff@zap.org.au>
# $Id$
#
# This file contains the macro USE_LATEST_XOPEN_SOURCE to determine the
# latest version of _XOPEN_SOURCE supported by the C library. It does
# this by compiling code with various values of that symbol. Once a
# particular value compiles without error, it redefines _XOPEN_SOURCE to
# that value using the auxiliary file <lib/xopen_source.h> and sets
# $x_cv_latest_xopen_source to one of the following values:
#
# 700 - _XOPEN_SOURCE=700 (for SUSv4 / XPG7) was accepted
# 600 - _XOPEN_SOURCE=600 (for SUSv3 / XPG6) was accepted
# unknown - _XOPEN_SOURCE set to above values failed to compile
#
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
AC_DEFUN([_CHECK_XOPEN_SOURCE], [dnl
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
/* Test for $2 */
@%:@define _XOPEN_SOURCE $1
@%:@include <stdio.h>
])], [$3], [$4])
])dnl
AC_DEFUN([USE_LATEST_XOPEN_SOURCE], [dnl
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AH_BOTTOM([
/* Redefine _XOPEN_SOURCE as required */
@%:@include <lib/xopen_source.h>
])
AC_CACHE_CHECK([the latest supported version of _XOPEN_SOURCE],
[x_cv_latest_xopen_source], [
x_cv_latest_xopen_source=unknown
_CHECK_XOPEN_SOURCE([700], [SUSv4 / XPG7], [
x_cv_latest_xopen_source=700
], [_CHECK_XOPEN_SOURCE([600], [SUSv3 / XPG6], [
x_cv_latest_xopen_source=600
])])
])
AS_IF([test "x$x_cv_latest_xopen_source" != xunknown], [dnl
AC_DEFINE_UNQUOTED([LATEST_XOPEN_SOURCE],
[$x_cv_latest_xopen_source],
[Define to the latest version of _XOPEN_SOURCE that is supported.])
])
])dnl USE_LATEST_XOPEN_SOURCE

View File

@ -43,14 +43,10 @@
* System header files *
************************************************************************/
#if ! defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 700
# undef _XOPEN_SOURCE
# if defined(__sun) && defined(__SVR4)
# define _XOPEN_SOURCE 600 // Use SUSv3 on SunOS 5.x
# else
# define _XOPEN_SOURCE 700 // Use SUSv4 everywhere else
# endif
#endif
/* Note that the configure-generated "config.h" defines feature test
macros as required by the compiler or operating system C library. In
particular, it defines _XOPEN_SOURCE, _GNU_SOURCE, __EXTENSIONS__ and
similar symbols to appropriate values. */
// Headers defined by ISO/IEC 9899:1999 (C99)