Bug 115416 - [13/14/15 regression] Setting --includedir to a nonexistent directory causes a build error since r13-5490-g59e4c98173a79f
Summary: [13/14/15 regression] Setting --includedir to a nonexistent directory causes ...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 14.1.0
: P3 normal
Target Milestone: 13.4
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2024-06-10 15:07 UTC by Marcus Calhoun-Lopez
Modified: 2024-06-16 09:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-06-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Calhoun-Lopez 2024-06-10 15:07:29 UTC
A change made earlier this year[1] is causing troubles on the MacPorts build of GCC.
MacPorts sets `--includedir=` to a directory that does not exist until after the build is complete.
Since  `@includedir@` is not `$(prefix)/include` and `$(prefix)/include` does not exist during the build, the Makefile exits[2].

[1] https://gcc.gnu.org/g:59e4c98173a79fcaa2c33253261409f38856c384
[2] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/Makefile.in;h=6001c9e3b559a90291b4d571c2410db6da4ede94;hb=59e4c98173a79fcaa2c33253261409f38856c384#l3273
Comment 1 Sam James 2024-06-10 15:36:12 UTC
I think we've hit this too in Gentoo but I hadn't reported it yet as I hadn't investigated, so I just worked around it.
Comment 2 YunQiang Su 2024-06-10 16:09:49 UTC
Can you give me the configure command, so that I can have a test.
Comment 3 YunQiang Su 2024-06-10 17:01:27 UTC
Since it doesn't exist, why use --includedir with it?
Anyway, so, maybe we should detect the existence of this dir.
Can you have a try of this patch?

--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -560,10 +560,11 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
 # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
 NATIVE_SYSTEM_HEADER_DIR = @NATIVE_SYSTEM_HEADER_DIR@
 # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
-ifeq (@includedir@,$(prefix)/include)
-  CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
-else
-  CROSS_SYSTEM_HEADER_DIR = @includedir@
+CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
+ifneq (@includedir@,$(prefix)/include)
+  ifneq (,$(wildcard @includedir@))
+    CROSS_SYSTEM_HEADER_DIR = @includedir@
+  endif
 endif
Comment 4 Marcus Calhoun-Lopez 2024-06-10 17:27:48 UTC
(In reply to YunQiang Su from comment #2)
> Can you give me the configure command, so that I can have a test.

The pertinent part of the configure command is
`configure --prefix=/opt/local --includedir=/opt/local/include/gcc --libdir=/opt/local/lib/libgcc`
Comment 5 Marcus Calhoun-Lopez 2024-06-10 17:32:33 UTC
(In reply to YunQiang Su from comment #3)
> Since it doesn't exist, why use --includedir with it?

/opt/local/include/gcc is where the header files will be installed after the build, so there is no reason for it to exist before the build.

> Anyway, so, maybe we should detect the existence of this dir.
> Can you have a try of this patch?
> 
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -560,10 +560,11 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
>  # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
>  NATIVE_SYSTEM_HEADER_DIR = @NATIVE_SYSTEM_HEADER_DIR@
>  # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
> -ifeq (@includedir@,$(prefix)/include)
> -  CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
> -else
> -  CROSS_SYSTEM_HEADER_DIR = @includedir@
> +CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
> +ifneq (@includedir@,$(prefix)/include)
> +  ifneq (,$(wildcard @includedir@))
> +    CROSS_SYSTEM_HEADER_DIR = @includedir@
> +  endif
>  endif

Yes, this seems to work.
Thank you very much.
Comment 6 YunQiang Su 2024-06-10 17:41:21 UTC
(In reply to Marcus Calhoun-Lopez from comment #5)
> (In reply to YunQiang Su from comment #3)
> > Since it doesn't exist, why use --includedir with it?
> 
> /opt/local/include/gcc is where the header files will be installed after the
> build, so there is no reason for it to exist before the build.
> 

Normally, we build gcc for 1st stage with/without --includedir, 
and then build libc with 1st stage gcc, and install the libc into the destination.
Then we build gcc stage2 with --includedir.


Ohh, in fact that I am worrying that both you and I have a mistake: the --includedir may be used for host instead of target.

Should we introduce a new build-time option?

Background: I add this patch due to Debian's cross toolchain install headers into /usr/<triple>/include
instead of /usr/<triple>/sys-include
Comment 7 YunQiang Su 2024-06-11 09:10:29 UTC
Maybe this patch is better

--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -560,11 +560,7 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
 # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
 NATIVE_SYSTEM_HEADER_DIR = @NATIVE_SYSTEM_HEADER_DIR@
 # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
-ifeq (@includedir@,$(prefix)/include)
-  CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
-else
-  CROSS_SYSTEM_HEADER_DIR = @includedir@
-endif
+CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
 
 # autoconf sets SYSTEM_HEADER_DIR to one of the above.
 # Purge it of unnecessary internal relative paths
@@ -581,7 +577,10 @@ BUILD_SYSTEM_HEADER_DIR = `echo @BUILD_SYSTEM_HEADER_DIR@ | sed -e :a -e 's,[^/]
 STMP_FIXINC = @STMP_FIXINC@
 
 # Test to see whether <limits.h> exists in the system header files.
-LIMITS_H_TEST = [ -f $(BUILD_SYSTEM_HEADER_DIR)/limits.h ]
+LIMITS_H_TEST = headdir=$(BUILD_SYSTEM_HEADER_DIR) && \
+               headdir_sys=`echo $$headdir | grep '/sys-include$$'` && \
+               headdir_nosys=`echo $$headdir | sed 's/sys-include/include/'` && \
+               [ -f $$headdir/limits.h -o -n $$headdir_sys -a -f "$$headdir_nosys/limits.h" ]
 
 # Directory for prefix to system directories, for
 # each of $(system_prefix)/usr/include, $(system_prefix)/usr/lib, etc.


Background: For cross/no-with-sysroot, the BUILD_SYSTEM_HEADER_DIR value will be `$(gcc_tooldir)/sys-include`.  Here, `sys-include` is used by `--with-headers` option.


So let's detect $(gcc_tooldir)/include too.