Initial submit of the project. Not yet tested
[lxqt-slackware.git] / lxqt.SlackBuild
CommitLineData
73c8ba7d 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
26set -e
27
28# Set initial variables:
29CWD=$(pwd)
30TMP=${TMP:-/tmp}
31BUILD_DIR=${BUILD_DIR:-$TMP/lxqt-build}
32
33# some useful functions
34fix_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
46strip_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
55process_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
72process_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
82no_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
91PROGRAM=$1
92VERSION=${VERSION:-0.15.0}
93PKG="$BUILD_DIR/package-${PROGRAM}"
94
95# Import the build configuration options for as far as they are not already set:
96[ -r ./lxqt.options ] && . ./lxqt.options
97
98# This avoids compiling a version number into LXQT's .la files:
99QTDIR=/usr/lib${LIBDIRSUFFIX}/qt ; export QTDIR
100
101# Reset $PKGARCH to its initial value:
102PKGARCH=$ARCH
103# Perhaps $PKGARCH should be something different:
104if grep -wq "^${PROGRAM}$" ${CWD}/noarch ; then
105 PKGARCH=noarch
106fi
107
108rm -rf "$PKG" "$TMP/${PROGRAM}-$VERSION"
109
110cd "$TMP"
111cp -R ${CWD}/src/${PROGRAM} $TMP/${PROGRAM}-$VERSION
112cd "${PROGRAM}"-$VERSION
113
114fix_perms
115
116# If any patches are needed, call this script to apply them:
117if [ -r $CWD/patch/${PROGRAM}.patch ]; then
118 . $CWD/patch/${PROGRAM}.patch || exit 1
119fi
120
121# Check autotools builds before continuing with cmake programs
122if [ -r $CWD/autotools/${PROGRAM} ]; then
123 . $CWD/autotools/${PROGRAM}
124else
125 if [ -r $CWD/cmake/${PROGRAM} ]; then
126 . $CWD/cmake/${PROGRAM}
127 else
128 # This is the default configure script:
129 . $CWD/cmake/cmake
130 fi
131fi
132
133make $NUMJOBS || make || exit 1
134make install DESTDIR=$PKG || exit 1
135
136# Get rid of zero-length junk files:
137find $PKG/usr/doc/${PROGRAM}-$VERSION -type f -size 0 -exec rm --verbose "{}" \; || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; }
138rmdir --verbose $PKG/usr/doc/${PROGRAM}-$VERSION 2> /dev/null || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; }
139
140# Strip binaries:
141strip_binaries || { touch ${BUILD_DIR}/${PROGRAM}.failed ; continue ; }
142
143# If there's any special post-install things to do, do them:
144if [ -r $CWD/post-install/${PROGRAM}.post-install ]; then
145. $CWD/post-install/${PROGRAM}.post-install
146fi
147
148# If this package requires some doinst.sh material, add it here:
149if [ -r $CWD/doinst.sh/${PROGRAM} ]; then
150mkdir -p $PKG/install
151cat $CWD/doinst.sh/${PROGRAM} \
152 | sed -e "s#usr/lib#usr/lib${LIBDIRSUFFIX}#g" \
153 >> $PKG/install/doinst.sh
154fi
155
156cd $PKG
157process_man_pages
158process_info_pages
159no_usr_share_doc
160mkdir -p $PKG/install
161if [ -r $CWD/slack-desc/${PROGRAM} ]; then
162 cat $CWD/slack-desc/${PROGRAM} > $PKG/install/slack-desc
163else
164 touch $PKG/install/slack-desc-missing
165fi
166
167/sbin/makepkg -l y -c n "$BUILD_DIR/${PROGRAM}-$VERSION-$PKGARCH-$BUILD$TAG.txz"