whitebox-tools.SlackBuild 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash
  2. # Slackware build script for whitebox-tools
  3. # Copyright 2019-2021 Benjamin Trigona-Harany <slackbuilds@jaxartes.net>
  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. cd $(dirname $0) ; CWD=$(pwd)
  23. PRGNAM=whitebox-tools
  24. BINNAM=`echo $PRGNAM | tr - _`
  25. VERSION=${VERSION:-1.5.0}
  26. BUILD=${BUILD:-1}
  27. TAG=${TAG:-_SBo}
  28. PKGTYPE=${PKGTYPE:-tgz}
  29. if [ -z "$ARCH" ]; then
  30. case "$( uname -m )" in
  31. i?86) ARCH=i586 ;;
  32. arm*) ARCH=arm ;;
  33. *) ARCH=$( uname -m ) ;;
  34. esac
  35. if [ "$ARCH" = "i586" ]; then
  36. if rustc -Vv | grep host | grep i686 > /dev/null ; then
  37. ARCH=i686
  38. fi
  39. fi
  40. fi
  41. # If the variable PRINT_PACKAGE_NAME is set, then this script will report what
  42. # the name of the created package would be, and then exit. This information
  43. # could be useful to other scripts.
  44. if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  45. echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  46. exit 0
  47. fi
  48. TMP=${TMP:-/tmp/SBo}
  49. PKG=$TMP/package-$PRGNAM
  50. OUTPUT=${OUTPUT:-/tmp}
  51. if [ "$ARCH" = "i586" ]; then
  52. SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  53. LIBDIRSUFFIX=""
  54. CARGOTARGET="--target i586-unknown-linux-gnu"
  55. elif [ "$ARCH" = "i686" ]; then
  56. SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  57. LIBDIRSUFFIX=""
  58. CARGOTARGET="--target i686-unknown-linux-gnu"
  59. elif [ "$ARCH" = "x86_64" ]; then
  60. SLKCFLAGS="-O2 -fPIC"
  61. LIBDIRSUFFIX="64"
  62. CARGOTARGET="--target x86_64-unknown-linux-gnu"
  63. else
  64. SLKCFLAGS="-O2"
  65. LIBDIRSUFFIX=""
  66. CARGOTARGET=""
  67. fi
  68. set -e
  69. rm -rf $PKG
  70. mkdir -p $TMP $PKG $OUTPUT
  71. cd $TMP
  72. rm -rf $PRGNAM-$VERSION
  73. tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
  74. cd $PRGNAM-$VERSION
  75. # build offline
  76. # configuration tells cargo to use the configured directory
  77. # for dependencies intead of downloading from crates.io
  78. mkdir .cargo
  79. cat << EOF >> .cargo/config
  80. [source.crates-io]
  81. registry = 'https://github.com/rust-lang/crates.io-index'
  82. replace-with = 'vendored-sources'
  83. [source.vendored-sources]
  84. directory = '$(pwd)/vendor'
  85. EOF
  86. # deps and versions come from Cargo.lock
  87. mkdir vendor
  88. (
  89. cd vendor
  90. grep -h -A 3 "\[\[package\]\]" $(find ../ -maxdepth 1 -mindepth 1 -name Cargo.lock | tr '\n' ' ') | \
  91. sed 's/[[:space:]]*=[[:space:]]*/=/g;s/^--//;s/^\[\[/--\n[[/' | \
  92. awk 'BEGIN { RS = "--\n" ; FS="\n" } { print $2, $3, $4 }' | sed 's/"//g;s/name=//;s/ version=/=/' | \
  93. grep crates\.io-index | sed 's/ source=.*$//' | sort -u | while read -r dep ; do
  94. ver="$(printf "%s\n" "$dep" | cut -d= -f2)"
  95. dep="$(printf "%s\n" "$dep" | cut -d= -f1)"
  96. tar xvf $CWD/$dep-$ver.crate
  97. touch $dep-$ver/.cargo-ok
  98. # generate checksum
  99. {
  100. printf "{\n"
  101. printf ' "files": {\n'
  102. (
  103. cd $dep-$ver
  104. find . -type f -print0 | xargs -0 sha256sum | sed -n '/\.cargo-checksum\.json/!p' | sed 's/\.\///;s/^\([^ ]*\)[[:space:]][[:space:]]*\(.*\)$/"\2":"\1",/'
  105. ) | sed '$ s/,$//'
  106. printf " },\n"
  107. printf ' "package": "'
  108. sha256sum "$CWD/$dep-$ver.crate" | cut -f1 -d' ' | sed 's/$/"/'
  109. printf "}\n"
  110. } | python -c "import sys, json; data = sys.stdin.read(); print json.dumps(json.loads(data), sort_keys=True, indent=4, separators=(',', ' : '))" > $dep-$ver/.cargo-checksum.json
  111. done
  112. )
  113. chown -R root:root .
  114. find -L . \
  115. \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  116. -o -perm 511 \) -exec chmod 755 {} \; -o \
  117. \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  118. -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
  119. CARGO_HOME=.cargo \
  120. CFLAGS="$SLKCFLAGS" \
  121. CXXFLAGS="$SLKCFLAGS" \
  122. cargo build --offline --release $CARGOTARGET
  123. mkdir -p $PKG/usr/bin/
  124. find target -name $BINNAM -exec install -m 755 {} $PKG/usr/bin/$BINNAM \;
  125. find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  126. | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  127. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  128. cp -a -r \
  129. LICENSE.txt README.md readme.txt \
  130. $PKG/usr/doc/$PRGNAM-$VERSION
  131. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  132. mkdir -p $PKG/install
  133. cat $CWD/slack-desc > $PKG/install/slack-desc
  134. cd $PKG
  135. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE