ncspot.SlackBuild 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/bash
  2. # Slackware build script for ncspot
  3. # Copyright 2021-2022 K. Eugene Carlson Tsukuba, Japan
  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=ncspot
  24. VERSION=${VERSION:-0.10.1}
  25. BUILD=${BUILD:-1}
  26. TAG=${TAG:-_SBo}
  27. PKGTYPE=${PKGTYPE:-tgz}
  28. if [ -z "$ARCH" ]; then
  29. case "$( uname -m )" in
  30. i?86) ARCH=i586 ;;
  31. arm*) ARCH=arm ;;
  32. *) ARCH=$( uname -m ) ;;
  33. esac
  34. if [ "$ARCH" = "i586" ]; then
  35. if rustc -Vv | grep host | grep i686 > /dev/null ; then
  36. ARCH=i686
  37. fi
  38. fi
  39. fi
  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 "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  45. exit 0
  46. fi
  47. TMP=${TMP:-/tmp/SBo}
  48. PKG=$TMP/package-$PRGNAM
  49. OUTPUT=${OUTPUT:-/tmp}
  50. if [ "$ARCH" = "i586" ]; then
  51. SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  52. CARGOTARGET="--target i586-unknown-linux-gnu"
  53. elif [ "$ARCH" = "i686" ]; then
  54. SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  55. CARGOTARGET="--target i686-unknown-linux-gnu"
  56. elif [ "$ARCH" = "x86_64" ]; then
  57. SLKCFLAGS="-O2 -fPIC"
  58. CARGOTARGET="--target x86_64-unknown-linux-gnu"
  59. else
  60. SLKCFLAGS="-O2"
  61. CARGOTARGET=""
  62. fi
  63. unset DRAWCOVER
  64. # Use COVERS=yes to compile ncspot with cover-drawing capabilities. Requires
  65. # ueberzug.
  66. [ ${COVERS:-no} = yes ] && DRAWCOVER="--features cover"
  67. set -e
  68. rm -rf $PKG
  69. mkdir -p $TMP $PKG $OUTPUT
  70. cd $TMP
  71. rm -rf $PRGNAM-$VERSION
  72. tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
  73. cd $PRGNAM-$VERSION
  74. # For cargo-1.58 incompatibilities
  75. patch -p1 < $CWD/cargo-lock-$VERSION.patch
  76. # build offline
  77. # configuration tells cargo to use the configured directory
  78. # for dependencies instead of downloading from crates.io
  79. mkdir .cargo
  80. cat << EOF >> .cargo/config
  81. [source.crates-io]
  82. registry = 'https://github.com/rust-lang/crates.io-index'
  83. replace-with = 'vendored-sources'
  84. [source.vendored-sources]
  85. directory = '$(pwd)/vendor'
  86. EOF
  87. # deps and versions come from Cargo.lock
  88. mkdir vendor
  89. (
  90. cd vendor
  91. grep -h -A 3 "\[\[package\]\]" $(find ../ -maxdepth 1 -mindepth 1 -name Cargo.lock | tr '\n' ' ') | \
  92. sed 's/[[:space:]]*=[[:space:]]*/=/g;s/^--//;s/^\[\[/--\n[[/' | \
  93. awk 'BEGIN { RS = "--\n" ; FS="\n" } { print $2, $3, $4 }' | sed 's/"//g;s/name=//;s/ version=/=/' | \
  94. grep crates\.io-index | sed 's/ source=.*$//' | sort -u | while read -r dep ; do
  95. ver="$(printf "%s\n" "$dep" | cut -d= -f2)"
  96. dep="$(printf "%s\n" "$dep" | cut -d= -f1)"
  97. tar xvf $CWD/$dep-$ver.crate
  98. touch $dep-$ver/.cargo-ok
  99. # generate checksum
  100. {
  101. printf "{\n"
  102. printf ' "files": {\n'
  103. (
  104. cd $dep-$ver
  105. find . -type f -print0 | xargs -0 sha256sum | sed -n '/\.cargo-checksum\.json/!p' | sed 's/\.\///;s/^\([^ ]*\)[[:space:]][[:space:]]*\(.*\)$/"\2":"\1",/'
  106. ) | sed '$ s/,$//'
  107. printf " },\n"
  108. printf ' "package": "'
  109. sha256sum "$CWD/$dep-$ver.crate" | cut -f1 -d' ' | sed 's/$/"/'
  110. printf "}\n"
  111. } > $dep-$ver/.cargo-checksum.json
  112. done
  113. )
  114. chown -R root:root .
  115. find -L . \
  116. \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  117. -o -perm 511 \) -exec chmod 755 {} \; -o \
  118. \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  119. -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
  120. CARGO_HOME=.cargo \
  121. CFLAGS="$SLKCFLAGS" \
  122. CXXFLAGS="$SLKCFLAGS" \
  123. cargo build --release $CARGOTARGET $DRAWCOVER
  124. mkdir -p $PKG/usr/bin/
  125. find target -name $PRGNAM -exec install -m 755 {} $PKG/usr/bin/$PRGNAM \;
  126. mkdir -p $PKG/usr/share/applications
  127. install -m 644 misc/$PRGNAM.desktop $PKG/usr/share/applications/
  128. mkdir -p $PKG/usr/share/icons/hicolor/scalable/apps
  129. install -m 644 images/logo.svg $PKG/usr/share/icons/hicolor/scalable/apps/$PRGNAM.svg
  130. find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  131. | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  132. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  133. cp -a LICENSE README.md $PKG/usr/doc/$PRGNAM-$VERSION
  134. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  135. mkdir -p $PKG/install
  136. cat $CWD/slack-desc > $PKG/install/slack-desc
  137. cat $CWD/doinst.sh > $PKG/install/doinst.sh
  138. cd $PKG
  139. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE