Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dlg compile on Solaris 10 and 11 #9

Closed
wants to merge 1 commit into from

Conversation

lemzwerg
Copy link
Contributor

@lemzwerg lemzwerg commented Sep 2, 2021

Without the adjusted settings, gcc 5.5 aborts with

Compiler or options invalid for pre-UNIX 03 X/Open
applications and pre-2001 POSIX applications

Without the adjusted settings, gcc 5.5 aborts with

    Compiler or options invalid for pre-UNIX 03 X/Open
    applications and pre-2001 POSIX applications
@lemzwerg
Copy link
Contributor Author

lemzwerg commented Sep 2, 2021

... not sure whether you accept this minor uglification, but there still are some Solaris hosts in use. I would have to patch FreeType locally (since we now use dlg), and I would be glad if I could avoid that.

@lemzwerg
Copy link
Contributor Author

lemzwerg commented Sep 2, 2021

BTW, you can find the following in /usr/include/sys/feature_tests.h on Solaris 10.

It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
using c99. The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
or a POSIX.1-2001 application with anything other than a c99 or later
compiler.

@@ -2,7 +2,13 @@
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt

#define _XOPEN_SOURCE
#if defined(__sun)
#define _XOPEN_SOURCE 600
Copy link

@mojca mojca Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I'm not really familiar with this at all and I'm not aware about implications, so I leave it up to the developers.
But maybe defining #define _XOPEN_SOURCE 600 unconditionally for all platforms would also be valid?

Also, I don't really need the _XPG6 definition in order to compile the code, just adding 600 was sufficient, see my other comment in the thread.

(Akira wrote the patches by following this advice without having access to Solaris.)

@mojca
Copy link

mojca commented Sep 3, 2021

Here's a full quote from /usr/include/sys/feature_tests.h. You can see that setting _XOPEN_SOURCE to 600 will automatically define _XPG6 as well. In any case, while I didn't test the hypothesis, the error most likely only occurs when compiling with the -std=c99 flag. (I suspect the code would also have worked out of the box if _POSIX_C_SOURCE was set to 200112L, but Solaris headers were probably written before that newer standard 200809L came into existence.)

/*
 * Use of _XOPEN_SOURCE
 *
 * The following X/Open specifications are supported:
 *
 * X/Open Portability Guide, Issue 3 (XPG3)
 * X/Open CAE Specification, Issue 4 (XPG4)
 * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
 * X/Open CAE Specification, Issue 5 (XPG5)
 * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
 *    IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
 *
 * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
 * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
 *     Version 2 (SUSv2)
 * XPG6 is the result of a merge of the X/Open and POSIX specifications
 *     and as such is also referred to as IEEE Std. 1003.1-2001 in
 *     addition to UNIX 03 and SUSv3.
 *
 * When writing a conforming X/Open application, as per the specification
 * requirements, the appropriate feature test macros must be defined at
 * compile time. These are as follows. For more info, see standards(5).
 *
 * Feature Test Macro                                Specification
 * ------------------------------------------------  -------------
 * _XOPEN_SOURCE                                         XPG3
 * _XOPEN_SOURCE && _XOPEN_VERSION = 4                   XPG4
 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1           XPG4v2
 * _XOPEN_SOURCE = 500                                   XPG5
 * _XOPEN_SOURCE = 600  (or POSIX_C_SOURCE=200112L)      XPG6
 *
 * In order to simplify the guards within the headers, the following
 * implementation private test macros have been created. Applications
 * must NOT use these private test macros as unexpected results will
 * occur.
 *
 * Note that in general, the use of these private macros is cumulative.
 * For example, the use of _XPG3 with no other restrictions on the X/Open
 * namespace will make the symbols visible for XPG3 through XPG6
 * compilation environments. The use of _XPG4_2 with no other X/Open
 * namespace restrictions indicates that the symbols were introduced in
 * XPG4v2 and are therefore visible for XPG4v2 through XPG6 compilation
 * environments, but not for XPG3 or XPG4 compilation environments.
 *
 * _XPG3    X/Open Portability Guide, Issue 3 (XPG3)
 * _XPG4    X/Open CAE Specification, Issue 4 (XPG4)
 * _XPG4_2  X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
 * _XPG5    X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
 * _XPG6    Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
 */

/* X/Open Portability Guide, Issue 3 */
#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
        (_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
#define _XPG3
/* X/Open CAE Specification, Issue 4 */
#elif   (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
#define _XPG4
#define _XPG3
/* X/Open CAE Specification, Issue 4, Version 2 */
#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
#define _XPG4_2
#define _XPG4
#define _XPG3
/* X/Open CAE Specification, Issue 5 */
#elif   (_XOPEN_SOURCE - 0 == 500)
#define _XPG5
#define _XPG4_2
#define _XPG4
#define _XPG3
#undef  _POSIX_C_SOURCE
#define _POSIX_C_SOURCE                 199506L
/* Open Group Technical Standard , Issue 6 */
#elif   (_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
#define _XPG6
#define _XPG5
#define _XPG4_2
#define _XPG4
#define _XPG3
#undef  _POSIX_C_SOURCE
#define _POSIX_C_SOURCE                 200112L
#undef  _XOPEN_SOURCE
#define _XOPEN_SOURCE                   600
#endif

/*
 * It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
 * using c99.  The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
 * and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
 * or a POSIX.1-2001 application with anything other than a c99 or later
 * compiler.  Therefore, we force an error in both cases.
 */
#if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
        and pre-2001 POSIX applications"
#elif !defined(_STDC_C99) && \
        (defined(__XOPEN_OR_POSIX) && defined(_XPG6))
#error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
        require the use of c99"
#endif

@apodtele
Copy link

apodtele commented Sep 3, 2021

This is not specific to Solaris. These macros should have values everywhere.

nyorain added a commit that referenced this pull request Sep 6, 2021
This should fix compilation on Solaris and seems like the right
thing to do everywhere.
See #9 for discussion.
Thanks to @lemzwerg, @apodtele and @mojca for their input.
@nyorain
Copy link
Owner

nyorain commented Sep 6, 2021

Thanks for the input everyone! I've added #define _XOPEN_SOURCE 600 to the source on master, it seems to be the right thing to do anyways. @lemzwerg could you confirm that this fixes the issue? Otherwise, I'm not opposed to merging your fix.

@mojca
Copy link

mojca commented Sep 7, 2021

Thank you. I can confirm that it works on Solaris 10 (and some random combination of macOS/clang).

@mojca
Copy link

mojca commented Sep 8, 2021

It also builds everywhere on our build farm: OpenBSD (6.8, 6.9 × i686, amd64), FreeBSD 11.4 (i686, amd64), Linux (Debian 9, Debian 10; i686, x86_64, arm, aarch64), macOS (10.6 x86_64, 11 arm64), Solaris 10 (i686, x86_64, sparc).

I guess this may safely be closed.

@apodtele
Copy link

apodtele commented Sep 8, 2021

Do you know why _POSIX_C_SOURCE is set so high? I tried 200112L and even 199506L - both seem to compile fine.

@nyorain
Copy link
Owner

nyorain commented Feb 24, 2022

Sorry, completely forget about this. @apodtele _POSIX_C_SOURCE was just set to what I'm used to. If this ever becomes a problem for someone and we want to support that usecase we will set it to a lower value. Closing this now.

@nyorain nyorain closed this Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants