From 5baaa500439481514ca173db650f7b45e4994b54 Mon Sep 17 00:00:00 2001
From: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Date: Thu, 13 Feb 2020 17:42:10 +0000
Subject: Adding a link to the *crt*.o files in the local install directory

Until now, we defined `LIBRARY_PATH' to fix the problem of the `ld' linker
of Binutils needing several `*crt*.o' files to run. However, some software
(for example ImageMagick) over-write `LIBRARY_PATH', therefore there is no
other way than to put a link to these necessary files in our local build
directory.

With this commit, we fixed the problem by putting a link to the system's
relevant files in the local library directory. This fixed the problem with
ImageMagick. Later, when we build the GNU C Library in the project, we
should remove this step.

This bug reported by Raul Castellanos Sanchez.
---
 reproduce/software/make/basic.mk      | 17 ++++++++++++++++-
 reproduce/software/shell/configure.sh |  1 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/reproduce/software/make/basic.mk b/reproduce/software/make/basic.mk
index 2cad9f9..d8afccd 100644
--- a/reproduce/software/make/basic.mk
+++ b/reproduce/software/make/basic.mk
@@ -1182,6 +1182,15 @@ endif
 # programs (http://savannah.nongnu.org/bugs/?56294). Therefore, we'll set
 # all other basic programs as Binutils prerequisite and GCC (the final
 # basic target) ultimately just depends on Binutils.
+#
+# The `ld' linker of Binutils needs several `*crt*.o' file to run. On some
+# systems these object files aren't installed in standard places. We
+# defined `LIBRARY_PATH' and that fixed the problem for many
+# systems. However, some software (for example ImageMagick) over-write
+# `LIBRARY_PATH', therefore there is no other way than to put a link to
+# these necessary files in our local build directory. IMPORTANT NOTE:
+# later, when we build the GNU C Library in the project, we should remove
+# this step.
 $(ibidir)/binutils: | $(ibidir)/sed \
                       $(ibidir)/wget \
                       $(ibidir)/grep \
@@ -1203,11 +1212,17 @@ $(ibidir)/binutils: | $(ibidir)/sed \
 	  $(call makelink,nm); \
 	  $(call makelink,ps); \
 	  $(call makelink,ranlib); \
-          echo "" > $@; \
+	  echo "" > $@; \
 	else \
 	  $(call gbuild, binutils-$(binutils-version), static, \
 	                 --with-lib-path=$(sys_library_path), \
 	                 -j$(numthreads) ) \
+	  && if ! [ x"$(sys_library_path)" = x ]; then \
+	       for f in $(sys_library_path)/*crt*.o; do \
+	         b=$$($(ibdir)/basename $$f); \
+	         ln -s $$f $(ildir)/$$b; \
+	       done; \
+	     fi \
 	  && echo "GNU Binutils $(binutils-version)" > $@; \
 	fi
 
diff --git a/reproduce/software/shell/configure.sh b/reproduce/software/shell/configure.sh
index 4c6c29a..7b3d939 100755
--- a/reproduce/software/shell/configure.sh
+++ b/reproduce/software/shell/configure.sh
@@ -1208,6 +1208,7 @@ fi
 # tools, but we have to be very portable (and use minimal features in all).
 echo; echo "Building necessary software (if necessary)..."
 make -k -f reproduce/software/make/basic.mk \
+     sys_library_path=$sys_library_path \
      good_static_libc=$good_static_libc \
      rpath_command=$rpath_command \
      static_build=$static_build \
-- 
cgit v1.2.1