summaryrefslogtreecommitdiffstats
path: root/system/mksh/mksh.SlackBuild
blob: ae3909e33e3cba4957f39fcb19b2d6d6b85ad267 (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 mksh

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

# Original author: Markus Reichelt, Aachen, DE
# Now maintained by B. Watson <urchlay@slackware.uk>

# 20230706 bkw:
# - only run test.sh if both stdin and stdout are TTYs.

# 20230102 bkw: BUILD=2
# - take over maintenance.
# - relicense as WTFPL.
# - install FAQ.htm, not mksh.faq.
# - make the test suite optional (but default to enabled).
# - simplify the build script.
# - make the slack-desc show the build options.

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

PRGNAM=mksh
VERSION=${VERSION:-R59c}
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="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

set -e

CC="gcc"
SLKCFLAGS="${SLKCFLAGS} -Wall"

# 20230102 bkw: fail if user passes both DIET=yes and MUSL=yes.
if [ "$DIET" = "yes" -a "$MUSL" = "yes" ]; then
  echo "$( basename $0 ): cannot combine DIET=yes with MUSL=yes." 1>&2
  exit 1
fi

if [ "$DIET" = "yes" ]; then
  # no need to log out & back in after installing dietlibc.
  source /etc/profile.d/dietlibc.sh
  CC="diet -Os gcc"
  # diet builds are always static
  STATIC=yes
  BUILDOPTS+="DIET=yes "
elif [ "$MUSL" = "yes" ]; then
  CC="musl-gcc"
  BUILDOPTS+="MUSL=yes "
fi

if [ "$STATIC" = "yes" ]; then
  LDFLAGS="${LDFLAGS} -static"
  CPPFLAGS="${CPPFLAGS} -DMKSH_NOPWNAM"
  BUILDOPTS+="STATIC=yes "
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM
tar xvf $CWD/$PRGNAM-$VERSION.tgz
cd $PRGNAM

chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

# 20230706 bkw: only run test.sh if stdin and stdout are TTYs, to avoid
# the test script hanging forever.
T=no
[ -t 0 -a -t 1 ] && T=yes
TESTS=${TESTS:-$T}
echo "=== run tests? $TESTS"

LDFLAGS="$LDFLAGS" \
CPPFLAGS="$CPPFLAGS" \
CFLAGS="$SLKCFLAGS" \
CC="$CC" \
  sh Build.sh -r

# make sure tests pass whether there is a controlling tty or not. There are
# some changes related to this in CVS, so this can probably be removed with the
# next release.
# thanks alpine maintainers.
# 20230102 bkw: make tests optional with TESTS=no. This is a maintainer-mode
# option (saves me time if I'm repeatedly editing/running the script).
if [ "$TESTS" = "yes" ]; then
  sed -i -e '/^name: selftest-tty-absent$/,/^---$/d' check.t
  ./test.sh -C regress:no-ctty
fi

# 20230102 bkw: turns mksh.faq into proper HTML (FAQ.htm).
sh FAQ2HTML.sh

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKGDOC $PKG/{bin,usr/man/man1,etc/skel,install}

install -m 755 -s mksh       $PKG/bin
install -m 644    dot.mkshrc $PKG/etc/skel/.mkshrc.new
install -m 644    dot.mkshrc $PKGDOC
install -m 644    FAQ.htm    $PKGDOC

for i in mksh lksh; do
  gzip -9c < $i.1 > $PKG/usr/man/man1/$i.1.gz
done

cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

cat $CWD/slack-desc > $PKG/install/slack-desc
[ -n "$BUILDOPTS" ] && \
  sed -i "15s,\$, Build options: $BUILDOPTS," $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

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