mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

426 lines
14 KiB

  1. #!/bin/bash
  2. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  3. #
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. # Please add additional copyright information _after_ the line containing
  6. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  7. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  8. #
  9. # ROCK Linux: rock-src/package/base/gcc/gcc.conf
  10. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version. A copy of the GNU General Public
  16. # License can be found at Documentation/COPYING.
  17. #
  18. # Many people helped and are helping developing ROCK Linux. Please
  19. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  20. # file for details.
  21. #
  22. # --- ROCK-COPYRIGHT-NOTE-END ---
  23. pkg_gcc_version=${xpkg#gcc}
  24. pkg_gcc_target=${arch_target}
  25. pkg_gcc_cross=""
  26. case "$xpkg" in
  27. gcc?-cross-*|gcc??-cross-*)
  28. pkg_gcc_cross="${xpkg#gcc*-cross-}"
  29. pkg_gcc_version=${pkg_gcc_version%-cross-*}
  30. pkg_gcc_target="${pkg_gcc_cross}-unknown-linux-gnu"
  31. prefix=usr
  32. set_confopt
  33. var_append confopt " " "--target=$pkg_gcc_target"
  34. echo_status "Preparing to build a cross-gcc package for $pkg_gcc_cross."
  35. var_append INSTALL_WRAPPER_FILTER "|" 'sed -r "\,(/share/(info|locale)|/usr/(man|info)), d"'
  36. ;;
  37. gcc?|gcc??)
  38. ;;
  39. *)
  40. echo_error "Not supported $pkg package name: $xpkg"
  41. exit 1
  42. ;;
  43. esac
  44. case "$pkg_gcc_version" in
  45. 34|4*)
  46. gcc_lib_dir="gcc/${pkg_gcc_target}/${ver%%-*}"
  47. ;;
  48. *)
  49. gcc_lib_dir="gcc-lib/${pkg_gcc_target}/${ver%%-*}"
  50. ;;
  51. esac
  52. patchfiles="`ls $patchfiles $confdir/gcc$pkg_gcc_version/*.patch \
  53. $confdir/gcc$pkg_gcc_version/*.patch.$arch 2>/dev/null | tr '\n' ' '`"
  54. if [ $stagelevel -le 1 ]; then
  55. patchfiles="`ls $patchfiles $confdir/gcc$pkg_gcc_version/*.patch.cross \
  56. $confdir/gcc$pkg_gcc_version/*.patch.cross.$arch 2>/dev/null | tr '\n' ' '`"
  57. fi
  58. if [ "$pkg_gcc_cross" ] ; then
  59. configprefix=""
  60. confopt="--prefix=$root/$prefix \
  61. --host=$arch_target --target=$pkg_gcc_target \
  62. --disable-nls --disable-multilib"
  63. # A gcc with shared libraries needs at least this file from glibc.
  64. if [ ! -e $root/$prefix/$pkg_gcc_target/lib/crti.o ] ; then
  65. echo_status "Building only static gcc because there is no cross-glibc (yet)."
  66. var_append confopt " " "--disable-shared --enable-languages=c"
  67. if [ $pkg_gcc_version -ge 43 ]; then
  68. makeopt="all-gcc all-target-libgcc"
  69. makeinstopt="install-gcc install-target-libgcc"
  70. else
  71. makeopt="all-gcc"
  72. makeinstopt="install-gcc"
  73. fi
  74. else
  75. var_append confopt " " "--enable-shared --enable-languages=c,c++"
  76. makeopt=""
  77. makeinstopt="install"
  78. fi
  79. elif [ $stagelevel -eq 0 ] ; then
  80. configprefix=""
  81. # --build=${CLFS_HOST} added for gcc 4.3 in stages 0 and 1. This avoids
  82. # cross-building the (cross-)compiler, which does not work here, and
  83. # builds the compiler natively. Previous gcc versions (4.2.4 at least)
  84. # seem to assume that build == host if --host is set but --build is not.
  85. # gcc 4.3.1 configure warns about this with:
  86. # WARNING: If you wanted to set the --build type, don't use --host.
  87. # If a cross compiler is detected then cross compile mode will be used.
  88. confopt="--prefix=${CLFS}/$cross_tools \
  89. --build=${CLFS_HOST} \
  90. --host=${CLFS_HOST} --target=${CLFS_TARGET} \$extraconfopt"
  91. var_append extraconfopt " " " \
  92. --with-sysroot=${CLFS} --disable-nls --disable-shared \
  93. --enable-languages=c"
  94. if [ $pkg_gcc_version -ge 43 ]; then
  95. makeopt="all-gcc all-target-libgcc"
  96. makeinstopt="install-gcc install-target-libgcc"
  97. else
  98. makeopt="all-gcc"
  99. makeinstopt="install-gcc"
  100. fi
  101. elif [ $stagelevel -eq 1 ] ; then
  102. configprefix=""
  103. confopt="--prefix=${CLFS}/$cross_tools \
  104. --build=${CLFS_HOST} \
  105. --host=${CLFS_HOST} --target=${CLFS_TARGET} \$extraconfopt"
  106. var_append extraconfopt " " " \
  107. --with-sysroot=${CLFS} --disable-nls --enable-shared \
  108. --enable-languages=\$languages --enable-__cxa_atexit \
  109. --enable-c99 --enable-long-long --enable-threads=posix"
  110. makeopt=""
  111. makeinstopt="install"
  112. elif [ $stagelevel -ge 2 ] ; then
  113. var_append extraconfopt " " " \
  114. --enable-shared \
  115. --enable-__cxa_atexit \
  116. --enable-c99 --enable-long-long --enable-threads=posix \
  117. --enable-clocale=gnu"
  118. if [ $stagelevel -eq 2 ] ; then
  119. var_append extraconfopt " " "--enable-languages=\$languages \
  120. --disable-libstdcxx-pch"
  121. # Help configure find the right target tools, esp. important in
  122. # native builds. Without this the tools installed on the build system
  123. # might be used instead of the ones built in stage 0 and 1, and
  124. # cause build errors.
  125. export CC_FOR_TARGET=$pkg_gcc_target-gcc
  126. export CXX_FOR_TARGET=$pkg_gcc_target-g++
  127. export GCC_FOR_TARGET=$pkg_gcc_target-gcc
  128. export GCJ_FOR_TARGET=$pkg_gcc_target-gcj
  129. export GFORTRAN_FOR_TARGET=$pkg_gcc_target-gfortran
  130. export AS_FOR_TARGET=$pkg_gcc_target-as
  131. export AR_FOR_TARGET=$pkg_gcc_target-ar
  132. export LD_FOR_TARGET=$pkg_gcc_target-ld
  133. export NM_FOR_TARGET=$pkg_gcc_target-nm
  134. export OBJDUMP_FOR_TARGET=$pkg_gcc_target-objdump
  135. export RANLIB_FOR_TARGET=$pkg_gcc_target-ranlib
  136. export STRIP_FOR_TARGET=$pkg_gcc_target-strip
  137. # The configure option
  138. # var_append extraconfopt " " "--with-build-time-tools=$root/$cross_tools/$pkg_gcc_target/bin"
  139. # does not work because $builddir/$cross_tools/$pkg_gcc_target/bin/gcc can't find cc1
  140. # (but $builddir/$cross_tools/bin/$pkg_gcc_target-gcc can).
  141. else
  142. var_append extraconfopt ' ' '--enable-languages=$languages'
  143. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_BOOTSTRAP"
  144. if [ "${!x}" = 0 ] ; then
  145. var_append extraconfopt ' ' '--disable-bootstrap'
  146. else
  147. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_PROFILED"
  148. if [ "${!x}" = 1 ] ; then
  149. var_append makeopt ' ' "GCJFLAGS=\"\$CXXFLAGS\" \
  150. profiledbootstrap"
  151. fi
  152. fi
  153. fi
  154. # We install binaries, info files and man pages in temporary
  155. # directories so we can rename them (adding version suffix) before
  156. # moving them to their final directories.
  157. #
  158. var_append makeopt " " "prefix=/$prefix"
  159. for x in bin info man data ; do
  160. mkdir -p $dummydir/inst_$x
  161. eval "${x}dir=$dummydir/inst_$x"
  162. done
  163. # libstdc++ locales are not installed to the $datadir without this.
  164. var_append INSTALL_WRAPPER_FILTER "|" "sed -e \
  165. 's,$root/$prefix/share\(/locale/.*/libstdc++.mo\),$dummydir/inst_data\1,'"
  166. var_append extraconfopt " " "--enable-version-specific-runtime-libs"
  167. fi
  168. if [ "$ROCKCFG_MULTILIB" = 0 ] ; then
  169. var_append extraconfopt " " "--disable-multilib"
  170. fi
  171. custmain="custmain"
  172. custmain () {
  173. # Don't install libiberty, use the one from binutils instead.
  174. cp libiberty/Makefile.in{,.orig}
  175. sed 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in.orig > \
  176. libiberty/Makefile.in
  177. if [ $stagelevel -eq 2 ] ; then
  178. cp gcc/gccbug.in{,.orig}
  179. sed 's/@have_mktemp_command@/yes/' gcc/gccbug.in.orig > gcc/gccbug.in
  180. cp gcc/Makefile.in{,.orig}
  181. sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
  182. fi
  183. languages="c"
  184. while read lang ; do
  185. x=""
  186. case $lang in
  187. c++) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_CPP"
  188. ;;
  189. esac
  190. if [ $stagelevel -ge 3 ] ; then
  191. case $lang in
  192. ada) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_ADA"
  193. ;;
  194. f77|f95|fortran)
  195. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_FORTRAN"
  196. ;;
  197. java) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_JAVA"
  198. ;;
  199. objc) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_OBJC"
  200. ;;
  201. obj-c++)
  202. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_OBJCPP"
  203. ;;
  204. esac
  205. fi
  206. if [ "${!x}" = 1 ] ; then
  207. var_append languages "," "$lang"
  208. fi
  209. done <<< "$( sed -nr 's,^language="(.*)",\1,p' gcc/*/config-lang.in )"
  210. mkdir -v ../objdir ; cd ../objdir
  211. eval echo $configprefix ../gcc-*/configure $( eval echo $confopt )
  212. eval $configprefix ../gcc-*/configure $( eval echo $confopt )
  213. eval make $makeopt
  214. if [ "$ROCKCFG_DO_CHECK" = 1 -a $stagelevel -ge 4 ] ; then
  215. make -k check || true
  216. ../gcc-*/contrib/test_summary
  217. fi
  218. eval make $makeinstopt
  219. if [ $stagelevel -eq 0 -a $pkg_gcc_version -ge 43 ]; then
  220. cp -v $root/$prefix/lib/$gcc_lib_dir/include-fixed/*.h $root/$prefix/lib/$gcc_lib_dir/include/
  221. fi
  222. if [ $stagelevel -ge 2 -a -z "$pkg_gcc_cross" ] ; then
  223. # Rename and install binaries
  224. #
  225. cd $dummydir/inst_bin ; mkdir -p $root/$prefix/bin
  226. for y in c++ c++filt g++ cpp f77 g77 gfortran gcc gcov ; do
  227. for x in $y ${pkg_gcc_target}-$y ; do
  228. if [ -f "$x" ] ; then
  229. mv -v $x $root/$prefix/bin/${x}-${pkg_gcc_version}
  230. fi
  231. done
  232. done
  233. # Rename and install info-files
  234. #
  235. cd $dummydir/inst_info ; mkdir -p $root/$prefix/info
  236. for x in * ; do
  237. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  238. fn=$( echo $x | sed "s,\([a-z0-9]*\),\1-${pkg_gcc_version}," )
  239. infoname=$( echo $x | sed "s,\([a-z0-9]*\).*,\1," )
  240. echo "$x -> $root/$prefix/info/$fn"
  241. sed "s,$infoname.info,$infoname-${pkg_gcc_version}.info," < $x \
  242. > $root/$prefix/info/$fn
  243. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  244. cp -v $x $root/$prefix/info/$x
  245. fi
  246. true
  247. done
  248. # Rename and install man-pages
  249. #
  250. cd $dummydir/inst_man/man1
  251. mkdir -p $root/$prefix/man/man1
  252. for x in * ; do
  253. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  254. mv -v $x $root/$prefix/man/man1/${x%.1}-${pkg_gcc_version}.1
  255. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  256. ln -sf ${x%.1}-${pkg_gcc_version}.1 $root/$prefix/man/man1/$x
  257. fi
  258. true
  259. done
  260. cd $dummydir/inst_man/man7
  261. mkdir -p $root/$prefix/man/man7
  262. for x in * ; do
  263. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  264. mv -v $x $root/$prefix/man/man7/${x%.1}-${pkg_gcc_version}.7
  265. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  266. ln -sf ${x%.1}-${pkg_gcc_version}.7 $root/$prefix/man/man7/$x
  267. fi
  268. true
  269. done
  270. # Rename and install locales
  271. #
  272. if [ -d "$dummydir/inst_data/locale" ] ; then
  273. cd $dummydir/inst_data/locale
  274. for x in */LC_MESSAGES/*.mo ; do
  275. [ ! -f "$x" ] && continue # e.g. if $x becomes '*' somehow
  276. y="$root/$prefix/share/locale/$x"
  277. y="${y%.mo}-${pkg_gcc_version}.mo"
  278. mkdir -p ${y%/*}
  279. echo "$x -> $y"
  280. mv $x $y
  281. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  282. echo "symlink $x -> $y"
  283. ln -svf ${y##*/} $root/$prefix/share/locale/$x
  284. fi
  285. true
  286. done
  287. fi
  288. # Create various symlinks for cc, c++, cpp and f77.
  289. #
  290. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  291. create_links gcc cpp gcov
  292. rm -f $root/$prefix/bin/cc
  293. if [ "$ROCKCFG_DIETLIBC_ALL" = 1 ]; then
  294. cat <<- 'EOT' > $root/$prefix/bin/cc
  295. #!/bin/sh
  296. exec diet gcc "$@"
  297. EOT
  298. chmod +x $root/$prefix/bin/cc
  299. else
  300. ln -svf gcc $root/$prefix/bin/cc
  301. fi
  302. ln -vsf ../$prefix/bin/cpp $root/lib/cpp
  303. fi
  304. ln -sf gcc-${pkg_gcc_version} $root/$prefix/bin/kcc-${pkg_gcc_version}
  305. if [ $ROCKCFG_DEFAULT_KCC = $xpkg ] ; then
  306. ln -vsf gcc-${pkg_gcc_version} $root/$prefix/bin/kcc
  307. fi
  308. if [ $ROCKCFG_DEFAULT_CXX = $xpkg ] ; then
  309. create_links c++ c++filt g++
  310. cp -a $confdir/g++-autopch.sh $root/$prefix/bin/g++-autopch
  311. chmod +x $root/$prefix/bin/g++-autopch
  312. fi
  313. if [ $ROCKCFG_DEFAULT_F77 = $xpkg ] ; then
  314. create_links g77
  315. if [ -f $root/$prefix/bin/g77 ] ; then
  316. rm -vf $root/$prefix/bin/f77
  317. ln -vsf g77 $root/$prefix/bin/f77
  318. fi
  319. fi
  320. if [ $ROCKCFG_DEFAULT_F95 = $xpkg ] ; then
  321. create_links gfortran
  322. fi
  323. # Inject our default optimisation options so when the user calls
  324. # gcc/g++ they match the ones used to precompile the headers ...
  325. # Save the options affecting optimization only.
  326. #
  327. if [ $ROCKCFG_DEFAULT_CC = $xpkg ]; then
  328. echo "Creating /etc/profile.d/gcc ..."
  329. {
  330. echo "export CFLAGS_SIZE=\"$(echo $(
  331. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  332. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  333. tr ' ' '\n' | sed -e 's/^-SIZE-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  334. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  335. ))\""
  336. echo "export CFLAGS_SPEED=\"$(echo $(
  337. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  338. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  339. tr ' ' '\n' | sed -e 's/^-SPEED-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  340. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  341. ))\""
  342. echo "export CFLAGS=\"\$CFLAGS_SIZE\""
  343. } > $root/etc/profile.d/gcc
  344. fi
  345. if [ $ROCKCFG_DEFAULT_CXX = $xpkg ]; then
  346. echo "Creating /etc/profile.d/gxx ..."
  347. {
  348. echo "export CXXFLAGS_SIZE=\"$(echo $(
  349. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  350. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  351. tr ' ' '\n' | sed -e 's/^-SIZE-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  352. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  353. ))\""
  354. echo "export CXXFLAGS_SPEED=\"$(echo $(
  355. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  356. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  357. tr ' ' '\n' | sed -e 's/^-SPEED-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  358. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  359. ))\""
  360. echo "export CXXFLAGS=\"\$CFLAGS_SIZE\""
  361. } > $root/etc/profile.d/gxx
  362. fi
  363. # The location of libgcc_s.so{,.1} has changed in gcc 4.3, move to old location.
  364. if [ $pkg_gcc_version -ge 43 ]; then
  365. for x in $root/$prefix/lib/${gcc_lib_dir}/../lib/libgcc_s.so.* ; do
  366. [ -e "$x" ] && mv -v "$x" $root/$prefix/lib/${gcc_lib_dir}/
  367. done
  368. [ -e $root/$prefix/lib/${gcc_lib_dir}/../lib ] && \
  369. rmdir -v --ignore-fail-on-non-empty $root/$prefix/lib/${gcc_lib_dir}/../lib
  370. fi
  371. # Create symlinks for runtime libraries so they can be found by
  372. # the dynamic loader and force rebuilding of the wrapper links
  373. #
  374. [ "$ROCKCFG_DEFAULT_CC" = $xpkg ] && \
  375. ( mkdir -p $root/$prefix/lib ; cd $root/$prefix/lib ; \
  376. ln -vfs ${gcc_lib_dir}/*.so.* . ; )
  377. fi
  378. rm -fv $base/build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate
  379. }
  380. create_links() {
  381. for x ; do
  382. if [ -f "$root/$prefix/bin/$x-${pkg_gcc_version}" ] ; then
  383. rm -vf $root/$prefix/bin/$x
  384. ln -vs $x-${pkg_gcc_version} $root/$prefix/bin/$x
  385. fi
  386. x="${pkg_gcc_target}-$x"
  387. if [ -f $root/$prefix/bin/$x-${pkg_gcc_version} ] ; then
  388. rm -vf $root/$prefix/bin/$x
  389. ln -vs $x-${pkg_gcc_version} $root/$prefix/bin/$x
  390. fi
  391. done
  392. }