aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Akhlaghi <mohammad@akhlaghi.org>2020-01-19 21:15:37 +0000
committerMohammad Akhlaghi <mohammad@akhlaghi.org>2020-01-19 21:15:37 +0000
commitbe73ea496657099603cce7e20413b9c6ee993c94 (patch)
tree095e94362bc5958cc83b955b0d06ce749c6b5312
parent852d996f8f5f1e5e0114dc82aaf33d81c725fb20 (diff)
LIBRARY_PATH is set accordingly based on the host
Until now, GCC wouldn't build properly on Debian-based operating systems because `ld' needed to link with several necessary C library features like `crti.o' and `crtn.o' (this is an `ld' issue, not GCC). The solution is to add the directory containing them to `LIBRARY_PATH'. In the previous commit, I actually searched for these files, but while testing on another system, I noticed that it can be problematic (other architectures may exist). With this commit, we are actually finding the build architecture of the running GCC (which is the same as the `ld') and using that to fix a fixed directory to `LIBRARY_PATH'.
-rwxr-xr-xreproduce/software/bash/configure.sh56
-rw-r--r--reproduce/software/make/basic.mk15
-rw-r--r--reproduce/software/make/high-level.mk7
3 files changed, 58 insertions, 20 deletions
diff --git a/reproduce/software/bash/configure.sh b/reproduce/software/bash/configure.sh
index 0bb0917..c0f8025 100755
--- a/reproduce/software/bash/configure.sh
+++ b/reproduce/software/bash/configure.sh
@@ -848,21 +848,26 @@ fi
# and necessary headers in a non-standard place, and we can't build GCC. So
# we need to find them first. The `sys/cdefs.h' header is also in a
# similarly different location.
-if [ x"$$on_mac_os" = xyes ]; then
- sys_libc_ldflags=;
-else
- sys_libc_ldflags=$(find /lib* /usr/lib*/* -name "libc.a" \
- | sed -e's|/libc\.a||g' \
- | tr ' ' '\n' \
- | awk '{printf "-L%s ", $1}' );
- sys_libc_cppflags=$(echo $sys_libc_ldflags \
- | tr ' ' '\n' \
- | sed -e's|-L|-I|' -e's|/lib/|/include/|' \
- | awk '!/\/lib/{printf "%s ", $1}' );
- #echo "sys_libc_ldflags: $sys_libc_ldflags"
- #echo "sys_libc_cppflags: $sys_libc_cppflags"
- export LDFLAGS="$LDFLAGS $sys_libc_ldflags"
- export CPPFLAGS="$CPPFLAGS $sys_libc_cppflags"
+sys_cppflags=""
+sys_library_path=""
+if [ x"$$on_mac_os" != xyes ]; then
+
+ # Get the GCC target name of the compiler, when its given, special
+ # C libraries and headers are in a sub-directory of the host.
+ gcctarget=$(gcc -v 2>&1 \
+ | tr ' ' '\n' \
+ | awk '/\-\-target/' \
+ | sed -e's/\-\-target=//')
+ if [ x"$gcctarget" != x ]; then
+ if [ -f /usr/lib/$gcctarget/libc.a ]; then
+ export sys_library_path=/usr/lib/$gcctarget
+ export sys_cppflags=-I/usr/include/$gcctarget
+ fi
+ fi
+
+ # For a check:
+ #echo "sys_library_path: $sys_library_path"
+ #echo "sys_cppflags: $sys_cppflags"
fi
@@ -1149,6 +1154,24 @@ fi
+# library_path (ONLY FOR BASIC)
+# -----------------------------
+#
+# During the basic build, we need to include possibly existing special C
+# compiler targets (if they exist).
+export CPPFLAGS="$CPPFLAGS $sys_cppflags"
+if [ x"$sys_library_path" != x ]; then
+ if [ x"$LIBRARY_PATH" = x ]; then
+ export LIBRARY_PATH="$sys_library_path"
+ else
+ export LIBRARY_PATH="$LIBRARY_PATH:$sys_library_path"
+ fi
+fi
+
+
+
+
+
# Build basic software
# --------------------
#
@@ -1160,9 +1183,9 @@ make -f reproduce/software/make/basic.mk \
good_static_libc=$good_static_libc \
rpath_command=$rpath_command \
static_build=$static_build \
+ numthreads=$numthreads \
needs_ldl=$needs_ldl \
on_mac_os=$on_mac_os \
- numthreads=$numthreads \
host_cc=$host_cc \
-j$numthreads
@@ -1184,6 +1207,7 @@ else
fi
.local/bin/env -i HOME=$bdir \
.local/bin/make -f reproduce/software/make/high-level.mk \
+ sys_library_path=$sys_library_path
rpath_command=$rpath_command \
static_build=$static_build \
numthreads=$numthreads \
diff --git a/reproduce/software/make/basic.mk b/reproduce/software/make/basic.mk
index e7d00df..9eba04b 100644
--- a/reproduce/software/make/basic.mk
+++ b/reproduce/software/make/basic.mk
@@ -1174,6 +1174,7 @@ $(ibidir)/binutils: | $(ibidir)/sed \
$(ibidir)/diffutils \
$(ibidir)/coreutils \
$(gcc-prerequisites)
+
if [ x$(on_mac_os) = xyes ]; then \
$(call makelink,as); \
$(call makelink,ar); \
@@ -1183,7 +1184,9 @@ $(ibidir)/binutils: | $(ibidir)/sed \
$(call makelink,ranlib); \
echo "" > $@; \
else \
- $(call gbuild, binutils-$(binutils-version), static) \
+ $(call gbuild, binutils-$(binutils-version), static, \
+ --with-lib-path=$(sys_library_path), \
+ -j$(numthreads) ) \
&& echo "GNU Binutils $(binutils-version)" > $@; \
fi
@@ -1257,15 +1260,19 @@ $(ibidir)/gcc: | $(ibidir)/binutils \
&& make SHELL=$(ibdir)/bash -j$(numthreads) \
&& make SHELL=$(ibdir)/bash install \
&& cd ../.. \
- && rm -rf gcc-$(gcc-version) \
+ && tempname=$(ddir)/gcc-$(gcc-version)/build/rpath-temp-copy \
&& if [ "x$(on_mac_os)" != xyes ]; then \
patchelf --add-needed $(ildir)/libiconv.so $(ildir)/libstdc++.so; \
for f in $$(find $(idir)/libexec/gcc) $(ildir)/libstdc++*; do \
- if ldd $$f &> /dev/null; then \
- patchelf --set-rpath $(ildir) $$f; \
+ isdynamic=$$(file $$f | grep "dynamically linked"); \
+ if [ x"$$isdynamic" != x ]; then \
+ cp $$f $$tempname; \
+ patchelf --set-rpath $(ildir) $$tempname; \
+ mv $$tempname $$f; echo "corrected"; \
fi; \
done; \
fi \
+ && rm -rf gcc-$(gcc-version) \
&& ln -sf $(ibdir)/gcc $(ibdir)/cc \
&& echo "GNU Compiler Collection (GCC) $(gcc-version)" > $@; \
fi
diff --git a/reproduce/software/make/high-level.mk b/reproduce/software/make/high-level.mk
index 735a24a..0afeaba 100644
--- a/reproduce/software/make/high-level.mk
+++ b/reproduce/software/make/high-level.mk
@@ -84,6 +84,13 @@ export PKG_CONFIG_LIBDIR := $(ildir)/pkgconfig
# causes crashs (see bug #56682). So we'll just give it no value at all.
export DYLD_LIBRARY_PATH :=
+# On Debian-based OSs, the basic C libraries are in a target-specific
+# location, not in standard places. Until we merge the building of the C
+# library, it is thus necessary to include this location here. On systems
+# that don't need it, `sys_library_path' is just empty. This is necessary
+# for `ld'.
+export LIBRARY_PATH := $(sys_library_path)
+
# Recipe startup script, see `reproduce/software/bash/bashrc.sh'.
export PROJECT_STATUS := configure_highlevel
export BASH_ENV := $(shell pwd)/reproduce/software/bash/bashrc.sh