[f33f781] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Copyright 2017, 2018 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 | cd $(dirname $0) ; CWD=$(pwd) |
---|
| 24 | |
---|
| 25 | PKGNAM=libsodium |
---|
| 26 | VERSION=${VERSION:-$(echo $PKGNAM-*.tar.?z | rev | cut -f 3- -d . | cut -f 1 -d - | rev)} |
---|
| 27 | BUILD=${BUILD:-3} |
---|
| 28 | |
---|
| 29 | # Automatically determine the architecture we're building on: |
---|
| 30 | if [ -z "$ARCH" ]; then |
---|
| 31 | case "$(uname -m)" in |
---|
| 32 | i?86) ARCH=i586 ;; |
---|
| 33 | arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || ARCH=armv7hl ;; |
---|
| 34 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
| 35 | *) ARCH=$(uname -m) ;; |
---|
| 36 | esac |
---|
| 37 | export ARCH |
---|
| 38 | fi |
---|
| 39 | |
---|
| 40 | # If the variable PRINT_PACKAGE_NAME is set, then this script will report what |
---|
| 41 | # the name of the created package would be, and then exit. This information |
---|
| 42 | # could be useful to other scripts. |
---|
| 43 | if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then |
---|
| 44 | echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz" |
---|
| 45 | exit 0 |
---|
| 46 | fi |
---|
| 47 | |
---|
| 48 | NUMJOBS=${NUMJOBS:-" -j$(expr $(nproc) + 1) "} |
---|
| 49 | |
---|
| 50 | if [ "$ARCH" = "i586" ]; then |
---|
| 51 | SLKCFLAGS="-O2 -march=i586 -mtune=i686" |
---|
| 52 | LIBDIRSUFFIX="" |
---|
| 53 | elif [ "$ARCH" = "i686" ]; then |
---|
| 54 | SLKCFLAGS="-O2 -march=i686" |
---|
| 55 | LIBDIRSUFFIX="" |
---|
| 56 | elif [ "$ARCH" = "s390" ]; then |
---|
| 57 | SLKCFLAGS="-O2" |
---|
| 58 | LIBDIRSUFFIX="" |
---|
| 59 | elif [ "$ARCH" = "x86_64" ]; then |
---|
| 60 | SLKCFLAGS="-O2 -fPIC" |
---|
| 61 | LIBDIRSUFFIX="64" |
---|
| 62 | elif [ "$ARCH" = "armv7hl" ]; then |
---|
| 63 | SLKCFLAGS="-O3 -march=armv7-a -mfpu=vfpv3-d16" |
---|
| 64 | LIBDIRSUFFIX="" |
---|
| 65 | else |
---|
| 66 | SLKCFLAGS="-O2" |
---|
| 67 | LIBDIRSUFFIX="" |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | TMP=${TMP:-/tmp} |
---|
| 71 | PKG=$TMP/package-$PKGNAM |
---|
| 72 | |
---|
| 73 | rm -rf $PKG |
---|
| 74 | mkdir -p $TMP $PKG |
---|
| 75 | |
---|
| 76 | cd $TMP |
---|
| 77 | rm -rf $PKGNAM-$VERSION |
---|
| 78 | tar xvf $CWD/$PKGNAM-$VERSION.tar.?z || exit 1 |
---|
| 79 | cd $PKGNAM-$VERSION || exit 1 |
---|
| 80 | |
---|
| 81 | chown -R root:root . |
---|
| 82 | find . \ |
---|
| 83 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
| 84 | -exec chmod 755 {} \+ -o \ |
---|
| 85 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
| 86 | -exec chmod 644 {} \+ |
---|
| 87 | |
---|
| 88 | # Configure: |
---|
| 89 | CFLAGS="$SLKCFLAGS" \ |
---|
| 90 | ./configure \ |
---|
| 91 | --prefix=/usr \ |
---|
| 92 | --sysconfdir=/etc \ |
---|
| 93 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
| 94 | --mandir=/usr/man \ |
---|
| 95 | --infodir=/usr/info \ |
---|
| 96 | --disable-static \ |
---|
| 97 | --build=$ARCH-slackware-linux || exit 1 |
---|
| 98 | |
---|
| 99 | # Build and install: |
---|
| 100 | make $NUMJOBS || make || exit 1 |
---|
| 101 | make install DESTDIR=$PKG || exit 1 |
---|
| 102 | |
---|
| 103 | # Don't ship .la files: |
---|
| 104 | rm -f $PKG/usr/lib${LIBDIRSUFFIX}/*.la |
---|
| 105 | |
---|
| 106 | # Strip binaries: |
---|
| 107 | ( cd $PKG |
---|
| 108 | find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true |
---|
| 109 | find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true |
---|
| 110 | ) || true |
---|
| 111 | |
---|
| 112 | # Add a documentation directory: |
---|
| 113 | mkdir -p $PKG/usr/doc/${PKGNAM}-$VERSION |
---|
| 114 | cp -a \ |
---|
| 115 | AUTHORS ChangeLog COPYING* LICENSE* NEWS README* THANKS TODO \ |
---|
| 116 | $PKG/usr/doc/${PKGNAM}-$VERSION || true |
---|
| 117 | |
---|
| 118 | # Compress and link manpages, if any: |
---|
| 119 | if [ -d $PKG/usr/man ]; then |
---|
| 120 | ( cd $PKG/usr/man |
---|
| 121 | for manpagedir in $(find . -type d -name "man*") ; do |
---|
| 122 | ( cd $manpagedir |
---|
| 123 | for eachpage in $( find . -type l -maxdepth 1 | grep -v '\.gz$') ; do |
---|
| 124 | ln -s $( readlink $eachpage ).gz $eachpage.gz |
---|
| 125 | rm $eachpage |
---|
| 126 | done |
---|
| 127 | gzip -9 *.? |
---|
| 128 | ) |
---|
| 129 | done |
---|
| 130 | ) |
---|
| 131 | fi |
---|
| 132 | |
---|
| 133 | # If there's a ChangeLog, installing at least part of the recent history |
---|
| 134 | # is useful, but don't let it get totally out of control: |
---|
| 135 | if [ -r ChangeLog ]; then |
---|
| 136 | DOCSDIR=$(echo $PKG/usr/doc/${PKGNAM}-$VERSION) |
---|
| 137 | cat ChangeLog | head -n 2000 > $DOCSDIR/ChangeLog |
---|
| 138 | touch -r ChangeLog $DOCSDIR/ChangeLog |
---|
| 139 | fi |
---|
| 140 | |
---|
| 141 | mkdir -p $PKG/install |
---|
| 142 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
| 143 | |
---|
| 144 | cd $PKG |
---|
| 145 | /sbin/makepkg -l y -c n $TMP/$PKGNAM-$VERSION-$ARCH-$BUILD.txz |
---|
| 146 | |
---|