| 1 | #!/bin/sh |
| 2 | # Copyright 2020 Danilo 'danix' Macrì < danix@danix.xyz > |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use of this script, with or without modification, is |
| 6 | # permitted provided that the following conditions are met: |
| 7 | # |
| 8 | # 1. Redistributions of this script must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # |
| 11 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 12 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 13 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 14 | # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 15 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 16 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 17 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 18 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 19 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 20 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 21 | |
| 22 | # Adapted from the lxqt modular build from Eric Hameleers <alien@slackware.com> |
| 23 | |
| 24 | ### Run this script as lxqt.SlackBuild <program> to build the pkg "program" |
| 25 | |
| 26 | set -e |
| 27 | |
| 28 | # Set initial variables: |
| 29 | CWD=$(pwd) |
| 30 | TMP=${TMP:-/tmp} |
| 31 | BUILD_DIR=${BUILD_DIR:-$TMP/lxqt-build} |
| 32 | |
| 33 | # some useful functions |
| 34 | fix_perms() { |
| 35 | target_dir=$1 |
| 36 | [ -z "$target_dir" ] && target_dir='.' |
| 37 | |
| 38 | chown -R root:root $target_dir |
| 39 | find $target_dir \ |
| 40 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
| 41 | -exec chmod 755 {} \; -o \ |
| 42 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
| 43 | -exec chmod 644 {} \; |
| 44 | } |
| 45 | |
| 46 | strip_binaries() { |
| 47 | target_dir=$1 |
| 48 | [ -z "$target_dir" ] && target_dir='.' |
| 49 | |
| 50 | find $target_dir | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
| 51 | find $target_dir | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
| 52 | find $target_dir | xargs file | grep "current ar archive" | grep ELF | cut -f 1 -d : | xargs strip -g 2> /dev/null |
| 53 | } |
| 54 | |
| 55 | process_man_pages() { |
| 56 | # Compress and if needed symlink the man pages: |
| 57 | if [ -d usr/man ]; then |
| 58 | ( cd usr/man |
| 59 | for manpagedir in $(find . -type d -name "man*") ; do |
| 60 | ( cd $manpagedir |
| 61 | for eachpage in $( find . -type l -maxdepth 1) ; do |
| 62 | ln -s $( readlink $eachpage ).gz $eachpage.gz |
| 63 | rm $eachpage |
| 64 | done |
| 65 | gzip -9 *.* || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; } |
| 66 | ) |
| 67 | done |
| 68 | ) |
| 69 | fi |
| 70 | } |
| 71 | |
| 72 | process_info_pages() { |
| 73 | # Compress info pages and purge "dir" file from the package: |
| 74 | if [ -d usr/info ]; then |
| 75 | ( cd usr/info |
| 76 | rm -f dir |
| 77 | gzip -9 * |
| 78 | ) |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | no_usr_share_doc() { |
| 83 | # If there are docs, move them: |
| 84 | if [ -d usr/share/doc ]; then |
| 85 | mkdir -p usr/doc |
| 86 | mv usr/share/doc/* usr/doc |
| 87 | rmdir usr/share/doc |
| 88 | fi |
| 89 | } |
| 90 | |
| 91 | PROGRAM=$1 |
| 92 | SOURCE=$PROGRAM |
| 93 | if [[ $PROGRAM == 'libfm-extra' ]]; then |
| 94 | SOURCE='libfm' |
| 95 | fi |
| 96 | VERSION=${VERSION:-0.16.0} |
| 97 | PKG="$BUILD_DIR/package-${PROGRAM}" |
| 98 | |
| 99 | # Import the build configuration options for as far as they are not already set: |
| 100 | [ -r ./lxqt.options ] && . ./lxqt.options |
| 101 | |
| 102 | # This avoids compiling a version number into LXQT's .la files: |
| 103 | QTDIR=/usr/lib${LIBDIRSUFFIX}/qt ; export QTDIR |
| 104 | |
| 105 | # Reset $PKGARCH to its initial value: |
| 106 | PKGARCH=$ARCH |
| 107 | # Perhaps $PKGARCH should be something different: |
| 108 | if grep -wq "^${PROGRAM}$" ${CWD}/noarch ; then |
| 109 | PKGARCH=noarch |
| 110 | fi |
| 111 | |
| 112 | rm -rf "$PKG" "$TMP/${PROGRAM}-$VERSION" |
| 113 | |
| 114 | cd "$TMP" |
| 115 | cp -R ${CWD}/src/${SOURCE} $TMP/${PROGRAM}-$VERSION |
| 116 | cd "${PROGRAM}"-$VERSION |
| 117 | |
| 118 | fix_perms |
| 119 | |
| 120 | # If any patches are needed, call this script to apply them: |
| 121 | if [ -r $CWD/patch/${PROGRAM}.patch ]; then |
| 122 | . $CWD/patch/${PROGRAM}.patch || exit 1 |
| 123 | fi |
| 124 | |
| 125 | # Check autotools builds before continuing with cmake programs |
| 126 | if [ -r $CWD/autotools/${PROGRAM} ]; then |
| 127 | echo "sourcing autotools settings for $PROGRAM" |
| 128 | . $CWD/autotools/${PROGRAM} |
| 129 | else |
| 130 | if [ -r $CWD/cmake/${PROGRAM} ]; then |
| 131 | echo "sourcing cmake settings for $PROGRAM" |
| 132 | . $CWD/cmake/${PROGRAM} |
| 133 | else |
| 134 | # This is the default configure script: |
| 135 | echo "setting generic cmake for $PROGRAM" |
| 136 | . $CWD/cmake/cmake |
| 137 | fi |
| 138 | fi |
| 139 | |
| 140 | make $NUMJOBS || make || exit 1 |
| 141 | make install DESTDIR=$PKG || exit 1 |
| 142 | |
| 143 | # Get rid of zero-length junk files: |
| 144 | find $PKG/usr/doc/${PROGRAM}-$VERSION -type f -size 0 -exec rm --verbose "{}" \; || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; } |
| 145 | rmdir --verbose $PKG/usr/doc/${PROGRAM}-$VERSION 2> /dev/null || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; } |
| 146 | |
| 147 | # Strip binaries: |
| 148 | strip_binaries || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; } |
| 149 | |
| 150 | # If there's any special post-install things to do, do them: |
| 151 | if [ -r $CWD/post-install/${PROGRAM}.post-install ]; then |
| 152 | . $CWD/post-install/${PROGRAM}.post-install |
| 153 | fi |
| 154 | |
| 155 | # If this package requires some doinst.sh material, add it here: |
| 156 | if [ -r $CWD/doinst.sh/${PROGRAM} ]; then |
| 157 | mkdir -p $PKG/install |
| 158 | cat $CWD/doinst.sh/${PROGRAM} \ |
| 159 | | sed -e "s#usr/lib#usr/lib${LIBDIRSUFFIX}#g" \ |
| 160 | >> $PKG/install/doinst.sh |
| 161 | fi |
| 162 | |
| 163 | cd $PKG |
| 164 | process_man_pages |
| 165 | process_info_pages |
| 166 | no_usr_share_doc |
| 167 | mkdir -p $PKG/install |
| 168 | if [ -r $CWD/slack-desc/${PROGRAM} ]; then |
| 169 | cat $CWD/slack-desc/${PROGRAM} > $PKG/install/slack-desc |
| 170 | else |
| 171 | touch $PKG/install/slack-desc-missing |
| 172 | fi |
| 173 | |
| 174 | /sbin/makepkg -l y -c n "$BUILD_DIR/${PROGRAM}-$VERSION-$PKGARCH-$BUILD$TAG.txz" |