|
| 1 | +# Copyright (c) 2011-2013, ARM Limited |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are met: |
| 6 | +# |
| 7 | +# * Redistributions of source code must retain the above copyright notice, |
| 8 | +# this list of conditions and the following disclaimer. |
| 9 | +# * Redistributions in binary form must reproduce the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer in the |
| 11 | +# documentation and/or other materials provided with the distribution. |
| 12 | +# * Neither the name of ARM nor the names of its contributors may be used |
| 13 | +# to endorse or promote products derived from this software without |
| 14 | +# specific prior written permission. |
| 15 | +# |
| 16 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 20 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | +# POSSIBILITY OF SUCH DAMAGE. |
| 27 | + |
| 28 | +error () { |
| 29 | + set +u |
| 30 | + echo "$0: error: $@" >&2 |
| 31 | + exit 1 |
| 32 | + set -u |
| 33 | +} |
| 34 | + |
| 35 | +warning () { |
| 36 | + set +u |
| 37 | + echo "$0: warning: $@" >&2 |
| 38 | + set -u |
| 39 | +} |
| 40 | + |
| 41 | +copy_dir() { |
| 42 | + set +u |
| 43 | + mkdir -p "$2" |
| 44 | + |
| 45 | + (cd "$1" && tar cf - .) | (cd "$2" && tar xf -) |
| 46 | + set -u |
| 47 | +} |
| 48 | + |
| 49 | +copy_dir_clean() { |
| 50 | + set +u |
| 51 | + mkdir -p "$2" |
| 52 | + (cd "$1" && tar cf - \ |
| 53 | + --exclude=CVS --exclude=.svn --exclude=.git --exclude=.pc \ |
| 54 | + --exclude="*~" --exclude=".#*" \ |
| 55 | + --exclude="*.orig" --exclude="*.rej" \ |
| 56 | + .) | (cd "$2" && tar xf -) |
| 57 | + set -u |
| 58 | +} |
| 59 | + |
| 60 | +# Create source package excluding source control information |
| 61 | +# parameter 1: base dir of the source tree |
| 62 | +# parameter 2: dirname of the source tree |
| 63 | +# parameter 3: target package name |
| 64 | +# parameter 4-10: additional excluding |
| 65 | +# This function will create bz2 package for files under param1/param2, |
| 66 | +# excluding unnecessary parts, and create package named param2. |
| 67 | +pack_dir_clean() { |
| 68 | + set +u |
| 69 | + tar cjfh $3 \ |
| 70 | + --exclude=CVS --exclude=.svn --exclude=.git --exclude=.pc \ |
| 71 | + --exclude="*~" --exclude=".#*" \ |
| 72 | + --exclude="*.orig" --exclude="*.rej" $4 $5 $6 $7 $8 $9 ${10} \ |
| 73 | + -C $1 $2 |
| 74 | + set -u |
| 75 | +} |
| 76 | + |
| 77 | +# Clean all global shell variables except for those needed by build scripts |
| 78 | +clean_env () { |
| 79 | + set +u |
| 80 | + local var_list |
| 81 | + local var |
| 82 | + var_list=`export|grep "^declare -x"|sed -e "s/declare -x //"|cut -d"=" -f1` |
| 83 | + |
| 84 | + for var in $var_list ; do |
| 85 | + case $var in |
| 86 | + DEJAGNU|\ |
| 87 | + DISPLAY|\ |
| 88 | + HOME|\ |
| 89 | + LD_LIBRARY_PATH|\ |
| 90 | + LOGNAME|\ |
| 91 | + PATH|\ |
| 92 | + PWD|\ |
| 93 | + SHELL|\ |
| 94 | + SHLVL|\ |
| 95 | + TERM|\ |
| 96 | + USER|\ |
| 97 | + USERNAME|\ |
| 98 | + com.apple.*|\ |
| 99 | + XAUTHORITY) |
| 100 | + ;; |
| 101 | + *) |
| 102 | + unset $var |
| 103 | + ;; |
| 104 | + esac |
| 105 | + done |
| 106 | + |
| 107 | + export LANG=C |
| 108 | + set -u |
| 109 | +} |
| 110 | + |
| 111 | +stack_level=0 |
| 112 | + |
| 113 | +# Start a new stack level to save variables |
| 114 | +# Must call this before saving any variables |
| 115 | +saveenv () { |
| 116 | + set +u |
| 117 | + # Force expr return 0 to avoid script fail |
| 118 | + stack_level=`expr $stack_level \+ 1 || true` |
| 119 | + eval stack_list_$stack_level= |
| 120 | + set -u |
| 121 | +} |
| 122 | + |
| 123 | +# Save a variable to current stack level, and set new value to this var. |
| 124 | +# If a variable has been saved, won't save it. Just set new value |
| 125 | +# Must be called when stack_level > 0 |
| 126 | +# $1: variable name |
| 127 | +# $2: new variable value |
| 128 | +saveenvvar () { |
| 129 | + set +u |
| 130 | + if [ $stack_level -le 0 ]; then |
| 131 | + error Must call saveenv before calling saveenvvar |
| 132 | + fi |
| 133 | + local varname="$1" |
| 134 | + local newval="$2" |
| 135 | + eval local oldval=\"\${$varname}\" |
| 136 | + eval local saved=\"\${level_saved_${stack_level}_${varname}}\" |
| 137 | + if [ "x$saved" = "x" ]; then |
| 138 | + # The variable wasn't saved in the level before. Save it |
| 139 | + eval local temp=\"\${stack_list_$stack_level}\" |
| 140 | + eval stack_list_$stack_level=\"$varname $temp\" |
| 141 | + eval save_level_${stack_level}_$varname=\"$oldval\" |
| 142 | + eval level_saved_${stack_level}_$varname="yes" |
| 143 | + eval level_preset_${stack_level}_${varname}=\"\${$varname+set}\" |
| 144 | + #echo Save $varname: \"$oldval\" |
| 145 | + fi |
| 146 | + eval export $varname=\"$newval\" |
| 147 | + #echo $varname set to \"$newval\" |
| 148 | + set -u |
| 149 | +} |
| 150 | + |
| 151 | +# Restore all variables that have been saved in current stack level |
| 152 | +restoreenv () { |
| 153 | + set +u |
| 154 | + if [ $stack_level -le 0 ]; then |
| 155 | + error "Trying to restore from an empty stack" |
| 156 | + fi |
| 157 | + |
| 158 | + eval local list=\"\${stack_list_$stack_level}\" |
| 159 | + local varname |
| 160 | + for varname in $list; do |
| 161 | + eval local varname_preset=\"\${level_preset_${stack_level}_${varname}}\" |
| 162 | + if [ "x$varname_preset" = "xset" ] ; then |
| 163 | + eval $varname=\"\${save_level_${stack_level}_$varname}\" |
| 164 | + else |
| 165 | + unset $varname |
| 166 | + fi |
| 167 | + eval level_saved_${stack_level}_$varname= |
| 168 | + # eval echo $varname restore to \\\"\"\${$varname}\"\\\" |
| 169 | + done |
| 170 | + # Force expr return 0 to avoid script fail |
| 171 | + stack_level=`expr $stack_level \- 1 || true` |
| 172 | + set -u |
| 173 | +} |
| 174 | + |
| 175 | +prependenvvar() { |
| 176 | + set +u |
| 177 | + eval local oldval=\"\$$1\" |
| 178 | + saveenvvar "$1" "$2$oldval" |
| 179 | + set -u |
| 180 | +} |
| 181 | + |
| 182 | +prepend_path() { |
| 183 | + set +u |
| 184 | + eval local old_path="\"\$$1\"" |
| 185 | + if [ x"$old_path" == "x" ]; then |
| 186 | + prependenvvar "$1" "$2" |
| 187 | + else |
| 188 | + prependenvvar "$1" "$2:" |
| 189 | + fi |
| 190 | + set -u |
| 191 | +} |
| 192 | + |
| 193 | +# Strip binary files as in "strip binary" form, for both native(linux/mac) and mingw. |
| 194 | +strip_binary() { |
| 195 | + set +e |
| 196 | + if [ $# -ne 2 ] ; then |
| 197 | + warning "strip_binary: Missing arguments" |
| 198 | + return 0 |
| 199 | + fi |
| 200 | + local strip="$1" |
| 201 | + local bin="$2" |
| 202 | + |
| 203 | + file $bin | grep -q -P "(\bELF\b)|(\bPE\b)|(\bPE32\b)" |
| 204 | + if [ $? -eq 0 ]; then |
| 205 | + $strip $bin 2>/dev/null || true |
| 206 | + fi |
| 207 | + |
| 208 | + set -e |
| 209 | +} |
| 210 | + |
| 211 | +# Copy target libraries from each multilib directories. |
| 212 | +# Usage copy_multi_libs dst_prefix=... src_prefix=... target_gcc=... |
| 213 | +copy_multi_libs() { |
| 214 | + local -a multilibs |
| 215 | + local multilib |
| 216 | + local multi_dir |
| 217 | + local src_prefix |
| 218 | + local dst_prefix |
| 219 | + local src_dir |
| 220 | + local dst_dir |
| 221 | + local target_gcc |
| 222 | + |
| 223 | + for arg in "$@" ; do |
| 224 | + eval "${arg// /\\ }" |
| 225 | + done |
| 226 | + |
| 227 | + multilibs=( $("${target_gcc}" -print-multi-lib 2>/dev/null) ) |
| 228 | + for multilib in "${multilibs[@]}" ; do |
| 229 | + multi_dir="${multilib%%;*}" |
| 230 | + src_dir=${src_prefix}/${multi_dir} |
| 231 | + dst_dir=${dst_prefix}/${multi_dir} |
| 232 | + cp -f "${src_dir}/libstdc++.a" "${dst_dir}/libstdc++_s.a" |
| 233 | + cp -f "${src_dir}/libsupc++.a" "${dst_dir}/libsupc++_s.a" |
| 234 | + cp -f "${src_dir}/libc.a" "${dst_dir}/libc_s.a" |
| 235 | + cp -f "${src_dir}/libg.a" "${dst_dir}/libg_s.a" |
| 236 | + cp -f "${src_dir}/librdimon.a" "${dst_dir}/librdimon_s.a" |
| 237 | + cp -f "${src_dir}/nano.specs" "${dst_dir}/" |
| 238 | + cp -f "${src_dir}/rdimon.specs" "${dst_dir}/" |
| 239 | + cp -f "${src_dir}/nosys.specs" "${dst_dir}/" |
| 240 | + cp -f "${src_dir}/"*crt0.o "${dst_dir}/" |
| 241 | + done |
| 242 | +} |
| 243 | + |
| 244 | +# Clean up unnecessary global shell variables |
| 245 | +clean_env |
| 246 | + |
| 247 | +ROOT=`pwd` |
| 248 | +SRCDIR=$ROOT/src |
| 249 | + |
| 250 | +BUILDDIR_NATIVE=$ROOT/build-native |
| 251 | +BUILDDIR_MINGW=$ROOT/build-mingw |
| 252 | +INSTALLDIR_NATIVE=$ROOT/install-native |
| 253 | +INSTALLDIR_NATIVE_DOC=$ROOT/install-native/share/doc/gcc-arm-none-eabi |
| 254 | +INSTALLDIR_MINGW=$ROOT/install-mingw |
| 255 | +INSTALLDIR_MINGW_DOC=$ROOT/install-mingw/share/doc/gcc-arm-none-eabi |
| 256 | + |
| 257 | +PACKAGEDIR=$ROOT/pkg |
| 258 | + |
| 259 | +BINUTILS=binutils |
| 260 | +CLOOG=cloog-0.18.0 |
| 261 | +EXPAT=expat-2.0.1 |
| 262 | +GCC=gcc |
| 263 | +GCC_PLUGINS=gcc-plugins |
| 264 | +GDB=gdb |
| 265 | +GMP=gmp-4.3.2 |
| 266 | +NEWLIB_NANO=newlib-nano-2.1 |
| 267 | +SAMPLES=samples |
| 268 | +LIBELF=libelf-0.8.13 |
| 269 | +LIBICONV=libiconv-1.14 |
| 270 | +MPC=mpc-0.8.1 |
| 271 | +MPFR=mpfr-2.4.2 |
| 272 | +NEWLIB=newlib |
| 273 | +ISL=isl-0.11.1 |
| 274 | +ZLIB=zlib-1.2.5 |
| 275 | +INSTALLATION=installation |
| 276 | +SAMPLES=samples |
| 277 | +BUILD_MANUAL=build-manual |
| 278 | + |
| 279 | +CLOOG_PACK=$CLOOG.tar.gz |
| 280 | +EXPAT_PACK=$EXPAT.tar.gz |
| 281 | +GMP_PACK=$GMP.tar.bz2 |
| 282 | +LIBELF_PACK=$LIBELF.tar.gz |
| 283 | +LIBICONV_PACK=$LIBICONV.tar.gz |
| 284 | +MPC_PACK=$MPC.tar.gz |
| 285 | +MPFR_PACK=$MPFR.tar.bz2 |
| 286 | +ISL_PACK=$ISL.tar.bz2 |
| 287 | +ZLIB_PACK=$ZLIB.tar.bz2 |
| 288 | + |
| 289 | +ZLIB_PATCH=$ZLIB.patch |
| 290 | + |
| 291 | +RELEASEDATE=`date +%Y%m%d` |
| 292 | +release_year=${RELEASEDATE:0:4} |
| 293 | +release_month=${RELEASEDATE:4:2} |
| 294 | +case $release_month in |
| 295 | + 01|02|03) |
| 296 | + RELEASEVER=${release_year}q1 |
| 297 | + ;; |
| 298 | + 04|05|06) |
| 299 | + RELEASEVER=${release_year}q2 |
| 300 | + ;; |
| 301 | + 07|08|09) |
| 302 | + RELEASEVER=${release_year}q3 |
| 303 | + ;; |
| 304 | + 10|11|12) |
| 305 | + RELEASEVER=${release_year}q4 |
| 306 | + ;; |
| 307 | +esac |
| 308 | + |
| 309 | +RELEASE_FILE=release.txt |
| 310 | +README_FILE=readme.txt |
| 311 | +LICENSE_FILE=license.txt |
| 312 | +SAMPLES_DOS_FILES=$SAMPLES/readme.txt |
| 313 | +BUILD_MANUAL_FILE=How-to-build-toolchain.pdf |
| 314 | +GCC_VER=`cat $SRCDIR/$GCC/gcc/BASE-VER` |
| 315 | +GCC_VER_NAME=`echo $GCC_VER | cut -d'.' -f1,2 | sed -e 's/\./_/g'` |
| 316 | +HOST_MINGW=i686-w64-mingw32 |
| 317 | +HOST_MINGW_TOOL=i686-w64-mingw32 |
| 318 | +TARGET=arm-none-eabi |
| 319 | +ENV_CFLAGS= |
| 320 | +ENV_CPPFLAGS= |
| 321 | +ENV_LDFLAGS= |
| 322 | +BINUTILS_CONFIG_OPTS= |
| 323 | +GCC_CONFIG_OPTS= |
| 324 | +GDB_CONFIG_OPTS= |
| 325 | +NEWLIB_CONFIG_OPTS= |
| 326 | + |
| 327 | + |
| 328 | +PKGVERSION="GNU Tools for ARM Embedded Processors" |
| 329 | +BUGURL="" |
| 330 | + |
| 331 | +# Set variables according to real environment to make this script can run |
| 332 | +# on Ubuntu and Mac OS X. |
| 333 | +build_gcc_plugin=no |
| 334 | +uname_string=`uname | sed 'y/LINUXDARWIN/linuxdarwin/'` |
| 335 | +host_arch=`uname -m | sed 'y/XI/xi/'` |
| 336 | +if [ "x$uname_string" == "xlinux" ] ; then |
| 337 | + BUILD="$host_arch"-linux-gnu |
| 338 | + HOST_NATIVE="$host_arch"-linux-gnu |
| 339 | + READLINK=readlink |
| 340 | + JOBS=`grep ^processor /proc/cpuinfo|wc -l` |
| 341 | + GCC_CONFIG_OPTS_LCPP="--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm" |
| 342 | + TAR=tar |
| 343 | + MD5="md5sum -b" |
| 344 | + PACKAGE_NAME_SUFFIX=linux |
| 345 | + build_gcc_plugin=yes |
| 346 | +elif [ "x$uname_string" == "xdarwin" ] ; then |
| 347 | + BUILD=x86_64-apple-darwin10 |
| 348 | + HOST_NATIVE=x86_64-apple-darwin10 |
| 349 | + READLINK=greadlink |
| 350 | +# Disable parallel build for mac as we will randomly run into "Permission denied" issue. |
| 351 | +# JOBS=`sysctl -n hw.ncpu` |
| 352 | + JOBS=1 |
| 353 | + GCC_CONFIG_OPTS_LCPP="--with-host-libstdcxx=-static-libgcc -Wl,-lstdc++ -lm" |
| 354 | + TAR=gnutar |
| 355 | + MD5="md5 -r" |
| 356 | + PACKAGE_NAME_SUFFIX=mac |
| 357 | +else |
| 358 | + error "Unsupported build system : $uname_string" |
| 359 | +fi |
| 360 | + |
| 361 | +OBJ_SUFFIX_MINGW=$TARGET-$RELEASEDATE-$HOST_MINGW |
| 362 | +OBJ_SUFFIX_NATIVE=$TARGET-$RELEASEDATE-$HOST_NATIVE |
| 363 | +PACKAGE_NAME=gcc-$TARGET-$GCC_VER_NAME-$RELEASEVER-$RELEASEDATE |
| 364 | +PACKAGE_NAME_NATIVE=$PACKAGE_NAME-$PACKAGE_NAME_SUFFIX |
| 365 | +PACKAGE_NAME_MINGW=$PACKAGE_NAME-win32 |
| 366 | +INSTALL_PACKAGE_NAME=gcc-$TARGET-$GCC_VER_NAME-$RELEASEVER |
| 367 | + |
0 commit comments