Skip to content

Commit 3597111

Browse files
committed
Shell script portability improvements
- support BSD tar(1) - support BSD install(1) - remove dependency on working directory from binutils and gzip build scripts - explicit dependency on GNU make (gmake(1))
1 parent 4fefa30 commit 3597111

3 files changed

Lines changed: 43 additions & 45 deletions

File tree

binutils.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,55 @@ BINUTILS_DL="https://ftp.gnu.org/gnu/binutils"
44
BINUTILS_XZ="binutils-2.38.tar.xz"
55
BINUTILS_DIR="$(basename $BINUTILS_XZ .tar.xz)"
66
BINUTILS_URL="$BINUTILS_DL/$BINUTILS_XZ"
7-
ORIG_DIR="$(pwd)"
7+
ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
88

99
# Dont continue on error.
1010
set -e
1111

1212
# Help text.
1313
if [ "$1" = '-h' ]; then
14-
echo >&2 "Usage: $0 [clean]"
15-
echo >&2
16-
echo >&2 'Specify "clean" to remove binutils, otherwise it will be downloaded and built.'
17-
exit 1
14+
echo >&2 "Usage: $0 [clean]"
15+
echo >&2
16+
echo >&2 'Specify "clean" to remove binutils, otherwise it will be downloaded and built.'
17+
exit 1
1818
fi
1919

2020
# Optional cleanup if requested.
2121
if [ "$1" = 'clean' ]; then
22-
rm -fv objcopy objdump ld "$BINUTILS_XZ"
23-
rm -rfv "$BINUTILS_DIR"
24-
exit
22+
rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld"
23+
rm -rfv "$BINUTILS_DIR"
24+
rm -fv "$ORIGIN_DIR/$BINUTILS_XZ"
25+
exit
2526
fi
2627

2728
# Download binutils.
2829
if [ ! -f "$BINUTILS_XZ" ]; then
29-
wget "$BINUTILS_URL"
30+
wget "$BINUTILS_URL"
3031
fi
3132

3233
# Extract binutils.
3334
if [ ! -d "$BINUTILS_DIR" ]; then
34-
tar xf "$BINUTILS_XZ"
35+
xzcat "$BINUTILS_XZ" | tar xf -
3536
fi
3637

3738
# Compile binutils.
3839
if [ ! -x "$BINUTILS_DIR/binutils/objcopy" ]; then
39-
cd "$BINUTILS_DIR"
40-
./configure --enable-targets=i386-pc-elf32 \
41-
--disable-gas \
42-
--disable-libctf \
43-
--disable-plugins \
44-
--disable-gprof \
45-
--enable-compressed-debug-sections=none
46-
47-
make all-ld -j$(nproc) MAKEINFO=true
40+
cd "$BINUTILS_DIR" && \
41+
./configure --enable-targets=i386-pc-elf32 \
42+
--disable-gas \
43+
--disable-libctf \
44+
--disable-plugins \
45+
--disable-gprof \
46+
--enable-compressed-debug-sections=none && \
47+
gmake all-ld -j$(nproc) MAKEINFO=true
48+
cd "$ORIGIN_DIR"
4849
fi
4950

5051
# Copy compiled binaries to working directory.
5152
copy() {
52-
test ! -x "$2" && cp -v "$1" "$2"
53+
test ! -x "$2" && cp -v "$1" "$2"
5354
}
5455

55-
cd "$ORIG_DIR"
56-
copy "$BINUTILS_DIR/binutils/objcopy" objcopy
57-
copy "$BINUTILS_DIR/binutils/objdump" objdump
58-
copy "$BINUTILS_DIR/ld/ld-new" ld
56+
copy "$BINUTILS_DIR/binutils/objcopy" "$ORIGIN_DIR/objcopy"
57+
copy "$BINUTILS_DIR/binutils/objdump" "$ORIGIN_DIR/objdump"
58+
copy "$BINUTILS_DIR/ld/ld-new" "$ORIGIN_DIR/ld"

extract.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ echo '==> Reconstructing object file'
5050

