Bug 708267 - `sys/times.h` issue while cross-compiling on openSUSE
Summary: `sys/times.h` issue while cross-compiling on openSUSE
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Build Process (show other bugs)
Version: master
Hardware: PC Linux
: P2 normal
Assignee: Chris Liddell (chrisl)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-23 20:56 UTC by Werner Lemberg
Modified: 2025-05-22 09:52 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Werner Lemberg 2025-01-23 20:56:24 UTC
[gs 10.03.0]
[MinGW-W64 11.0.1]
[gcc 10.4.0]
[x86_64-w64-mingw32-gcc 13.2.0]
[openSUSE Leap 15.5]

I have a problem with cross-compiling on my openSUSE GNU/Linux box for Windows using mingw.  `configaux.log` contains

```
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TIMES_H 1
```

These values are taken from the standard openSUSE compilation environment.  As a consequence, the generated file `obj/gconfig_.h` file contains

```
#ifndef HAVE_SYS_TIME_H
#define HAVE_SYS_TIME_H 1
#endif

#ifndef HAVE_SYS_TIMES_H
#define HAVE_SYS_TIMES_H 1
#endif
```

On the other hand, `config.log` only contains

```
#define HAVE_SYS_TIME_H 1
```

During compilation of file `base/gp_stdib.c` (with the mingw cross-compiler), file `base/time_.h` gets included, which in turn includes `base/gconfig_.h`.  Due to that the test

```
#if defined(HAVE_SYS_TIMES_H) && HAVE_SYS_TIMES_H == 1
#  include <sys/times.h>
...
```

succeeds, causing the compilation error because mingw does not have `sys/times.h`.

In both passes, the configure script uses `AC_CHECK_HEADERS[... sys/times.h ...]`, which only defines `HAVE_SYS_TIMES_H=1` if the file exists – it does nothing if `sys/times.h` doesn't exist.  AFAICS, this is incorrect: it should actually define `HAVE_SYS_TIMES_H=0` if it does not exist so that `gconfig_.h` doesn't set it to an incorrect value during cross-compilation.

I fixed this locally by adding `GCFLAGS=-DHAVE_SYS_TIMES_H=0"` to the configure script.
Comment 1 Werner Lemberg 2025-01-28 18:29:54 UTC
More analysis showed that some GNU/Linux distributions like Fedora or openSUSE have `/usr/include/sys/times.h`, while others like Ubuntu or Debian have `/usr/include/x86_64-linux-gnu/sys/times.h`.  The problem is that `unix-aux.mak` looks hard-coded into `/usr/include` to produce `gconfig_.h`.  That's wrong - not only for cross-compiling, but also for native compilation.  It only becomes a problem with cross-compilation, though.
Comment 2 Chris Liddell (chrisl) 2025-05-22 08:58:29 UTC
The comment suggests the stuff in unix-aux.mak is a hack for a specific problem or set of problems with specific environments - probably historical at this point, but still, I think it should be benign if we do the "earlier" bits properly.

I'm hoping this resolves the problem:

https://cgit.ghostscript.com/cgi-bin/cgit.cgi/user/chrisl/ghostpdl.git/commit/?id=9b5d2d46361f83f7d5c2baee911e038961d522f1

What do you think Werner?

(Apologies for the long delay... it's been a busy few months)
Comment 3 Werner Lemberg 2025-05-22 09:18:41 UTC
(In reply to Chris Liddell (chrisl) from comment #2)

Looks good to me, thanks!
Comment 4 Chris Liddell (chrisl) 2025-05-22 09:52:21 UTC
(In reply to Werner Lemberg from comment #3)
> (In reply to Chris Liddell (chrisl) from comment #2)
> 
> Looks good to me, thanks!

Thanks Werner.

Pushed:

https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=dcfe10972b9