source: scripts/target-scripts/target-gcc.sh@ 1a625f6

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 1a625f6 was 12ba0a4, checked in by Jim Gifford <clfs@…>, 19 years ago

r565@server (orig r563): ryan | 2005-06-08 01:50:22 -0700
(Log missing during jims svk sync...)


Set AS_FOR_TARGET and LD_FOR_TARGET during gcc-4 builds so configure uses
the cross assembler/linker for feature checks


Will look at whether this works for gcc3.x as well, if so we can drop the
configure patch...



  • Property mode set to 100755
File size: 8.4 KB
Line 
1#!/bin/bash
2
3# cross-lfs target gcc build
4# --------------------------
5# $LastChangedBy$
6# $LastChangedDate$
7# $LastChangedRevision$
8# $HeadURL$
9#
10
11cd ${SRC}
12
13LOG="gcc-target.log"
14
15set_libdirname
16setup_multiarch
17
18if [ "${USE_SYSROOT}" = "Y" ]; then
19 BUILD_PREFIX=/usr
20 INSTALL_PREFIX="${LFS}${BUILD_PREFIX}"
21 INSTALL_OPTIONS="DESTDIR=${LFS}"
22else
23 BUILD_PREFIX=${TGT_TOOLS}
24 INSTALL_PREFIX="${TGT_TOOLS}"
25 INSTALL_OPTIONS=""
26fi
27
28if [ ! "${libdirname}" = "lib" ]; then
29 extra_conf="${extra_conf} --libdir=${BUILD_PREFIX}/${libdirname}"
30fi
31
32if [ "Y" = "${MULTIARCH}" ]; then
33 vendor_os=`echo ${TARGET} | sed 's@\([^-]*\)-\(.*\)@\2@'`
34 case ${TGT_ARCH} in
35 x86_64 )
36 TARGET=x86_64-${vendor_os}
37 ;;
38 sparc64* )
39 TARGET=sparc64-${vendor_os}
40 ;;
41 sparc* )
42 TARGET=sparc64-${vendor_os}
43 ;;
44 powerpc* | ppc* )
45 TARGET=powerpc64-${vendor_os}
46 ;;
47 s390* )
48 TARGET=s390x-${vendor_os}
49 ;;
50 mips*el* )
51 TARGET=mips64el-${vendor_os}
52 ;;
53 * )
54 # TODO: add some error messages etc
55 barf
56 ;;
57 esac
58else
59 # If we are not bi-arch, disable multilib
60 extra_conf="${extra_conf} --enable-multilib=no"
61
62 # HACK: this sets abi to n32 with mips... this should be handled
63 # by the multiarch funcs somehow... and set according to DEFAULTENV
64 case ${TGT_ARCH} in
65 mips* )
66 extra_conf="${extra_conf} --with-abi=${DEFAULTENV}"
67 ;;
68 esac
69fi
70
71# if target has no floating point unit, use soft float
72if [ "${WITHOUT_FPU}" = "Y" ]; then
73 extra_conf="${extra_conf} --with-float=soft"
74fi
75
76unpack_tarball gcc-${GCC_VER}
77
78#3.0 20030427
79# Cannot trust ${GCC_VER} to supply us with the correct
80# gcc version (especially if cvs).
81# Grab it straight from version.c
82cd ${SRC}/${PKGDIR}
83target_gcc_ver=`grep version_string gcc/version.c | \
84 sed 's@.* = \(\|"\)\([0-9.]*\).*@\2@g'`
85# As of gcc4, the above doesn't cut it... check gcc/BASE-VER
86if [ -z "${target_gcc_ver}" -a -f gcc/BASE-VER ]; then
87 target_gcc_ver=`cat gcc/BASE-VER`
88fi
89
90# Apply linkonce patch for gcc (should be fixed come gcc 3.4.4)
91cd ${SRC}/${PKGDIR}
92case ${target_gcc_ver} in
93 3.4.3 ) apply_patch gcc-3.4.3-linkonce-1
94 apply_patch gcc-3.4.0-arm-bigendian
95 apply_patch gcc-3.4.0-arm-nolibfloat
96 apply_patch gcc-3.4.0-arm-lib1asm
97 apply_patch gcc-3.4.3-clean_exec_and_lib_search_paths_when_cross-1
98 ;;
99 4.0.0 ) apply_patch gcc-4.0.0-fix_tree_optimisation_PR21173
100 apply_patch gcc-4.0.0-reload_check_uninitialized_pseudos_PR20973
101 apply_patch gcc-4.0.0-clean_exec_and_lib_search_paths_when_cross-1
102 ;;
103esac
104
105# if we are using gcc-3.4x, set libexecdir to */${libdirname}
106case ${target_gcc_ver} in
107 3.4* | 4.* )
108 extra_conf="${extra_conf} --libexecdir=${BUILD_PREFIX}/${libdirname}"
109 ;;
110esac
111
112# HACK: should at least check if any of these are set first
113ARCH_CFLAGS="${TGT_CFLAGS} ${ARCH_CFLAGS}"
114
115# if target is same as build host, adjust build slightly to avoid running
116# configure checks which we cannot run
117if [ "${TARGET}" = "${BUILD}" ]; then
118 BUILD=`echo ${BUILD} | sed 's@\([_a-zA-Z0-9]*\)\(-[_a-zA-Z0-9]*\)\(.*\)@\1\2x\3@'`
119fi
120
121if [ ! "${USE_SYSROOT}" = "Y" ]; then
122 # LFS style build
123 #----------------
124
125 # source functions for required gcc modifications
126 . ${SCRIPTS}/funcs/cross_gcc-funcs.sh
127
128 # Alter the generated specs file to
129 # o set dynamic linker to be under ${TGT_TOOLS}/lib{,32,64}
130 # o set startfile_prefix_spec so we search for startfiles
131 # under ${TGT_TOOLS}/lib/lib{,32,64}
132 gcc_specs_mod
133
134 # We need to stop cpp using /usr/include as the standard include directory.
135 # This is defined in gcc/cppdefault.c using STANDARD_INCLUDE_DIR
136 cpp_undef_standard_include_dir
137
138 # We need to override SYSTEM_HEADER_DIR so fixincludes only fixes
139 # headers under ${TGT_TOOLS}
140 fixincludes_set_native_system_header_dir
141fi
142
143# HACKS
144#-------
145# This here is a hack. mklibgcc runs the created xgcc for determining
146# the multilib dirs and multilib os dirs. Only problem here is we are
147# cross building a native compiler so we cannot actually run xgcc.
148# We get around this by substituting our cross-compiler here for xgcc,
149# by rights it should have the same specs and produce the expected results
150cd ${SRC}/${PKGDIR}/gcc
151test -f mklibgcc.in-ORIG ||
152 mv mklibgcc.in mklibgcc.in-ORIG
153
154sed "s@\./xgcc@${HST_TOOLS}/bin/${TARGET}-gcc@g" \
155 mklibgcc.in-ORIG > mklibgcc.in
156
157# A similar problem exists when setting MULTILIBS on the environment
158# for the mklibgcc script for generation of libgcc.mk .
159# Here we will force it to use our cross-compiler to produce the results
160# of gcc --print-multi-lib
161sed -i "/MULTILIBS/s@\$(GCC_FOR_TARGET)@${HST_TOOLS}/bin/${TARGET}-gcc@g" \
162 Makefile.in
163
164# When cross-building a target native compiler we run into big issues
165# when determining assembler and linker features required for tls support,
166# ( not to mention which nm, objdump et al to use ) during the configures
167# triggered by make.
168#
169# Gcc's configury does not take into account the fact that when cross
170# building the target native compiler we are _still_ actually cross-compiling.
171# As far as it is concerned during the final configure fragment host = target,
172# it doesn't check whether host = build.
173#
174# It then performs its checks for binutils components as if this was a standard
175# host native build.
176#
177# If a target native binutils was installed before attempting to build gcc
178# it will try to use the created ld, as etc under ${TGT_TOOLS}
179# This obviously will not work, they will not run on the host.
180#
181# If the target native binutils hasn't been built yet it will use the
182# as ld et al from the _build_ host.
183# This quite frankly sucks rocks.
184#
185# The following patch fixes this behaviour, enforcing usage of our
186# cross-tools for configure checks if host = target and host != build
187#
188# NOTE: 20050507 This doesn't appear to be necessary for gcc 4.x :-)
189# This of course will have to be checked thoroughly...
190
191# TODO: Add patches for gcc-3.3 series as well
192cd ${SRC}/${PKGDIR}
193case ${target_gcc_ver} in
194 3.4* )
195 apply_patch gcc-3.4.1-fix_configure_for_target_native
196 ;;
197 4.* )
198 # Testing only... set AS_FOR_TARGET and LD_FOR_TARGET so these are used
199 # for feature checks... will have to check for unintended side effects
200 extra_makeopts="AS_FOR_TARGET=${HST_TOOLS}/bin/${TARGET}-as"
201 extra_makeopts="${extra_makeopts} LD_FOR_TARGET=${HST_TOOLS}/bin/${TARGET}-ld"
202 ;;
203esac
204#
205# End HACKS
206
207test -d ${SRC}/gcc-${GCC_VER}-target &&
208 rm -rf ${SRC}/gcc-${GCC_VER}-target
209
210mkdir -p ${SRC}/gcc-${GCC_VER}-target &&
211cd ${SRC}/gcc-${GCC_VER}-target &&
212
213max_log_init Gcc ${GCC_VER} cross-pt2 ${CONFLOGS} ${LOG}
214#CONFIG_SHELL=/bin/bash \
215CFLAGS="-O2 -pipe" \
216CXXFLAGS="-O2 -pipe" \
217CC="${TARGET}-gcc ${ARCH_CFLAGS}" \
218../${PKGDIR}/configure --prefix=${BUILD_PREFIX} \
219 --build=${BUILD} --host=${TARGET} --target=${TARGET} \
220 --enable-languages=c,c++ --enable-__cxa_atexit \
221 --enable-c99 --enable-long-long --enable-threads=posix \
222 --disable-nls --enable-shared ${extra_conf} \
223 >> ${LOGFILE} 2>&1 &&
224echo " o Configure OK" || barf
225# --enable-languages=c,c++,f77,objc,ada,java,pascal,treelang --enable-__cxa_atexit \
226# --enable-version-specific-runtime-libs \
227
228min_log_init ${BUILDLOGS} &&
229make ${PMFLAGS} BOOT_LDFLAGS="-s" BOOT_CFLAGS="-O2 ${HOST_CFLAGS} -pipe" \
230 STAGE1_CFLAGS="-O2 ${HOST_CFLAGS} -pipe" ${extra_makeopts} all \
231 >> ${LOGFILE} 2>&1 &&
232echo " o Build OK" || barf
233
234min_log_init ${INSTLOGS} &&
235make ${INSTALL_OPTIONS} install \
236 >> ${LOGFILE} 2>&1 &&
237echo " o Install OK" || barf
238
239if [ ! "${USE_SYSROOT}" = "Y" ]; then
240 # Prep new root for target native glibc build
241 libdirs="${libdirname}"
242 if [ "Y" = "${MULTIARCH}" ]; then libdirs="lib lib32 lib64" ; fi
243 for dir in ${libdirs} ; do
244 if [ -d ${TGT_TOOLS}/${dir} ]; then
245 test -d ${LFS}/usr/${dir} || mkdir -p ${LFS}/usr/${dir}
246 ln -sf ../..${TGT_TOOLS}/${dir}/libgcc_s.so.1 \
247 ${LFS}/usr/${dir}/libgcc_s.so.1
248 test -f ${TGT_TOOLS}/${dir}/libgcc_s.so &&
249 ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s.so
250 test -f ${TGT_TOOLS}/${dir}/libgcc_s_32.so &&
251 ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s_32.so
252 test -f ${TGT_TOOLS}/${dir}/libgcc_s_64.so &&
253 ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s_64.so
254 fi
255 done
256fi
257
258test -L ${INSTALL_PREFIX}/bin/cc || ln -s gcc ${INSTALL_PREFIX}/bin/cc
259
Note: See TracBrowser for help on using the repository browser.