5151
if ! cat "${LOTUS}"/sysV386/lib/123.o.z_1 "${LOTUS}"/sysV386/lib/123.o.z_2 | zcat > "${ORIG}/123.o"; then
5252
echo >&2 'Failed to decompress object files.'
53-
5453
echo >&2 'If you see the message "code out of range", gzip is too old.'
5554
echo >&2 'You can try running ./gzip.sh to build a recent gzip that is known to work.'
5655
exit 1
@@ -63,10 +62,10 @@ echo '==> Uncompressing and copying remaining object files'
6362
cp "${LOTUS}"/sysV386/lib/*.o "${ORIG}/"
6463

6564
echo '==> Copying the banner template over'
66-
install -vDm644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri"
65+
install -Dm 644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri"
6766

6867
echo '==> Copying default config file'
69-
install -vDm644 l123set.cf "${ETC}/l123set.cf"
68+
install -Dm 644 "l123set.cf" "${ETC}/l123set.cf"
7069

7170
echo '==> Copying man page'
72-
install -vDm644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1"
71+
install -Dm 644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1"

gzip.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,48 @@ GZIP_DL="https://ftp.gnu.org/gnu/gzip"
66
GZIP_XZ="gzip-1.12.tar.xz"
77
GZIP_DIR="$(basename $GZIP_XZ .tar.xz)"
88
GZIP_URL="$GZIP_DL/$GZIP_XZ"
9-
ORIG_DIR="$(pwd)"
9+
ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
1010

1111
# Dont continue on error.
1212
set -e
1313

1414
# Help text.
1515
if [ "$1" = '-h' ]; then
16-
echo >&2 "Usage: $0 [clean]"
17-
echo >&2
18-
echo >&2 'Specify "clean" to remove gzip, otherwise it will be downloaded and built.'
19-
exit 1
16+
echo >&2 "Usage: $0 [clean]"
17+
echo >&2
18+
echo >&2 'Specify "clean" to remove gzip, otherwise it will be downloaded and built.'
19+
exit 1
2020
fi
2121

2222
# Optional cleanup if requested.
2323
if [ "$1" = 'clean' ]; then
24-
rm -fv gzip gunzip zcat "$GZIP_XZ"
25-
rm -rfv "$GZIP_DIR"
26-
exit
24+
rm -fv "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat"
25+
rm -rfv "$GZIP_DIR"
26+
rm -fv "$ORIGIN_DIR/$GZIP_XZ"
27+
exit
2728
fi
2829

2930
# Download gzip.
3031
if [ ! -f "$GZIP_XZ" ]; then
31-
wget "$GZIP_URL"
32+
wget "$GZIP_URL"
3233
fi
3334

3435
# Extract gzip.
3536
if [ ! -d "$GZIP_DIR" ]; then
36-
tar xf "$GZIP_XZ"
37+
xzcat "$GZIP_XZ" | tar xf -
3738
fi
3839

3940
# Compile gzip.
4041
if [ ! -x "$GZIP_DIR/gzip" ]; then
41-
cd "$GZIP_DIR"
42-
./configure
43-
make -j$(nproc)
42+
cd "$GZIP_DIR" && ./configure && gmake -j$(nproc)
43+
cd "$ORIGIN_DIR"
4444
fi
4545

4646
# Copy compiled binaries to working directory.
4747
copy() {
4848
test ! -x "$2" && cp -v "$1" "$2"
4949
}
5050

51-
cd "$ORIG_DIR"
52-
copy "$GZIP_DIR/gzip" gzip
53-
copy "$GZIP_DIR/gunzip" gunzip
54-
copy "$GZIP_DIR/zcat" zcat
51+
copy "$GZIP_DIR/gzip" "$ORIGIN_DIR/gzip"
52+
copy "$GZIP_DIR/gunzip" "$ORIGIN_DIR/gunzip"
53+
copy "$GZIP_DIR/zcat" "$ORIGIN_DIR/zcat"

0 commit comments

Comments
 (0)