[aafe99e] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | # Copyright 2005-2016 Patrick J. Volkerding, Sebeka, Minnesota, USA |
---|
| 4 | # All rights reserved. |
---|
| 5 | # |
---|
| 6 | # Redistribution and use of this script, with or without modification, is |
---|
| 7 | # permitted provided that the following conditions are met: |
---|
| 8 | # |
---|
| 9 | # 1. Redistributions of this script must retain the above copyright |
---|
| 10 | # notice, this list of conditions and the following disclaimer. |
---|
| 11 | # |
---|
| 12 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
---|
| 13 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
---|
| 14 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
---|
| 15 | # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
| 16 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 17 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
---|
| 18 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
---|
| 19 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
| 20 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
---|
| 21 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 22 | |
---|
| 23 | # Modified 2011 by Eric Hameleers <alien at slackware.com> for ARM port. |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | PKGNAM=binutils |
---|
| 27 | VERSION=${VERSION:-$(echo $PKGNAM-*.tar.xz | rev | cut -f 3- -d . | cut -f 1 -d - | rev)} |
---|
| 28 | BUILD=${BUILD:-2} |
---|
| 29 | |
---|
| 30 | # Automatically determine the architecture we're building on: |
---|
| 31 | MARCH=$( uname -m ) |
---|
| 32 | if [ -z "$ARCH" ]; then |
---|
| 33 | case "$MARCH" in |
---|
| 34 | i?86) export ARCH=i586 ;; |
---|
| 35 | armv7hl) export ARCH=$MARCH ;; |
---|
| 36 | arm*) export ARCH=arm ;; |
---|
| 37 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
| 38 | *) export ARCH=$MARCH ;; |
---|
| 39 | esac |
---|
| 40 | fi |
---|
| 41 | |
---|
| 42 | NUMJOBS=${NUMJOBS:-" -j7 "} |
---|
| 43 | |
---|
| 44 | # Uncomment this to include the experimental gold linker: |
---|
| 45 | GOLD=" --enable-gold=yes --enable-ld=default " |
---|
| 46 | |
---|
| 47 | # Set to ld.gold or ld.bfd: |
---|
| 48 | DEFAULT_LD=ld.bfd |
---|
| 49 | |
---|
| 50 | # The --enable-initfini-array option was added in binutils-2.21.51.0.3. |
---|
| 51 | # This option currently causes a world of hurt trying to compile glibc, |
---|
| 52 | # and might break static libraries or cause other ill effects. There |
---|
| 53 | # is an upstream patch for glibc but it does not avoid all of the known |
---|
| 54 | # problems (and there may be some unknown ones, too), so we will avoid |
---|
| 55 | # introducing this feature for now. |
---|
| 56 | # References: |
---|
| 57 | # http://sourceware.org/bugzilla/show_bug.cgi?id=12343 |
---|
| 58 | # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770 |
---|
| 59 | NO_INITFINI=" --disable-initfini-array " |
---|
| 60 | |
---|
| 61 | if [ "$ARCH" = "i586" ]; then |
---|
| 62 | SLKCFLAGS="-O2 -march=i586 -mtune=i686" |
---|
| 63 | # The config option below is currently needed to compile on x86: |
---|
| 64 | WERROR="--enable-werror=no" |
---|
| 65 | LIBDIRSUFFIX="" |
---|
| 66 | elif [ "$ARCH" = "i686" ]; then |
---|
| 67 | SLKCFLAGS="-O2 -march=i686 -mtune=i686" |
---|
| 68 | # The config option below is currently needed to compile on x86: |
---|
| 69 | WERROR="--enable-werror=no" |
---|
| 70 | LIBDIRSUFFIX="" |
---|
| 71 | elif [ "$ARCH" = "s390" ]; then |
---|
| 72 | SLKCFLAGS="-O2" |
---|
| 73 | LIBDIRSUFFIX="" |
---|
| 74 | elif [ "$ARCH" = "x86_64" ]; then |
---|
| 75 | SLKCFLAGS="-O2 -fPIC" |
---|
| 76 | LIBDIRSUFFIX="64" |
---|
| 77 | elif [ "$ARCH" = "armv7hl" ]; then |
---|
| 78 | SLKCFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16" |
---|
| 79 | LIBDIRSUFFIX="" |
---|
| 80 | else |
---|
| 81 | SLKCFLAGS="-O2" |
---|
| 82 | LIBDIRSUFFIX="" |
---|
| 83 | fi |
---|
| 84 | |
---|
| 85 | case "$ARCH" in |
---|
| 86 | arm*) TARGET=$ARCH-slackware-linux-gnueabi ;; |
---|
| 87 | *) TARGET=$ARCH-slackware-linux ;; |
---|
| 88 | esac |
---|
| 89 | |
---|
| 90 | CWD=$(pwd) |
---|
| 91 | TMP=${TMP:-/tmp} |
---|
| 92 | PKG=$TMP/package-binutils |
---|
| 93 | |
---|
| 94 | rm -rf $PKG |
---|
| 95 | mkdir -p $TMP $PKG |
---|
| 96 | |
---|
| 97 | cd $TMP |
---|
| 98 | rm -rf binutils-$VERSION |
---|
| 99 | tar xvf $CWD/binutils-$VERSION.tar.xz || \ |
---|
| 100 | tar xvf $CWD/binutils-$VERSION.tar.bz2 || exit 1 |
---|
| 101 | cd binutils-$VERSION |
---|
| 102 | |
---|
| 103 | # Various upstream patches: |
---|
| 104 | zcat $CWD/patches/binutils-2.20.51.0.2-libtool-lib64.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 105 | zcat $CWD/patches/binutils-2.20.51.0.10-ppc64-pie.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 106 | zcat $CWD/patches/binutils-2.25-version.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 107 | zcat $CWD/patches/binutils-2.25-set-long-long.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 108 | zcat $CWD/patches/binutils-2.20.51.0.10-copy-osabi.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 109 | zcat $CWD/patches/binutils-2.20.51.0.10-sec-merge-emit.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 110 | zcat $CWD/patches/binutils-2.23.52.0.1-addr2line-dynsymtab.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 111 | zcat $CWD/patches/binutils-2.24-ldforcele.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 112 | zcat $CWD/patches/binutils-2.25.1-cleansweep.patch.gz | patch -p2 --verbose || exit 1 |
---|
| 113 | |
---|
| 114 | # Export the demangle.h header file: |
---|
| 115 | zcat $CWD/patches/binutils.export.demangle.h.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 116 | # Don't check to see if "config.h" was included in the installed headers: |
---|
| 117 | zcat $CWD/patches/binutils.no-config-h-check.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 118 | |
---|
| 119 | # Set %version to something halfway meaningful: |
---|
| 120 | sed -i -e 's/%''{release}/slack15/g' bfd/Makefile{.am,.in} |
---|
| 121 | |
---|
| 122 | chown -R root:root . |
---|
| 123 | find . \ |
---|
| 124 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
| 125 | -exec chmod 755 {} \; -o \ |
---|
| 126 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
| 127 | -exec chmod 644 {} \; |
---|
| 128 | |
---|
| 129 | # End of preparations |
---|
| 130 | if echo "$*" | grep -qw -- --prep ; then |
---|
| 131 | exit 0 |
---|
| 132 | fi |
---|
| 133 | |
---|
| 134 | # Build for an x86 glibc2-based Linux system: |
---|
| 135 | CFLAGS="$SLKCFLAGS" \ |
---|
| 136 | ./configure \ |
---|
| 137 | --prefix=/usr \ |
---|
| 138 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
| 139 | --mandir=/usr/man \ |
---|
| 140 | --infodir=/usr/info \ |
---|
| 141 | --with-docdir=/usr/doc/binutils-$VERSION \ |
---|
| 142 | --disable-compressed-debug-sections \ |
---|
| 143 | --enable-shared \ |
---|
| 144 | --enable-multilib \ |
---|
| 145 | --enable-64-bit-bfd \ |
---|
| 146 | --enable-plugins \ |
---|
| 147 | --enable-threads \ |
---|
| 148 | --enable-targets=i386-efi-pe,${TARGET} \ |
---|
| 149 | --enable-install-libiberty \ |
---|
| 150 | $GOLD \ |
---|
| 151 | $NO_INITFINI \ |
---|
| 152 | $WERROR \ |
---|
| 153 | --build=$TARGET \ |
---|
| 154 | || exit 1 |
---|
| 155 | |
---|
| 156 | make clean || exit 1 |
---|
| 157 | make $NUMJOBS || make || exit 1 |
---|
| 158 | make install DESTDIR=$PKG || exit 1 |
---|
| 159 | |
---|
| 160 | # Differentiate between BSD strings and GNU strings |
---|
| 161 | ( cd $PKG/usr/bin ; mv strings strings-GNU ) |
---|
| 162 | ( cd $PKG/usr/man/man1 ; mv strings.1 strings-GNU.1 ) |
---|
| 163 | |
---|
| 164 | # Move ldscripts to /usr/lib${LIBDIRSUFFIX}, and then put symlinks in place |
---|
| 165 | mv $PKG/usr/${TARGET}/lib/ldscripts $PKG/usr/lib${LIBDIRSUFFIX} |
---|
| 166 | ( cd $PKG/usr/${TARGET} |
---|
| 167 | ln -s /usr/lib${LIBDIRSUFFIX}/ldscripts lib/ldscripts |
---|
| 168 | for FILE in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib strip ; do |
---|
| 169 | if [ -r "/usr/bin/$FILE" ]; then |
---|
| 170 | rm -f bin/$FILE |
---|
| 171 | ln -s /usr/bin/$FILE bin/$FILE |
---|
| 172 | fi |
---|
| 173 | done |
---|
| 174 | ) |
---|
| 175 | |
---|
| 176 | # If the requested default linker is present, make it the default: |
---|
| 177 | # Set the link differently on the system to change the default at runtime. |
---|
| 178 | if [ -r $PKG/usr/bin/$DEFAULT_LD ]; then |
---|
| 179 | ( cd $PKG/usr/bin ; rm -f ld ; ln -sf $DEFAULT_LD ld ) |
---|
| 180 | fi |
---|
| 181 | |
---|
| 182 | find $PKG | xargs file | grep -e "executable" -e "shared object" \ |
---|
| 183 | | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
| 184 | |
---|
| 185 | # Remove some unneeded man pages, and then compress the rest |
---|
| 186 | rm -f $PKG/usr/man/man1/{dlltool,windres}.1 |
---|
| 187 | ( cd $PKG/usr/man |
---|
| 188 | find . -type f -exec gzip -9 {} \; |
---|
| 189 | for i in $(find . -type l) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done |
---|
| 190 | ) |
---|
| 191 | |
---|
| 192 | # Compress info pages |
---|
| 193 | rm -f $PKG/usr/info/dir |
---|
| 194 | gzip -9 $PKG/usr/info/* |
---|
| 195 | |
---|
| 196 | mkdir -p $PKG/usr/doc/binutils-$VERSION |
---|
| 197 | cp \ |
---|
| 198 | COPYING* MAI* README* \ |
---|
| 199 | $PKG/usr/doc/binutils-$VERSION |
---|
| 200 | |
---|
| 201 | # If there's a ChangeLog, installing at least part of the recent history |
---|
| 202 | # is useful, but don't let it get totally out of control: |
---|
| 203 | if [ -r ChangeLog ]; then |
---|
| 204 | DOCSDIR=$(echo $PKG/usr/doc/*-$VERSION) |
---|
| 205 | cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog |
---|
| 206 | touch -r ChangeLog $DOCSDIR/ChangeLog |
---|
| 207 | fi |
---|
| 208 | |
---|
| 209 | chown -R root:root $PKG/usr/doc/binutils-$VERSION |
---|
| 210 | |
---|
| 211 | # Add slack-desc: |
---|
| 212 | mkdir -p $PKG/install |
---|
| 213 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
| 214 | |
---|
| 215 | cd $PKG |
---|
| 216 | /sbin/makepkg -l y -c n $TMP/binutils-$VERSION-$ARCH-$BUILD.txz |
---|
| 217 | |
---|
| 218 | cat << EOF |
---|
| 219 | |
---|
| 220 | ############################# |
---|
| 221 | oprofile links to libbfd so |
---|
| 222 | be sure to recompile that |
---|
| 223 | ############################# |
---|
| 224 | |
---|
| 225 | EOF |
---|