Bug 708267 - `sys/times.h` issue while cross-compiling on openSUSE
Summary: `sys/times.h` issue while cross-compiling on openSUSE
Status: UNCONFIRMED
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-02-12 14:37 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.