J-Link.SlackBuild 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/bash
  2. # Slackware build script for SEGGER J-Link
  3. # Copyright 2021 Andrzej Telszewski, Szczecin
  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=J-Link
  24. VERSION=${VERSION:-7.00a}
  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. fi
  35. # If the variable PRINT_PACKAGE_NAME is set, then this script will report what
  36. # the name of the created package would be, and then exit. This information
  37. # could be useful to other scripts.
  38. if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  39. echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  40. exit 0
  41. fi
  42. TMP=${TMP:-/tmp/SBo}
  43. PKG=$TMP/package-$PRGNAM
  44. OUTPUT=${OUTPUT:-/tmp}
  45. if [ "$ARCH" = "x86_64" ]; then
  46. LIBDIRSUFFIX="64"
  47. else
  48. LIBDIRSUFFIX=""
  49. fi
  50. if [ "$ARCH" != "i586" ] && [ "$ARCH" != "x86_64" ]; then
  51. echo -ne "\n\nError: \"${ARCH}\" architecture is not supported.\n\n"
  52. exit 1
  53. fi
  54. SRCNAM="JLink_Linux_V$(echo $VERSION | tr -d .)"
  55. if [ "$ARCH" = "i586" ]; then
  56. SRCNAM="${SRCNAM}_i386"
  57. else
  58. SRCNAM="${SRCNAM}_${ARCH}"
  59. fi
  60. set -e
  61. rm -rf $PKG
  62. mkdir -p $TMP $PKG $OUTPUT
  63. cd $TMP
  64. rm -rf $PRGNAM-$VERSION
  65. tar xvf $CWD/$SRCNAM.tgz
  66. mv $SRCNAM $PRGNAM-$VERSION
  67. cd $PRGNAM-$VERSION
  68. TREE_MD5=bfc46ffdebe4e426f48d2ad74e1aeb33
  69. UDEV_MD5=048a92be10a5864e558415326001d5e9
  70. TREE_MD5_NEW=( $(find . -not \( -path './x86' -prune \) -not -name 'libjlinkarm.so*' \
  71. -not -name 'libjlinkarm_x86.so*' -not -name 'libQt*' | LC_ALL=C sort | md5sum) )
  72. UDEV_MD5_NEW=( $(md5sum 99-jlink.rules) )
  73. if [ $TREE_MD5 != $TREE_MD5_NEW ] || [ $UDEV_MD5 != $UDEV_MD5_NEW ]; then
  74. if [ $TREE_MD5 != $TREE_MD5_NEW ]; then
  75. printf "\n\tThe directory structure for which this script has been written is different\n"
  76. printf "\tfrom the provided one. Although most probably nothing wrong will happen,\n"
  77. printf "\tit's possible there will be a missing file or a build failure.\n"
  78. fi
  79. if [ $UDEV_MD5 != $UDEV_MD5_NEW ]; then
  80. printf "\n\tThe udev rules found in the provided source are different from the one\n"
  81. printf "\tfor which this script has been written. Although most probably nothing\n"
  82. printf "\twrong will happen, you might run into some device permissions problems.\n"
  83. fi
  84. sleep 5
  85. fi
  86. chown -R root:root .
  87. chmod -R a-st,u+rwX,go-w+rX .
  88. mkdir -p $PKG/opt/J-Link
  89. cp -a Devices ETC GDBServer JFlash* JLink* JMemExe JRunExe JTAGLoadExe libQt* \
  90. $PKG/opt/J-Link
  91. mkdir -p $PKG/usr/bin
  92. # The official J-Link tarball contains executables and soft links to executables
  93. # in the _root_ directory of the tarball. This SlackBuild makes _/opt/J-Link_
  94. # the _root_ directory of the executables and exposes them in _/usr/bin_ with soft links.
  95. find $PKG/opt/J-Link -maxdepth 1 -print0 | xargs -0 file -L | grep -e 'ELF.*executable' | \
  96. cut -f1 -d: | rev | cut -f1 -d/ | rev | while IFS= read -r EXENAME; do
  97. if [ -L $EXENAME ]; then
  98. ln -s /opt/J-Link/$(readlink $EXENAME) $PKG/usr/bin/$EXENAME
  99. else
  100. ln -s /opt/J-Link/$EXENAME $PKG/usr/bin/$EXENAME
  101. fi
  102. done
  103. mkdir -p $PKG/usr/lib$LIBDIRSUFFIX
  104. cp -a libjlinkarm.so* $PKG/usr/lib$LIBDIRSUFFIX
  105. ln -s /usr/lib$LIBDIRSUFFIX/libjlinkarm.so $PKG/opt/J-Link/libjlinkarm.so
  106. mkdir -p $PKG/lib/udev/rules.d
  107. fromdos < 99-jlink.rules > $PKG/lib/udev/rules.d/99-jlink.rules
  108. sed -i 's/SUBSYSTEM!="usb_device"/SUBSYSTEM!="usb"/g' $PKG/lib/udev/rules.d/99-jlink.rules
  109. sed -i -E 's/MODE="0{0,1}666"(, GROUP="dialout"){0,1}/MODE="0664", GROUP="plugdev"/g' \
  110. $PKG/lib/udev/rules.d/99-jlink.rules
  111. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  112. cp -a Doc/* Samples $PKG/usr/doc/$PRGNAM-$VERSION
  113. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  114. mkdir -p $PKG/install
  115. cat $CWD/slack-desc > $PKG/install/slack-desc
  116. cd $PKG
  117. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE