Apologies for commenting to my own posting.
The script below will both compile Lazarus v2 or v3 from scratch, or once a configuration directory exists will recompile it for multiple widget sets (subject obviously to library compatibility etc.)
#!/bin/sh
# Build the Lazarus IDE with extra installed packages. The suffix is what is
# after the - in the binary and configuration directories, so if the directory
# is e.g. /usr/local/share/lazarus-2.2.6+3.2.2 it is 2.2.6+3.2.2 .
# PREREQUISITE: The FPC compiler's PPC symlink points to the correct version.
SUFFIX=newstable
# set -x
make distclean
make LCL_PLATFORM=gtk2 bigide
if [ -d ~/.lazarus-$SUFFIX ]; then
# The --build-ide= option defaults to reading the existing configuration
# directory. Preserve original file ownership etc. if possible.
if lazbuild-$SUFFIX --no-write-project --widgetset=qt5 --add-package lazprojectgroups --build-ide= ; then
cp -p lazarus lazarus-qt5
else
rm -f lazarus-qt5
fi
if lazbuild-$SUFFIX --no-write-project --widgetset=gtk2 --add-package lazprojectgroups --build-ide= ; then
cp -p lazarus lazarus-gtk2
else
rm -f lazarus-gtk2
fi
echo
ls -lt lazarus lazarus-* lazbuild lazbuild-* startlazarus startlazarus-* 2> /dev/null
echo
else
# No configuration directory exists.
echo
echo Run lazarus-$SUFFIX to establish the basic configuration. Do not install
echo any extra packages, or recompile from inside the IDE for any other
echo reason since doing so might mess up the widget set choice.
echo
fi
It assumes that each particular Lazarus variant is stored in a directory such as /usr/local/share.lazarus/lazarus-newstable, and that there's a configuration directory ~/.lazarus-newstable
I wasn't able to work out from the help text, documentation or wiki what sort of parameter --build-ide= expected. In practice, the above suits my requirements.
There's something wrong with rebuilding from inside the IDE when there are multiple widget sets being used, e.g. qt5 and gtk2. Checking with readelf indicates that the lazarus binary correctly indicates with widget set, but rebuilding leaves multiple binaries all using the same widget set (qt5 in my case).
Updated: further-developed script at
https://forum.lazarus.freepascal.org/index.php/topic,67244.msg517129.html#msg517129MarkMLl