| git.druid.rocks | index | druid520 | ports | ports/ | textproc/ | gawk/ | add.sh |
ports/textproc/gawk/add.sh
set -e
# https://, not git:// (what this used to be): the plain git protocol
# (port 9418, unencrypted) started failing consistently from this
# environment ("fatal: read error: Connection reset by peer"), while
# https:// to the identical repo works fine -- same class of
# reliability gap as every other port in this tree already avoids by
# using https:// consistently.
git clone https://git.savannah.gnu.org/git/gawk.git
cd gawk
./bootstrap.sh
./configure --prefix=$MP_PREFIX
make CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" -j$MP_JOBS
# -j1: mpx exports MAKEFLAGS=-j$MP_JOBS for the whole script (not just the
# explicit -j above), so this plain "make install" would otherwise still
# inherit it. gawk's doc/ subdir builds several texinfo targets
# (gawk.info, gawkinet.info, gawkworkflow.info, pm-gawk.info) that don't
# fully serialize against each other under real parallelism, and losing
# the race leaves the loser's *.info installed as a 0-byte file instead
# of failing loud -- which only then breaks later, on the NEXT uninstall,
# with "install-info: ...: empty file". -j1 here is explicit, not just
# "no -j", since command-line -j overrides an inherited MAKEFLAGS.
# gawk's own "make install" (below) creates $MP_PREFIX/bin/awk (a plain
# "awk" symlink/wrapper alongside "gawk" itself, standard GNU
# convention) unconditionally, OVERWRITING whatever's already there --
# fine when gawk actually IS this system's own chosen %awk provider,
# but a real, destructive collision with build-tools/onetrueawk's own
# identically-named "awk" binary whenever it isn't (gawk installed
# purely as some OTHER port's own specific, named dependency --
# compilers/gcc's own build genuinely needs real gawk by name,
# "./config.status: line ...: gawk: not found", confirmed directly --
# not just "some %awk provider"). USE=own_awk_symlink (off by default,
# deliberately NOT tied to pkg_tags="awk"'s own pkg_pref ranking, which
# only decides what a bare %awk dependency resolves to, not what's
# actually safe to leave on disk once installed) keeps that symlink
# only when explicitly asked for -- a system whose own chosen %awk
# provider IS gawk turns this on once, globally, the same way any
# other "this port owns the shared name" USE flag works elsewhere in
# this tree (see coreutils/busybox's own shadow/init/awk flags for the
# identical shape of problem, solved the identical way).
#
# backed up with "cp", not moved aside with "mv", before "make install"
# runs -- confirmed the hard way, twice: a plain "rm -f" cleanup AFTER
# install is too late (gawk's own "make install" already overwrote
# whatever was at bin/awk -- onetrueawk's own real binary, if that's
# this system's own chosen provider -- by the time a post-install "rm"
# ever runs, so it only ever deletes GAWK's own freshly-written
# symlink, restoring nothing); moving it OUT of the way first (leaving
# nothing at all on PATH named "awk" during the install) breaks
# something different and worse -- gawk's OWN "make install" itself
# shells out to a bare "awk" as part of installing ITSELF (real,
# reproduced: "/bin/sh: line N: awk: not found" from inside its own
# install-sh/libtool invocations, and the actual gawk binary silently
# never making it into bin/ as a result, despite "make install" still
# reporting overall success). keeping a working "awk" on PATH the
# WHOLE TIME covers gawk's own bootstrapping need for it, and a saved
# COPY (not the moved-away original) is what gets put back afterward.
if [ -z "$USE_own_awk_symlink" ]; then
cp -p $MP_PREFIX/bin/awk /tmp/gawk-add-awk-save 2>/dev/null || true
else
# the opposite problem: gawk's own install-exec-hook is idempotent
# ("if [ ! -f awk ]; then ln -s ... awk; fi") -- it silently does
# NOTHING if anything already exists at bin/awk (onetrueawk's own
# binary, most likely, still installed as gawk's own %awk
# bootstrap pkg_bdepend at this exact point in the build), so
# USE_own_awk_symlink being ON doesn't actually make gawk claim
# "awk" unless that path is genuinely empty first -- confirmed the
# hard way: gawk installed fine, own_awk_symlink was on, and
# bin/awk was STILL onetrueawk's own untouched 452464-byte binary
# afterward, not gawk's. removing whatever's there first forces
# gawk's own hook to actually see an empty slot and create its own.
rm -f $MP_PREFIX/bin/awk
fi
# belt and suspenders for gawk's own "make install" needing "awk" on
# PATH (see above): the backup just above only covers "some awk
# provider was already installed" -- a genuinely from-scratch system
# (nothing named awk anywhere yet) has nothing to back up at all, and
# would hit the exact same "awk: not found" failure installing gawk
# for the very first time. gawk's own freshly-built (not yet
# installed) ./gawk binary from the build step above can stand in for
# itself here -- self-sufficient, no external awk required at all.
mkdir -p /tmp/gawk-install-awk-shim
ln -sf "$PWD/gawk" /tmp/gawk-install-awk-shim/awk
PATH="/tmp/gawk-install-awk-shim:$PATH" make install -j1
rm -rf /tmp/gawk-install-awk-shim
if [ -z "$USE_own_awk_symlink" ]; then
rm -f $MP_PREFIX/bin/awk
# MUST be a real "if", not "[ -f ... ] && mv ..." -- busybox ash
# (this system's own default SHELL) aborts the ENTIRE script the
# moment a bare "&&"/"||" list's own non-last command fails, not
# just skips the rest of that one list (see /etc/mpx.env's own
# identical warning, a real incident there too) -- and "nothing to
# restore" (the common, expected case whenever there was never a
# provider awk here to begin with) is exactly that: [ -f ... ]
# alone returning false under set -e.
if [ -f /tmp/gawk-add-awk-save ]; then
# "cp -p" here too, not "mv": a plain "mv" across filesystems
# (/tmp to $MP_PREFIX/bin, no guarantee they're the same one)
# isn't guaranteed to preserve the original mtime the way
# "cp -p" explicitly does -- confirmed the hard way, a real
# (if survivable) "conflicts with onetrueawk on installed
# files" false positive: the restored file's CONTENT was
# correct (verified directly) but its mtime had shifted to
# "whenever the restore itself ran," which is exactly what
# mp's own snapshot diff (mtime-based, see mplib::db's own
# diff_snapshot comment) treats as "this install changed this
# file," even though nothing about its actual content differs
# from before.
cp -p /tmp/gawk-add-awk-save $MP_PREFIX/bin/awk
rm -f /tmp/gawk-add-awk-save
fi
fi
make clean || true