1 | #!/bin/sh |
---|
2 | |
---|
3 | # Copyright 2017 Patrick J. Volkerding, Sebeka, Minnesota, USA |
---|
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 | |
---|
24 | PKGNAM=mlocate |
---|
25 | VERSION=${VERSION:-$(echo $PKGNAM-*.tar.xz | rev | cut -f 3- -d . | cut -f 1 -d - | rev)} |
---|
26 | BUILD=${BUILD:-1} |
---|
27 | |
---|
28 | # Automatically determine the architecture we're building on: |
---|
29 | if [ -z "$ARCH" ]; then |
---|
30 | case "$(uname -m)" in |
---|
31 | i?86) ARCH=i586 ;; |
---|
32 | arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || ARCH=armv7hl ;; |
---|
33 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
34 | *) ARCH=$(uname -m) ;; |
---|
35 | esac |
---|
36 | export ARCH |
---|
37 | fi |
---|
38 | |
---|
39 | NUMJOBS=${NUMJOBS:-" -j7 "} |
---|
40 | |
---|
41 | if [ "$ARCH" = "i586" ]; then |
---|
42 | SLKCFLAGS="-O2 -march=i586 -mtune=i686" |
---|
43 | LIBDIRSUFFIX="" |
---|
44 | elif [ "$ARCH" = "i686" ]; then |
---|
45 | SLKCFLAGS="-O2 -march=i686" |
---|
46 | LIBDIRSUFFIX="" |
---|
47 | elif [ "$ARCH" = "s390" ]; then |
---|
48 | SLKCFLAGS="-O2" |
---|
49 | LIBDIRSUFFIX="" |
---|
50 | elif [ "$ARCH" = "x86_64" ]; then |
---|
51 | SLKCFLAGS="-O2 -fPIC" |
---|
52 | LIBDIRSUFFIX="64" |
---|
53 | elif [ "$ARCH" = "armv7hl" ]; then |
---|
54 | SLKCFLAGS="-O3 -march=armv7-a -mfpu=vfpv3-d16" |
---|
55 | LIBDIRSUFFIX="" |
---|
56 | else |
---|
57 | SLKCFLAGS="-O2" |
---|
58 | LIBDIRSUFFIX="" |
---|
59 | fi |
---|
60 | |
---|
61 | CWD=$(pwd) |
---|
62 | TMP=${TMP:-/tmp} |
---|
63 | PKG=$TMP/package-$PKGNAM |
---|
64 | |
---|
65 | rm -rf $PKG |
---|
66 | mkdir -p $TMP $PKG |
---|
67 | |
---|
68 | cd $TMP |
---|
69 | rm -rf $PKGNAM-$VERSION |
---|
70 | tar xvf $CWD/$PKGNAM-$VERSION.tar.xz || exit 1 |
---|
71 | cd $PKGNAM-$VERSION || exit 1 |
---|
72 | |
---|
73 | chown -R root:root . |
---|
74 | find . \ |
---|
75 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
76 | -exec chmod 755 {} \; -o \ |
---|
77 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
78 | -exec chmod 644 {} \; |
---|
79 | |
---|
80 | # Configure: |
---|
81 | CFLAGS="$SLKCFLAGS" \ |
---|
82 | ./configure \ |
---|
83 | --prefix=/usr \ |
---|
84 | --sysconfdir=/etc \ |
---|
85 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
86 | --localstatedir=/var/lib \ |
---|
87 | --mandir=/usr/man \ |
---|
88 | --build=$ARCH-slackware-linux || exit 1 |
---|
89 | |
---|
90 | # Build and install: |
---|
91 | make $NUMJOBS groupname=slocate || make groupname=slocate || exit 1 |
---|
92 | make install DESTDIR=$PKG || exit 1 |
---|
93 | |
---|
94 | mkdir -p $PKG/etc |
---|
95 | cp -a $CWD/updatedb.conf.new $PKG/etc/updatedb.conf.new |
---|
96 | chown root:root $PKG/etc/updatedb.conf.new |
---|
97 | chmod 644 $PKG/etc/updatedb.conf.new |
---|
98 | |
---|
99 | mv $PKG/usr/bin/locate $PKG/usr/bin/mlocate |
---|
100 | ( cd $PKG/usr/bin ; ln -sf mlocate locate ) |
---|
101 | |
---|
102 | ( cd $PKG/usr/man/man1 |
---|
103 | ln -sf locate.1 mlocate.1 |
---|
104 | ) |
---|
105 | |
---|
106 | mkdir -p $PKG/usr/libexec |
---|
107 | cp -a $CWD/mlocate-run-updatedb $PKG/usr/libexec/mlocate-run-updatedb |
---|
108 | chown root:root $PKG/usr/libexec/mlocate-run-updatedb |
---|
109 | chmod 755 $PKG/usr/libexec/mlocate-run-updatedb |
---|
110 | |
---|
111 | mkdir -p $PKG/etc/cron.daily |
---|
112 | cp -a $CWD/mlocate.cron $PKG/etc/cron.daily/mlocate |
---|
113 | chown root:root $PKG/etc/cron.daily/mlocate |
---|
114 | chmod 755 $PKG/etc/cron.daily/mlocate |
---|
115 | |
---|
116 | chown root:slocate $PKG/usr/bin/mlocate |
---|
117 | chmod 2711 $PKG/usr/bin/mlocate |
---|
118 | mkdir -p $PKG/var/lib/mlocate |
---|
119 | chown root:slocate $PKG/var/lib/mlocate |
---|
120 | chmod 750 $PKG/var/lib/mlocate |
---|
121 | |
---|
122 | # Strip binaries: |
---|
123 | ( cd $PKG |
---|
124 | #find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
125 | #find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
126 | ) |
---|
127 | |
---|
128 | # Compress and link manpages, if any: |
---|
129 | if [ -d $PKG/usr/man ]; then |
---|
130 | ( cd $PKG/usr/man |
---|
131 | for manpagedir in $(find . -type d -name "man*") ; do |
---|
132 | ( cd $manpagedir |
---|
133 | for eachpage in $( find . -type l -maxdepth 1 | grep -v '\.gz$') ; do |
---|
134 | ln -s $( readlink $eachpage ).gz $eachpage.gz |
---|
135 | rm $eachpage |
---|
136 | done |
---|
137 | gzip -9 *.? |
---|
138 | ) |
---|
139 | done |
---|
140 | ) |
---|
141 | fi |
---|
142 | |
---|
143 | # Add a documentation directory: |
---|
144 | mkdir -p $PKG/usr/doc/${PKGNAM}-$VERSION |
---|
145 | cp -a \ |
---|
146 | ABOUT-NLS AUTHORS COPYING* ChangeLog INSTALL NEWS README* \ |
---|
147 | $PKG/usr/doc/${PKGNAM}-$VERSION |
---|
148 | |
---|
149 | # If there's a ChangeLog, installing at least part of the recent history |
---|
150 | # is useful, but don't let it get totally out of control: |
---|
151 | if [ -r ChangeLog ]; then |
---|
152 | DOCSDIR=$(echo $PKG/usr/doc/${PKGNAM}-$VERSION) |
---|
153 | cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog |
---|
154 | touch -r ChangeLog $DOCSDIR/ChangeLog |
---|
155 | fi |
---|
156 | |
---|
157 | |
---|
158 | mkdir -p $PKG/install |
---|
159 | zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh |
---|
160 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
161 | |
---|
162 | cd $PKG |
---|
163 | /sbin/makepkg -l y -c n $TMP/$PKGNAM-$VERSION-$ARCH-$BUILD.txz |
---|
164 | |
---|