rubygem-template.SlackBuild 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. # Slackware build script for <appname>
  3. # Copyright <year> <you> <where you live>
  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. # REMOVE THIS ENTIRE BLOCK OF TEXT #
  24. #
  25. # A license is required, and we strongly suggest you use the above
  26. # BSD/MIT style license. We DO NOT accept "Public Domain" scripts.
  27. # Public domain is not valid in some countries, and no license is
  28. # worse than a "bad" license in those countries.
  29. #
  30. # This template is not meant to be a 'cut and paste' script to
  31. # enable any random user to make a working package. While
  32. # we're certainly not discouraging use of this template, if
  33. # you haven't manually gone through each step of the process
  34. # without the build script (typically as a normal user, as this
  35. # will reveal problems that you won't see as root), then there's
  36. # a good chance that something important is missing from your
  37. # submission.
  38. # When using this template script, please remove as many of
  39. # these unnecessary comments as possible. Commented code is
  40. # a good thing, but if it's obvious, there's no need to comment it.
  41. #
  42. # AGAIN, REMOVE THE COMMENTS IF THEY ARE NOT NEEDED - DON'T JUST
  43. # DELETE THIS BLOCK OF TEXT WITHOUT BOTHERING TO READ WHAT'S IN IT.
  44. #
  45. # |-----------------------------------------------------------------| #
  46. PRGNAM=rubygem-appname # replace 'appname' with name of gem
  47. VERSION=${VERSION:-1.4.1} # replace with version of program
  48. BUILD=${BUILD:-1}
  49. TAG=${TAG:-_SBo} # the "_SBo" is required
  50. SRCNAM=appname # replace with name of gem
  51. # Automatically determine the architecture we're building on:
  52. if [ -z "$ARCH" ]; then
  53. case "$( uname -m )" in
  54. i?86) ARCH=i586 ;;
  55. arm*) ARCH=arm ;;
  56. # Unless $ARCH is already set, use uname -m for all other archs:
  57. *) ARCH=$( uname -m ) ;;
  58. esac
  59. fi
  60. CWD=$(pwd)
  61. TMP=${TMP:-/tmp/SBo} # For consistency's sake, use this
  62. PKG=$TMP/package-$PRGNAM
  63. OUTPUT=${OUTPUT:-/tmp} # Drop the package in /tmp
  64. if [ "$ARCH" = "i586" ]; then
  65. SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  66. LIBDIRSUFFIX=""
  67. elif [ "$ARCH" = "i686" ]; then
  68. SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  69. LIBDIRSUFFIX=""
  70. elif [ "$ARCH" = "x86_64" ]; then
  71. SLKCFLAGS="-O2 -fPIC"
  72. LIBDIRSUFFIX="64"
  73. else
  74. SLKCFLAGS="-O2"
  75. LIBDIRSUFFIX=""
  76. fi
  77. set -e
  78. rm -rf $PKG
  79. mkdir -p $TMP $PKG $OUTPUT
  80. cd $TMP
  81. # Get the full path of the ruby installation, for gems
  82. DESTDIR=$( ruby -r rbconfig -e '
  83. include RbConfig
  84. printf("%s/%s/gems/%s\n",
  85. CONFIG["libdir"],
  86. CONFIG["RUBY_INSTALL_NAME"],
  87. CONFIG["ruby_version"]
  88. )
  89. ')
  90. # print a friendly warning of unsatisfied ":runtime" dependencies
  91. # good to leave in place, even if the gem doesn't have any dependencies.
  92. # things could always change
  93. gem specification $CWD/$SRCNAM-$VERSION.gem | \
  94. ruby -r yaml -r rbconfig -e '
  95. c = RbConfig::CONFIG
  96. path = sprintf("%s/%s/gems/%s",
  97. c["libdir"],
  98. c["RUBY_INSTALL_NAME"],
  99. c["ruby_version"])
  100. sys_gemspecs = Dir.glob(path + "/specifications/**/*.gemspec").map {|g| gs = Gem::Specification.load(g); gs.name }
  101. obj = Gem::Specification.from_yaml($stdin)
  102. obj.dependencies.each {|dep|
  103. if not(dep.type == :runtime)
  104. next
  105. end
  106. if not(sys_gemspecs.include?(dep.name))
  107. $stderr.write("WARNING: #{dep.name} gem not found\n")
  108. sleep 0.5
  109. end
  110. }'
  111. gem install \
  112. --local \
  113. --no-update-sources \
  114. --ignore-dependencies \
  115. --backtrace \
  116. --install-dir $PKG/$DESTDIR \
  117. --bindir $PKG/usr/bin \
  118. $CWD/$SRCNAM-$VERSION.gem
  119. # Strip binaries and libraries.
  120. find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  121. | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  122. # Remove cached gem from install, if you are so inspired ..
  123. #rm -rf $PKG/$DESTDIR/cache
  124. # Copy program documentation into the package
  125. # The included documentation varies from one application to another, so be sure
  126. # to adjust your script as needed
  127. # Also, include the SlackBuild script in the documentation directory
  128. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  129. tar -x -O --file=$CWD/$SRCNAM-$VERSION.gem data.tar.gz \
  130. | tar -xz -C $PKG/usr/doc/$PRGNAM-$VERSION --file=- \
  131. <documentation>
  132. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  133. # Copy the slack-desc (and a custom doinst.sh if necessary) into ./install
  134. mkdir -p $PKG/install
  135. cat $CWD/slack-desc > $PKG/install/slack-desc
  136. cat $CWD/doinst.sh > $PKG/install/doinst.sh
  137. # Make the package; be sure to leave it in $OUTPUT
  138. # If package symlinks need to be created during install *before*
  139. # your custom contents of doinst.sh runs, then add the -p switch to
  140. # the makepkg command below -- see makepkg(8) for details
  141. cd $PKG
  142. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}