aboutsummaryrefslogtreecommitdiff
path: root/audio/flac-opt/flac-opt.SlackBuild
blob: 4f5ec56233158ba24533e166c6d4bed337a1bfaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash

# Slackware build script for flac-opt

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# 20250512 bkw: BUILD=2
# - fix man breakage that occurred if MANPATH wasn't already set
#   when the profile script ran. Thanks to fourtysixandtwo for
#   catching this.

# Notes:
# - Not based on PV's flac.SlackBuild. Started with SBo template.
# - Static libraries, not shared, because they live in a weird prefix.
# - It's possible to export PREFIX=/whatever, but not documented in README
#   because I really don't expect anyone to do this.
# - I include the API docs and examples even though PV leaves them
#   out of his flac package.
# - Encoding really is about 25% faster than Slackware's older flac, even if
#   you don't use the new -j option to run in parallel. With -j8 on my 8-core
#   workstation, it's 4-5x as fast as the old flac.
# - It's possible to build with either autoconf or cmake. I tried both,
#   didn't see any difference. Went with autoconf because it's more
#   familiar. May change in the future, if upstream drops autoconf.
# - I see no advantage to building with -O2 rather than upstream's
#   default -O3, but I added an option to use -O2 if you're that
#   fanatical about using default CFLAGS.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=flac-opt
SRCNAM=flac
VERSION=${VERSION:-1.5.0}
BUILD=${BUILD:-2}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" -o "$ARCH" = "aarch64" ]; then
  SLKCFLAGS="-fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS=""
  LIBDIRSUFFIX=""
fi

# upstream uses -O3, we'll go with that unless the user insists.
COPT=-O3
[ "${FORCE_O2:-no}" = "yes" ] && COPT=-O2
SLKCFLAGS="$COPT $SLKCFLAGS"

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-$VERSION
tar xvf $CWD/$SRCNAM-$VERSION.tar.xz
cd $SRCNAM-$VERSION
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod -h 755 {} + -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod -h 644 {} +

if [ "${ASM:-yes}" = "no" ]; then
  ASMOPT=disable
  WITHASM="WITHOUT"
else
  ASMOPT=enable
  WITHASM="WITH"
fi

PREFIX=${PREFIX:-/opt/$PRGNAM}
DOCDIR=/usr/doc/$PRGNAM-$VERSION
PKGDOC=$PKG/$DOCDIR
LIBDIR=$PREFIX/lib$LIBDIRSUFFIX

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --disable-examples \
  --disable-werror \
  --$ASMOPT-asm-optimizations \
  --prefix=$PREFIX \
  --libdir=$LIBDIR \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=$PREFIX/man \
  --docdir=/usr/doc/$PRGNAM-$VERSION \
  --disable-shared \
  --enable-static \
  --build=$ARCH-slackware-linux

make V=1
make install-strip DESTDIR=$PKG
rm -f $PKG/$PREFIX/lib*/*.la
gzip -9 $PKG/$PREFIX/man/man*/*

PROF=$PKG/etc/profile.d
mkdir -p $PROF
for i in flac-opt.sh flac-opt-dev.sh; do
  sed -e "s,@PREFIX@,$PREFIX,g" -e "s,@LIBDIR@,$LIBDIR,g" $CWD/$i > $PROF/$i
done
chmod 755 $PROF/flac-opt.sh

# pkgconfig needs a bit of help. we do this so callers don't have to
# specify --static as a pkg-config option.
sed -i -e '/^Libs\.private/d' \
       -e '/^Libs:/s,$, -logg -lm,' \
       $PKG/$LIBDIR/pkgconfig/flac.pc

# we didn't build the examples, but include their source in the doc dir.
mkdir -p $PKGDOC
cp -a examples/ AUTHORS *.md COPYING* $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
sed -e "s,@WITHASM@,$WITHASM," \
    -e "s,@PREFIX@,$PREFIX," \
    -e "s,@SLKCFLAGS@,$SLKCFLAGS," \
    $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE