navi.SlackBuild 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. # Slackware build script for dust
  3. # Copyright 2019-2021 Benjamin Trigona-Harany <slackbuilds@jaxartes.net>
  4. # Copyright 2021-2022 Erich Ritz, Jenks, Oklahoma, USA
  5. # All rights reserved.
  6. #
  7. # Redistribution and use of this script, with or without modification, is
  8. # permitted provided that the following conditions are met:
  9. #
  10. # 1. Redistributions of this script must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  14. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. cd $(dirname $0) ; CWD=$(pwd)
  24. PRGNAM=navi
  25. VERSION=${VERSION:-2.20.1}
  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 [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  42. echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  43. exit 0
  44. fi
  45. TMP=${TMP:-/tmp/SBo}
  46. PKG=$TMP/package-$PRGNAM
  47. OUTPUT=${OUTPUT:-/tmp}
  48. if [ "$ARCH" = "i586" ]; then
  49. SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  50. LIBDIRSUFFIX=""
  51. CARGOTARGET="--target i586-unknown-linux-gnu"
  52. elif [ "$ARCH" = "i686" ]; then
  53. SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  54. LIBDIRSUFFIX=""
  55. CARGOTARGET="--target i686-unknown-linux-gnu"
  56. elif [ "$ARCH" = "x86_64" ]; then
  57. SLKCFLAGS="-O2 -fPIC"
  58. LIBDIRSUFFIX="64"
  59. CARGOTARGET="--target x86_64-unknown-linux-gnu"
  60. else
  61. SLKCFLAGS="-O2"
  62. LIBDIRSUFFIX=""
  63. CARGOTARGET=""
  64. fi
  65. set -e
  66. rm -rf $PKG
  67. mkdir -p $TMP $PKG $OUTPUT
  68. cd $TMP
  69. rm -rf $PRGNAM-$VERSION
  70. tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
  71. cd $PRGNAM-$VERSION
  72. # build offline
  73. # configuration tells cargo to use the configured directory
  74. # for dependencies intead of downloading from crates.io
  75. mkdir .cargo
  76. cat << EOF >> .cargo/config.toml
  77. [source]
  78. [source.crates-io]
  79. replace-with = "vendored-sources"
  80. [source.vendored-sources]
  81. directory = "vendor"
  82. EOF
  83. # deps and versions come from Cargo.lock
  84. mkdir vendor
  85. (
  86. cd vendor
  87. grep -h -A 4 "\[\[package\]\]" \
  88. $(find "../" -maxdepth 1 -mindepth 1 -name Cargo.lock | tr '\n' ' ') | \
  89. sed 's/[[:space:]]*=[[:space:]]*/=/g;s/^--//;s/^\[\[/--\n[[/' | \
  90. awk 'BEGIN { RS = "--\n" ; FS="\n" } { print $2, $3, $4, $5 }' | \
  91. sed 's/"//g;s/name=//;s/ version=/=/' | \
  92. grep " source=" | \
  93. sed 's/ dependencies=.*$//' | \
  94. sed 's/ source=[^ ]*//' | \
  95. sed 's/ checksum=/=/' | \
  96. sort -u | \
  97. while read -r dep ; do
  98. cksum="$(printf "%s\n" "$dep" | cut -d= -f3)"
  99. ver="$(printf "%s\n" "$dep" | cut -d= -f2)"
  100. dep="$(printf "%s\n" "$dep" | cut -d= -f1)"
  101. CRATE_FILE=$CWD/$dep-$ver.crate
  102. if [ -z "$cksum" ] ; then
  103. mkdir $dep-$ver
  104. tar xvf $CRATE_FILE -C $dep-$ver --strip-components=1
  105. cksum="null"
  106. else
  107. tar xvf $CRATE_FILE
  108. fi
  109. touch $dep-$ver/.cargo-ok
  110. # generate checksum
  111. {
  112. printf "{\n"
  113. printf ' "files": {\n'
  114. (
  115. cd $dep-$ver
  116. find . -type f -print0 | xargs -0 sha256sum | sed -n '/\.cargo-checksum\.json/!p' | sed 's/\.\///;s/^\([^ ]*\)[[:space:]][[:space:]]*\(.*\)$/"\2":"\1",/'
  117. ) | sed '$ s/,$//'
  118. printf " },\n"
  119. printf ' "package": "%s"' "$cksum"
  120. printf "}\n"
  121. } | 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
  122. done
  123. )
  124. chown -R root:root .
  125. find -L . \
  126. \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  127. -o -perm 511 \) -exec chmod 755 {} \; -o \
  128. \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  129. -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
  130. CARGO_HOME=.cargo \
  131. CFLAGS="$SLKCFLAGS" \
  132. CXXFLAGS="$SLKCFLAGS" \
  133. cargo build --offline --release $CARGOTARGET
  134. find target -name $PRGNAM -exec install -Dm 755 {} $PKG/usr/bin/$PRGNAM \;
  135. find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  136. | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  137. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  138. cp -a -r \
  139. LICENSE README.md docs/* \
  140. $PKG/usr/doc/$PRGNAM-$VERSION
  141. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  142. mkdir -p $PKG/install
  143. cat $CWD/slack-desc > $PKG/install/slack-desc
  144. cd $PKG
  145. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE