mdbook.SlackBuild 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/bash
  2. # Slackware build script for mdBook Rust Tool
  3. # Copyright 2019-2022 Pouria Rezaei <Pouria.rz@outlook.com>
  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. # 20220425 bkw: Modified by SlackBuilds.org, BUILD=2:
  23. # - strip binary.
  24. # - include a couple more doc files.
  25. cd $(dirname $0) ; CWD=$(pwd)
  26. PRGNAM=mdbook
  27. VERSION=${VERSION:-0.4.18}
  28. SRCNAM=mdBook
  29. BUILD=${BUILD:-1}
  30. TAG=${TAG:-_SBo}
  31. PKGTYPE=${PKGTYPE:-tgz}
  32. if [ -z "$ARCH" ]; then
  33. case "$( uname -m )" in
  34. i?86) ARCH=i586 ;;
  35. arm*) ARCH=arm ;;
  36. *) ARCH=$( uname -m ) ;;
  37. esac
  38. if [ "$ARCH" = "i586" ]; then
  39. if rustc -Vv | grep host | grep i686 > /dev/null ; then
  40. ARCH=i686
  41. fi
  42. fi
  43. fi
  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 $SRCNAM-$VERSION
  73. tar xvf $CWD/$SRCNAM-$VERSION.tar.gz
  74. cd $SRCNAM-$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. } > $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 --release $CARGOTARGET
  123. mkdir -p $PKG/usr/bin
  124. find target -name $PRGNAM -exec install -s -m 755 {} $PKG/usr/bin/$PRGNAM \;
  125. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  126. cp -a *.md LICENSE $PKG/usr/doc/$PRGNAM-$VERSION/
  127. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  128. mkdir -p $PKG/install
  129. cat $CWD/slack-desc > $PKG/install/slack-desc
  130. cd $PKG
  131. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE