1 | #!/bin/sh |
---|
2 | |
---|
3 | # Copyright 2005-2008, 2009, 2010, 2013 Patrick J. Volkerding, Sebeka, MN, 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 | VERSION=${VERSION:-$(echo file-*.tar.?z* | cut -d - -f 2 | rev | cut -f 3- -d . | rev)} |
---|
24 | BUILD=${BUILD:-1} |
---|
25 | |
---|
26 | NUMJOBS=${NUMJOBS:--j7} |
---|
27 | |
---|
28 | # Automatically determine the architecture we're building on: |
---|
29 | if [ -z "$ARCH" ]; then |
---|
30 | case "$( uname -m )" in |
---|
31 | i?86) export ARCH=i486 ;; |
---|
32 | arm*) export ARCH=arm ;; |
---|
33 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
34 | *) export ARCH=$( uname -m ) ;; |
---|
35 | esac |
---|
36 | fi |
---|
37 | |
---|
38 | if [ "$ARCH" = "i486" ]; then |
---|
39 | SLKCFLAGS="-O2 -march=i486 -mtune=i686" |
---|
40 | LIBDIRSUFFIX="" |
---|
41 | elif [ "$ARCH" = "i686" ]; then |
---|
42 | SLKCFLAGS="-O2 -march=i686 -mtune=i686" |
---|
43 | LIBDIRSUFFIX="" |
---|
44 | elif [ "$ARCH" = "x86_64" ]; then |
---|
45 | SLKCFLAGS="-O2 -fPIC" |
---|
46 | LIBDIRSUFFIX="64" |
---|
47 | else |
---|
48 | SLKCFLAGS="-O2" |
---|
49 | LIBDIRSUFFIX="" |
---|
50 | fi |
---|
51 | |
---|
52 | CWD=$(pwd) |
---|
53 | TMP=${TMP:-/tmp} |
---|
54 | PKG=$TMP/package-file |
---|
55 | |
---|
56 | rm -rf $PKG |
---|
57 | mkdir -p $TMP $PKG |
---|
58 | cd $TMP |
---|
59 | rm -rf file-$VERSION |
---|
60 | tar xvf $CWD/file-$VERSION.tar.?z* || exit 1 |
---|
61 | cd file-$VERSION || exit 1 |
---|
62 | chown -R root:root . |
---|
63 | find . \ |
---|
64 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
65 | -exec chmod 755 {} \; -o \ |
---|
66 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
67 | -exec chmod 644 {} \; |
---|
68 | |
---|
69 | # Make the default data directory /etc/file like it has always been: |
---|
70 | zcat $CWD/file.etc.file.diff.gz | patch -p1 --verbose || exit 1 |
---|
71 | # This is needed after the patch above: |
---|
72 | autoreconf || exit 1 |
---|
73 | |
---|
74 | # Since we're going to include the compiled magic database now (otherwise |
---|
75 | # there seem to be libmagic related crashes), this patch probably doesn't |
---|
76 | # need to be applied. |
---|
77 | # |
---|
78 | ## Don't spew warnings about using the flat text files |
---|
79 | #zcat $CWD/file.quiet.diff.gz | patch -p1 -E --verbose || exit 1 |
---|
80 | |
---|
81 | # Keep the output format for ELF binaries the same as it was in earlier |
---|
82 | # versions of file to avoid breaking existing scripts: |
---|
83 | zcat $CWD/file.short.diff.gz | patch -p1 -E --verbose || exit 1 |
---|
84 | |
---|
85 | # Add zisofs and crda regulatory bin detection |
---|
86 | zcat $CWD/file.zisofs.magic.gz >> magic/Magdir/compress |
---|
87 | zcat $CWD/file.crdaregbin.magic.gz >> magic/Magdir/crdaregbin |
---|
88 | |
---|
89 | CFLAGS="$SLKCFLAGS" \ |
---|
90 | ./configure \ |
---|
91 | --prefix=/usr \ |
---|
92 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
93 | --sysconfdir=/etc \ |
---|
94 | --datadir=/etc \ |
---|
95 | --mandir=/usr/man \ |
---|
96 | --infodir=/usr/info \ |
---|
97 | --docdir=/usr/doc/file-$VERSION \ |
---|
98 | --enable-fsect-man5 \ |
---|
99 | --disable-static \ |
---|
100 | --build=$ARCH-slackware-linux |
---|
101 | |
---|
102 | # The generated $TMP/file-$VERSION/libtool is buggy. I don't know if this is supposed |
---|
103 | # to work, but it certainly does, so... :-) |
---|
104 | cat $(which libtool) > libtool |
---|
105 | |
---|
106 | make $NUMJOBS || make || exit 1 |
---|
107 | make install DESTDIR=$PKG || exit 1 |
---|
108 | |
---|
109 | # Seems --disable-static has been ignored lately: |
---|
110 | rm -f $PKG/usr/lib${LIBDIRSUFFIX}/libmagic.a |
---|
111 | |
---|
112 | # Install the flat files. |
---|
113 | # We'll generate /etc/file/magic.mgc in the doinst.sh. |
---|
114 | rm -f $PKG/etc/file/magic.mgc |
---|
115 | mkdir -p $PKG/etc/file/magic |
---|
116 | cp -a magic/Magdir/* $PKG/etc/file/magic |
---|
117 | |
---|
118 | # Add a script to recompile the flat files in the obvious location. |
---|
119 | # The package install script will compile the flat files initially. |
---|
120 | cp -a $CWD/recompile_magic.mgc.sh.gz $PKG/etc/file |
---|
121 | gzip -d $PKG/etc/file/recompile_magic.mgc.sh.gz |
---|
122 | chown root:root $PKG/etc/file/recompile_magic.mgc.sh |
---|
123 | chmod 755 $PKG/etc/file/recompile_magic.mgc.sh |
---|
124 | |
---|
125 | # IMHO, moving this sort of thing does not make sense. |
---|
126 | # We'll support both the traditional and new locations. |
---|
127 | # I hate to squat on a name as generic as "/etc/misc/", |
---|
128 | # but it wasn't my idea. |
---|
129 | ( cd $PKG/etc ; ln -sf file misc ) |
---|
130 | |
---|
131 | # Strip everything for good measure: |
---|
132 | find $PKG | xargs file | grep -e "executable" -e "shared object" \ |
---|
133 | | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
134 | |
---|
135 | ( cd $PKG/usr/man || exit 1 |
---|
136 | find . -type f -exec gzip -9 {} \; |
---|
137 | for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done |
---|
138 | ) |
---|
139 | |
---|
140 | mkdir -p $PKG/usr/doc/file-$VERSION |
---|
141 | cp -a \ |
---|
142 | AUTHORS COPYING* INSTALL MAINT NEWS README* TODO \ |
---|
143 | $PKG/usr/doc/file-$VERSION |
---|
144 | |
---|
145 | mkdir -p $PKG/install |
---|
146 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
147 | zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh |
---|
148 | |
---|
149 | # Build the package: |
---|
150 | cd $PKG |
---|
151 | /sbin/makepkg -l y -c n $TMP/file-$VERSION-$ARCH-$BUILD.txz |
---|
152 | |
---|