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