gcc_build 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #! /bin/sh
  2. ########################################################################
  3. #
  4. # File: gcc_build
  5. # Author: Mark Mitchell
  6. # Date: 2000-07-10
  7. #
  8. # Adapted to Subversion by Ben Elliston <bje@au.ibm.com>, 2005-07-14.
  9. #
  10. # Contents:
  11. # Script to automatically download and build GCC.
  12. #
  13. # Copyright (c) 2000, 2001, 2003, 2005 Free Software Foundation.
  14. #
  15. # This file is part of GCC.
  16. #
  17. # GCC is free software; you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation; either version 3, or (at your option)
  20. # any later version.
  21. #
  22. # GCC is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with GCC; see the file COPYING. If not, write to
  29. # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  30. # Boston, MA 02110-1301, USA.
  31. #
  32. ########################################################################
  33. ########################################################################
  34. # Notes
  35. ########################################################################
  36. # You can set the following variables in the environment. They
  37. # have no corresponding command-line options because they should
  38. # only be needed infrequently:
  39. #
  40. # MAKE The path to `make'.
  41. ########################################################################
  42. # Functions
  43. ########################################################################
  44. # Issue the error message given by $1 and exit with a non-zero
  45. # exit code.
  46. error() {
  47. echo "gcc_build: error: $1"
  48. exit 1
  49. }
  50. # Issue a usage message explaining how to use this script.
  51. usage() {
  52. cat <<EOF
  53. gcc_build [-c configure_options]
  54. [-d destination_directory]
  55. [-m make_boot_options]
  56. [-o objdir]
  57. [-b branch_name]
  58. [-u username]
  59. [-p protocol]
  60. [-t tarfile]
  61. [-x make_check_options]
  62. [bootstrap]
  63. [build]
  64. [checkout]
  65. [configure]
  66. [export]
  67. [install]
  68. [test]
  69. [update]
  70. EOF
  71. exit 1
  72. }
  73. # Change to the directory given by $1.
  74. changedir() {
  75. cd $1 || \
  76. error "Could not change directory to $1"
  77. }
  78. # Checkout a fresh copy of the GCC build tree.
  79. checkout_gcc() {
  80. # If the destination already exists, don't risk destroying it.
  81. test -e ${DESTINATION} && \
  82. error "${DESTINATION} already exists"
  83. # Checkout the tree
  84. test -n "${SVN_USERNAME}" && SVN_USERNAME="${SVN_USERNAME}@"
  85. SVNROOT="${SVN_PROTOCOL}://${SVN_USERNAME}${SVN_SERVER}${SVN_REPOSITORY}${SVN_BRANCH}"
  86. $GCC_SVN co $SVNROOT ${DESTINATION} || \
  87. error "Could not check out GCC"
  88. }
  89. # Update GCC.
  90. update_gcc() {
  91. # If the destination does not already exist, complain.
  92. test -d ${DESTINATION} || \
  93. error "${DESTINATION} does not exist"
  94. # Enter the destination directory.
  95. changedir ${DESTINATION}
  96. # Update the tree
  97. ./contrib/gcc_update || \
  98. error "Could not update GCC"
  99. }
  100. # Configure for a build of GCC.
  101. configure_gcc() {
  102. # Go to the source directory.
  103. changedir ${DESTINATION}
  104. # Remove the object directory.
  105. rm -rf ${OBJDIR}
  106. # Create it again.
  107. mkdir ${OBJDIR} || \
  108. error "Could not create ${OBJDIR}"
  109. # Enter it.
  110. changedir ${OBJDIR}
  111. # Configure the tree.
  112. echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}"
  113. eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
  114. error "Could not configure the compiler"
  115. }
  116. # Bootstrap GCC. Assume configuration has already occurred.
  117. bootstrap_gcc() {
  118. # Go to the source directory.
  119. changedir ${DESTINATION}
  120. # Go to the object directory.
  121. changedir ${OBJDIR}
  122. # Bootstrap the compiler
  123. echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap"
  124. eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \
  125. error "Could not bootstrap the compiler"
  126. }
  127. # Test GCC.
  128. test_gcc() {
  129. # Go to the source directory.
  130. changedir ${DESTINATION}
  131. # Go to the object directory.
  132. changedir ${OBJDIR}
  133. echo "Running tests... This will take a while."
  134. eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check
  135. ${DESTINATION}/contrib/test_summary
  136. }
  137. # Export the GCC source tree.
  138. export_gcc() {
  139. # Go to the source directory.
  140. changedir ${DESTINATION}
  141. # Go up one level.
  142. changedir ..
  143. # Build a tarball of the source directory.
  144. tar czf ${TARFILE} \
  145. --exclude=${OBJDIR} \
  146. --exclude=.svn \
  147. --exclude='.#*' \
  148. --exclude='*~' \
  149. `basename ${DESTINATION}`
  150. }
  151. # Install GCC.
  152. install_gcc() {
  153. # Go to the source directory.
  154. changedir ${DESTINATION}
  155. # Go to the object directory.
  156. changedir ${OBJDIR}
  157. ${MAKE} install || error "Installation failed"
  158. }
  159. ########################################################################
  160. # Initialization
  161. ########################################################################
  162. # SVN command
  163. GCC_SVN=${GCC_SVN-${SVN-svn}}
  164. # The SVN server containing the GCC repository.
  165. SVN_SERVER="gcc.gnu.org"
  166. # The path to the repository on that server.
  167. SVN_REPOSITORY="/svn/gcc/"
  168. # The branch to check out from that server.
  169. # Defaults to trunk if no branch is defined with -b.
  170. SVN_BRANCH=""
  171. # The SVN protocol to use.
  172. SVN_PROTOCOL="svn"
  173. # The username to use when connecting to the server.
  174. # An empty string means anonymous.
  175. SVN_USERNAME=""
  176. # The directory where the checked out GCC will be placed.
  177. DESTINATION="${HOME}/dev/gcc"
  178. # The relative path from the top of the source tree to the
  179. # object directory.
  180. OBJDIR="objdir"
  181. # The file where the tarred up sources will be placed.
  182. TARFILE="${HOME}/dev/gcc.tgz"
  183. # Options to pass to configure.
  184. CONFIGURE_OPTIONS=
  185. # The `make' program.
  186. MAKE=${MAKE:-make}
  187. # Options to pass to "make bootstrap".
  188. MAKE_BOOTSTRAP_OPTIONS=
  189. # Options to pass to "make check".
  190. MAKE_CHECK_OPTIONS=
  191. # Modes of operation
  192. BOOTSTRAP=0
  193. CHECKOUT=0
  194. CONFIGURE=0
  195. EXPORT=0
  196. INSTALL=0
  197. TEST=0
  198. UPDATE=0
  199. ########################################################################
  200. # Main Program
  201. ########################################################################
  202. # Issue usage if no parameters are given.
  203. test $# -eq 0 && usage
  204. # Parse the options.
  205. while getopts "c:d:m:o:p:t:b:u:x:" ARG; do
  206. case $ARG in
  207. c) CONFIGURE_OPTIONS="${OPTARG}";;
  208. d) DESTINATION="${OPTARG}";;
  209. m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";;
  210. o) OBJDIR="${OPTARG}";;
  211. p) SVN_PROTOCOL="${OPTARG}";;
  212. t) TARFILE="${OPTARG}";;
  213. x) MAKE_CHECK_OPTIONS="${OPTARG}";;
  214. b) SVN_BRANCH="${OPTARG}";;
  215. u) SVN_USERNAME="${OPTARG}";;
  216. \?) usage;;
  217. esac
  218. done
  219. shift `expr ${OPTIND} - 1`
  220. # Handle the major modes.
  221. while [ $# -ne 0 ]; do
  222. case $1 in
  223. bootstrap) BOOTSTRAP=1;;
  224. build) CONFIGURE=1; BOOTSTRAP=1;;
  225. checkout) CHECKOUT=1;;
  226. configure) CONFIGURE=1;;
  227. export) EXPORT=1;;
  228. install) INSTALL=1;;
  229. test) TEST=1;;
  230. update) UPDATE=1;;
  231. *) usage;;
  232. esac
  233. shift
  234. done
  235. # Check the arguments for sanity.
  236. if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
  237. error "Cannot checkout and update simultaneously"
  238. fi
  239. if [ ${CHECKOUT} -eq 0 ] && test -n "${SVN_BRANCH}"; then
  240. error "Branch argument only makes sense when doing a checkout"
  241. fi
  242. # Validate the branch name.
  243. if test -n "${SVN_BRANCH}"; then
  244. SVN_BRANCH="branches/${SVN_BRANCH}";
  245. else
  246. SVN_BRANCH="trunk";
  247. fi
  248. # Checkout the tree.
  249. if [ ${CHECKOUT} -ne 0 ]; then
  250. checkout_gcc
  251. elif [ ${UPDATE} -ne 0 ]; then
  252. update_gcc
  253. fi
  254. # Configure to build the tree.
  255. if [ ${CONFIGURE} -ne 0 ]; then
  256. configure_gcc
  257. fi
  258. # Bootstrap the compiler.
  259. if [ ${BOOTSTRAP} -ne 0 ]; then
  260. bootstrap_gcc
  261. fi
  262. # Test the compiler
  263. if [ ${TEST} -ne 0 ]; then
  264. test_gcc
  265. fi
  266. # Install the compiler.
  267. if [ ${INSTALL} -ne 0 ]; then
  268. install_gcc
  269. fi
  270. # Export the sources
  271. if [ ${EXPORT} -ne 0 ]; then
  272. export_gcc
  273. fi