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.

369 lines
11 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. makeopt="all-gcc"
  68. makeinstopt="install-gcc"
  69. else
  70. var_append confopt " " "--enable-shared --enable-languages=c,c++"
  71. makeopt=""
  72. makeinstopt="install"
  73. fi
  74. elif [ $stagelevel -eq 0 ] ; then
  75. configprefix=""
  76. confopt="--prefix=${CLFS}/$cross_tools \
  77. --host=${CLFS_HOST} --target=${CLFS_TARGET} \$extraconfopt"
  78. var_append extraconfopt " \
  79. --with-sysroot=${CLFS} --disable-nls --disable-shared \
  80. --enable-languages=c"
  81. makeopt="all-gcc"
  82. makeinstopt="install-gcc"
  83. elif [ $stagelevel -eq 1 ] ; then
  84. configprefix=""
  85. confopt="--prefix=${CLFS}/$cross_tools \
  86. --host=${CLFS_HOST} --target=${CLFS_TARGET} \$extraconfopt"
  87. var_append extraconfopt " \
  88. --with-sysroot=${CLFS} --disable-nls --enable-shared \
  89. --enable-languages=c,c++ --enable-__cxa_atexit \
  90. --enable-c99 --enable-long-long --enable-threads=posix"
  91. makeopt=""
  92. makeinstopt="install"
  93. elif [ $stagelevel -ge 2 ] ; then
  94. var_append extraconfopt " " " \
  95. --enable-shared \
  96. --enable-__cxa_atexit \
  97. --enable-c99 --enable-long-long --enable-threads=posix \
  98. --enable-clocale=gnu"
  99. if [ $stagelevel -eq 2 ] ; then
  100. var_append extraconfopt " " "--enable-languages=c,c++ \
  101. --disable-libstdcxx-pch"
  102. else
  103. var_append confopt ' ' '--enable-languages=$languages'
  104. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_PROFILED"
  105. if [ "${!x}" = 1 ] ; then
  106. var_append makeopt ' ' "GCJFLAGS=\"\$CXXFLAGS\" \
  107. profiledbootstrap"
  108. fi
  109. fi
  110. # We install binaries, info files and man pages in temporary
  111. # directories so we can rename them (adding version suffix) before
  112. # moving them to their final directories.
  113. #
  114. var_append makeopt " " "prefix=/$prefix"
  115. for x in bin info man data ; do
  116. mkdir -p $dummydir/inst_$x
  117. eval "${x}dir=$dummydir/inst_$x"
  118. done
  119. # libstdc++ locales are not installed to the $datadir without this.
  120. var_append INSTALL_WRAPPER_FILTER "|" "sed -e \
  121. 's,$root/$prefix/share\(/locale/.*/libstdc++.mo\),$dummydir/inst_data\1,'"
  122. var_append extraconfopt " " "--enable-version-specific-runtime-libs"
  123. fi
  124. if [ "$ROCKCFG_MULTILIB" = 0 ] ; then
  125. var_append extraconfopt " " "--disable-multilib"
  126. fi
  127. custmain="custmain"
  128. custmain () {
  129. # Don't install libiberty, use the one from binutils instead.
  130. cp libiberty/Makefile.in{,.orig}
  131. sed 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in.orig > \
  132. libiberty/Makefile.in
  133. if [ $stagelevel -eq 2 ] ; then
  134. cp gcc/gccbug.in{,.orig}
  135. sed 's/@have_mktemp_command@/yes/' gcc/gccbug.in.orig > gcc/gccbug.in
  136. cp gcc/Makefile.in{,.orig}
  137. sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
  138. fi
  139. languages="c"
  140. while read lang ; do
  141. x=""
  142. case $lang in
  143. c++) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_CPP"
  144. ;;
  145. esac
  146. if [ $stagelevel -ge 3 ] ; then
  147. case $lang in
  148. ada) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_ADA"
  149. ;;
  150. f77|f95|fortran)
  151. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_FORTRAN"
  152. ;;
  153. java) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_JAVA"
  154. ;;
  155. objc) x="ROCKCFG_PKG_GCC${pkg_gcc_version}_OBJC"
  156. ;;
  157. obj-c++)
  158. x="ROCKCFG_PKG_GCC${pkg_gcc_version}_OBJCPP"
  159. ;;
  160. esac
  161. fi
  162. if [ "${!x}" = 1 ] ; then
  163. var_append languages "," "$lang"
  164. fi
  165. done <<< "$( sed -nr 's,^language="(.*)",\1,p' gcc/*/config-lang.in )"
  166. mkdir -v ../objdir ; cd ../objdir
  167. eval echo $configprefix ../gcc-*/configure $confopt
  168. eval $configprefix ../gcc-*/configure $confopt
  169. eval make $makeopt
  170. if [ "$ROCKCFG_DO_CHECK" = 1 -a $stagelevel -ge 4 ] ; then
  171. make -k check || true
  172. ../gcc-*/contrib/test_summary
  173. fi
  174. eval make $makeinstopt
  175. if [ $stagelevel -ge 2 -a -z "$pkg_gcc_cross" ] ; then
  176. # Rename and install binaries
  177. #
  178. cd $dummydir/inst_bin ; mkdir -p $root/$prefix/bin
  179. for y in c++ c++filt g++ cpp f77 g77 gfortran gcc gcov ; do
  180. for x in $y ${pkg_gcc_target}-$y ; do
  181. if [ -f "$x" ] ; then
  182. mv -v $x $root/$prefix/bin/${x}-${pkg_gcc_version}
  183. fi
  184. done
  185. done
  186. # Rename and install info-files
  187. #
  188. cd $dummydir/inst_info ; mkdir -p $root/$prefix/info
  189. for x in * ; do
  190. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  191. fn=$( echo $x | sed "s,\([a-z0-9]*\),\1-${pkg_gcc_version}," )
  192. infoname=$( echo $x | sed "s,\([a-z0-9]*\).*,\1," )
  193. echo "$x -> $root/$prefix/info/$fn"
  194. sed "s,$infoname.info,$infoname-${pkg_gcc_version}.info," < $x \
  195. > $root/$prefix/info/$fn
  196. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  197. cp -v $x $root/$prefix/info/$x
  198. fi
  199. true
  200. done
  201. # Rename and install man-pages
  202. #
  203. cd $dummydir/inst_man/man1
  204. mkdir -p $root/$prefix/man/man1
  205. for x in * ; do
  206. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  207. mv -v $x $root/$prefix/man/man1/${x%.1}-${pkg_gcc_version}.1
  208. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  209. ln -sf ${x%.1}-${pkg_gcc_version}.1 $root/$prefix/man/man1/$x
  210. fi
  211. true
  212. done
  213. cd $dummydir/inst_man/man7
  214. mkdir -p $root/$prefix/man/man7
  215. for x in * ; do
  216. [ ! -f $x ] && continue # e.g. if $x becomes '*' somehow
  217. mv -v $x $root/$prefix/man/man7/${x%.1}-${pkg_gcc_version}.7
  218. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  219. ln -sf ${x%.1}-${pkg_gcc_version}.7 $root/$prefix/man/man7/$x
  220. fi
  221. true
  222. done
  223. # Rename and install locales
  224. #
  225. if [ -d "$dummydir/inst_data/locale" ] ; then
  226. cd $dummydir/inst_data/locale
  227. for x in */LC_MESSAGES/*.mo ; do
  228. [ ! -f "$x" ] && continue # e.g. if $x becomes '*' somehow
  229. y="$root/$prefix/share/locale/$x"
  230. y="${y%.mo}-${pkg_gcc_version}.mo"
  231. mkdir -p ${y%/*}
  232. echo "$x -> $y"
  233. mv $x $y
  234. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  235. echo "symlink $x -> $y"
  236. ln -svf ${y##*/} $root/$prefix/share/locale/$x
  237. fi
  238. true
  239. done
  240. fi
  241. # Create various symlinks for cc, c++, cpp and f77.
  242. #
  243. if [ $ROCKCFG_DEFAULT_CC = $xpkg ] ; then
  244. create_links gcc cpp gcov
  245. rm -f $root/$prefix/bin/cc
  246. if [ "$ROCKCFG_DIETLIBC_ALL" = 1 ]; then
  247. cat <<- 'EOT' > $root/$prefix/bin/cc
  248. #!/bin/sh
  249. exec diet gcc "$@"
  250. EOT
  251. chmod +x $root/$prefix/bin/cc
  252. else
  253. ln -svf gcc $root/$prefix/bin/cc
  254. fi
  255. ln -vsf ../$prefix/bin/cpp $root/lib/cpp
  256. fi
  257. ln -sf gcc-${pkg_gcc_version} $root/$prefix/bin/kcc-${pkg_gcc_version}
  258. if [ $ROCKCFG_DEFAULT_KCC = $xpkg ] ; then
  259. ln -vsf gcc-${pkg_gcc_version} $root/$prefix/bin/kcc
  260. fi
  261. if [ $ROCKCFG_DEFAULT_CXX = $xpkg ] ; then
  262. create_links c++ c++filt g++
  263. cp -a $confdir/g++-autopch.sh $root/$prefix/bin/g++-autopch
  264. chmod +x $root/$prefix/bin/g++-autopch
  265. fi
  266. if [ $ROCKCFG_DEFAULT_F77 = $xpkg ] ; then
  267. create_links g77
  268. if [ -f $root/$prefix/bin/g77 ] ; then
  269. rm -vf $root/$prefix/bin/f77
  270. ln -vsf g77 $root/$prefix/bin/f77
  271. fi
  272. fi
  273. if [ $ROCKCFG_DEFAULT_F95 = $xpkg ] ; then
  274. create_links gfortran
  275. fi
  276. # Inject our default optimisation options so when the user calls
  277. # gcc/g++ they match the ones used to precompile the headers ...
  278. # Save the options affecting optimization only.
  279. #
  280. if [ $ROCKCFG_DEFAULT_CC = $xpkg ]; then
  281. echo "Creating /etc/profile.d/gcc ..."
  282. {
  283. echo "export CFLAGS_SIZE=\"$(echo $(
  284. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  285. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  286. tr ' ' '\n' | sed -e 's/^-SIZE-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  287. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  288. ))\""
  289. echo "export CFLAGS_SPEED=\"$(echo $(
  290. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  291. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  292. tr ' ' '\n' | sed -e 's/^-SPEED-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  293. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  294. ))\""
  295. echo "export CFLAGS=\"\$CFLAGS_SIZE\""
  296. } > $root/etc/profile.d/gcc
  297. fi
  298. if [ $ROCKCFG_DEFAULT_CXX = $xpkg ]; then
  299. echo "Creating /etc/profile.d/gxx ..."
  300. {
  301. echo "export CXXFLAGS_SIZE=\"$(echo $(
  302. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  303. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  304. tr ' ' '\n' | sed -e 's/^-SIZE-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  305. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  306. ))\""
  307. echo "export CXXFLAGS_SPEED=\"$(echo $(
  308. eval echo \$GCC_WRAPPER_INSERT \$GCC_WRAPPER_APPEND \
  309. \$GCC${ver:0:1}_WRAPPER_INSERT \$GCC${ver:0:1}_WRAPPER_APPEND | \
  310. tr ' ' '\n' | sed -e 's/^-SPEED-/-/' -e '/^-O/ { p; d; }' -e '/^-mcpu=/ { p; d; }' \
  311. -e '/-march=/ { p; d; }' -e '/-mtune=/ { p; d; }' -e 'd'
  312. ))\""
  313. echo "export CXXFLAGS=\"\$CFLAGS_SIZE\""
  314. } > $root/etc/profile.d/gxx
  315. fi
  316. # Create symlinks for runtime libraries so they can be found by
  317. # the dynamic loader and force rebuilding of the wrapper links
  318. #
  319. [ "$ROCKCFG_DEFAULT_CC" = $xpkg ] && \
  320. ( mkdir -p $root/$prefix/lib ; cd $root/$prefix/lib ; \
  321. ln -vfs ${gcc_lib_dir}/*.so.* . ; )
  322. fi
  323. rm -fv $base/build/$ROCKCFG_ID/ROCK/$toolsdir/.lastupdate
  324. }
  325. create_links() {
  326. for x ; do
  327. if [ -f "$root/$prefix/bin/$x-${pkg_gcc_version}" ] ; then
  328. rm -vf $root/$prefix/bin/$x
  329. ln -vs $x-${pkg_gcc_version} $root/$prefix/bin/$x
  330. fi
  331. x="${pkg_gcc_target}-$x"
  332. if [ -f $root/$prefix/bin/$x-${pkg_gcc_version} ] ; then
  333. rm -vf $root/$prefix/bin/$x
  334. ln -vs $x-${pkg_gcc_version} $root/$prefix/bin/$x
  335. fi
  336. done
  337. }