User Tools

Site Tools


projects:computerbeheer:firefox:build_automation

Firefox release build steps with unity menubar patch

This page describes how to build a firefox release from mozilla sources to get support for the unity menubar.

1. prerequisites

Mozilla firefox depends on the following prerequisites to be installed:

sudo apt-get install python3 python3-dev
sudo apt-get install mercurial

If not done yet, create a system variable containing the absolute path where to store Mozilla Firefox sources, build environment and all related files:

export MOZBUILD_STATE_PATH=YOURPATH
#                          ^^^^^^^^ <-- NB. YOURPATH should end with "/mozilla/"

Use for example: ${HOME}/apps/mozilla/

Issue the following commands to create a system variable and project directory for building firefox:

if ! grep -q MOZBUILD_STATE_PATH ${HOME}/.profile; then
  echo "export MOZBUILD_STATE_PATH=${MOZBUILD_STATE_PATH%/}/" >> $HOME/.profile
  . $HOME/.profile
  [ -d "${MOZBUILD_STATE_PATH%/}/firefox" ] || mkdir -p ${MOZBUILD_STATE_PATH%/}/firefox
fi
cd ${MOZBUILD_STATE_PATH}/firefox

The directory structure for your project will then look something like the following:

../mozilla
   ├── firefox
   │   ├── mozilla-release  <-- clone of mozilla repository, firefox is built from here
   etc.

The MOZBUILD_STATE_PATH variable is used to specify the mozilla top directory in which a firefox directory resides. A python-based bootstrap script which mozilla provides creates per default a clone from their repository https://hg.mozilla.org/mozilla-unified/'. It also helps to setup a mozilla-provided build system (clang-based) within the MOZBUILD_STATE_PATH directory with which firefox can be built.

Since we are interested in checking out from the release repository rather than nightly, it would be possible to either clone from the mozilla-unified first and then from the releases repository, or modify the script to clone from the releases repository directly. This is not supported by Mozilla by default. Instead we need to slightly patch the mozilla supplied bootstrap file which prepares your build setup.

The modified script requires the exact release version tag from the repository as a command line option, which can be found among others with a browser on the following page.

With that it is then possible to specify a custom repository and revision as command line-argument:

(For firefox 103.0.1)

cd 
# Use FIREFOX_103_0_1_RELEASE
FFVER=FIREFOX_103_0_1_RELEASE
wget https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py
wget https://www.auditeon.com/xyz/bootstrap_FIREFOX_103_0_1_RELEASE.patch
patch -s -p1 < bootstrap_FIREFOX_103_0_1_RELEASE.patch
python3 bootstrap.py --no-interactive --vcs hg --application-choice browser --repo-url https://hg.mozilla.org/releases/mozilla-release/ --revision ${FFVER}

After about 40 minutes, depending on the transfer speed, the following message appears:

Executing as root: sudo apt-get install -y build-essential libpython3-dev m4 nodejs unzip uuid zip
[sudo] password for USER:

Enter your user password. The script will now create the build environment in the above mentioned MOZBUILD_STATE_PATH directory. Once done, the directory will look like:

../mozilla
   ├── cbindgen ...
   ├── clang ...
   ├── clang-tools ...
   ├── firefox
   │   ├── mozilla-release
   │   ├── ...
   │   └── unity-menubar.patch
   ├── fix-stacks ...
   ├── minidump_stackwalk ...
   ├── nasm ...
   ├── node ...
   ├── sccache ...
   ├── toolchains ...
   └── _virtualenvs ...

2. Patch and build Firefox

The unity-menubar patch for firefox 103.0.1 has all changes in one single file:

cd ${MOZBUILD_STATE_PATH}/firefox
wget https://gitlab.com/Thaodan/firefox-kde-opensuse/-/raw/master/unity-menubar.patch
patch -d mozilla-release/ -p1 < unity-menubar.patch

Make sure build options for at least the release build and clang compiler are set in the mozconfig file1):

cd ${MOZBUILD_STATE_PATH}/firefox/mozilla-release
# use variable expansion here
echo "# Use the mozilla supplied clang compiler" > mozconfig
echo "CC=${MOZBUILD_STATE_PATH%/}/clang/bin/clang" >> mozconfig
echo "CXX=${MOZBUILD_STATE_PATH%/}/clang/bin/clang++" >> mozconfig
 
cat >> mozconfig << "EOF"
 
# If you have a multicore machine, all cores will be used by default.
 
# If you have installed (or will install) wireless-tools, and you wish
# to use geolocation web services, comment out this line
ac_add_options --disable-necko-wifi
 
# API Keys for geolocation APIs - necko-wifi (above) is required for MLS
# Uncomment the following line if you wish to use Mozilla Location Service
#ac_add_options --with-mozilla-api-keyfile=$PWD/mozilla-key
 
# Uncomment the following line if you wish to use Google's geolocaton API
# (needed for use with saved maps with Google Maps)
#ac_add_options --with-google-location-service-api-keyfile=$PWD/google-key
 
# startup-notification is required since firefox-78
 
# Uncomment the following option if you have not installed PulseAudio
#ac_add_options --disable-pulseaudio
# or uncomment this if you installed alsa-lib instead of PulseAudio
#ac_add_options --enable-alsa
 
# release build
ac_add_options --enable-release
 
# Comment out following options if you have not installed
# recommended dependencies:
# ac_add_options --with-system-libevent
# ac_add_options --with-system-webp
# ac_add_options --with-system-nspr
# ac_add_options --with-system-nss
# ac_add_options --with-system-icu
 
# Do not specify the gold linker which is not the default. It will take
# longer and use more disk space when debug symbols are disabled.
 
# libdavid (av1 decoder) requires nasm. Uncomment this if nasm
# has not been installed.
#ac_add_options --disable-av1
 
# You cannot distribute the binary if you do this
ac_add_options --enable-official-branding
 
# Stripping is now enabled by default.
# Uncomment these lines if you need to run a debugger:
#ac_add_options --disable-strip
#ac_add_options --disable-install-strip
 
# Disabling debug symbols makes the build much smaller and a little
# faster. Comment this if you need to run a debugger. Note: This is
# required for compilation on i686.
ac_add_options --disable-debug-symbols
 
# The elf-hack is reported to cause failed installs (after successful builds)
# on some machines. It is supposed to improve startup time and it shrinks
# libxul.so by a few MB - comment this if you know your machine is not affected.
ac_add_options --disable-elf-hack
 
# The BLFS editors recommend not changing anything below this line:
ac_add_options --prefix=/usr
ac_add_options --enable-application=browser
ac_add_options --disable-crashreporter
 
# disable updater
ac_add_options --disable-updater
ac_add_options --disable-update-channel
 
# enabling the tests will use a lot more space and significantly
# increase the build time, for no obvious benefit.
ac_add_options --disable-tests
 
# The default level of optimization again produces a working build with gcc.
ac_add_options --enable-optimize
 
# ac_add_options --enable-system-ffi
# ac_add_options --enable-system-pixman
 
# --with-system-bz2 was removed in firefox-78
# ac_add_options --without-system-jpeg
# ac_add_options --without-system-png
# ac_add_options --without-system-zlib
 
# The following option unsets Telemetry Reporting. With the Addons Fiasco,
# Mozilla was found to be collecting user's data, including saved passwords and
# web form data, without users consent. Mozilla was also found shipping updates
# to systems without the user's knowledge or permission.
# As a result of this, use the following command to permanently disable
# telemetry reporting in Firefox.
unset MOZ_TELEMETRY_REPORTING
 
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/firefox-build-dir
EOF

Then build with:

cd ${MOZBUILD_STATE_PATH}/firefox/mozilla-release
# optionally to clobber the tree (delete the object directory).
# ./mach clobber
./mach configure
./mach build

After a few hours you should have your firefox build here:

../firefox-build-dir/dist/bin/firefox

3. create a package of firefox

You can make a package of firefox with the following command:

./mach package

The resulting .tar.bz2 package will then be in:

${MOZBUILD_STATE_PATH}/firefox/mozilla-release/firefox-build-dir/dist

4. Extract and install firefox unity

Instead of overwriting a current installation, please remove any old installations of firefox by deleting the /opt/firefox directory.

The archive with firefox unity has been tested for release version 103.0.1 :

Extract this versions to /opt/ by using the following command:

sudo tar xf firefox-103.0.1.en-US.linux-x86_64.tar.bz2 -C /opt/

Please follow further steps below only if not done before on your system.

5. Add firefox unity launchbar program and icon

Using the following script:

cd ${MOZBUILD_STATE_PATH%/}/firefox
cat > firefox-unity-add-menuitem.sh << "eof"
#!/bin/bash
#
# Resolve the location of the installation.
# This includes resolving any symlinks.
 
if [ ! $# -eq 3 ]; then
    echo "Add application to the unity launcher."
    echo
    echo "    Usage:"
    echo "        $0 APPNAME LOCATION IMAGE"
    echo
    echo "        APPNAME:  Name as it appears in unity launchbar"
    echo "        LOCATION: Location of the binary executable"
    echo "        IMAGE:    Location of the image to show on the launchbar"
    echo
    echo "    For example:"
    echo "        $0 firefox-unity /opt/firefox/firefox /opt/firefox/browser/chrome/icons/default/default128.png"
    exit 0
fi
 
PRG_NAME=$1
BINFILE=$2
IMG=$3
 
# absolutize dir
PRG_BIN="$(dirname "${BINFILE}")"
oldpwd=`pwd`
cd "${PRG_BIN}"
PRG_BIN=`pwd`
cd "${oldpwd}"
 
APP="$(basename "${BINFILE}")"
DTFILE="${PRG_NAME}.desktop"
 
TMP_DIR=`mktemp --directory`
 
DESKTOP_FILE=$TMP_DIR/${DTFILE}
cat << EOF > ${DESKTOP_FILE}
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Firefox Web Browser for unity
Keywords=Internet;WWW;Browser;Web;Explorer
GenericName=Web Browser
Type=Application
Categories=GNOME;GTK;Network;WebBrowser;
Terminal=false
StartupNotify=true
Exec="${PRG_BIN}/${APP}" %u
Icon=${PRG_NAME}.png
EOF
 
xdg-desktop-menu install --novendor ${DESKTOP_FILE}
xdg-icon-resource install --novendor --size 128 "${IMG}" ${PRG_NAME}
 
rm $DESKTOP_FILE
rm -R $TMP_DIR
eof
 
chmod +x firefox-unity-add-menuitem.sh

and the following image: saved as release128.png
(Original source: eponas-deeway, https://findicons.com/icon/63844/firefox, (license Creative Commons Attribution Non-commercial (by-nc))

Invoke with following command:

cd ${MOZBUILD_STATE_PATH%/}/firefox
wget https://www.auditeon.com/xyz/release128.png -O release128.png
./firefox-unity-add-menuitem.sh firefox-unity /opt/firefox/firefox ${MOZBUILD_STATE_PATH%/}/firefox/release128.png

For definitions of xdg categories, see here.

To be able to invoke firefox-unity from the command line, add a symbolic link to firefox-unity in /usr/local/bin

cd /usr/local/bin
sudo ln -s /opt/firefox/firefox /usr/local/bin/firefox-unity
projects/computerbeheer/firefox/build_automation.txt · Last modified: 2022/10/28 15:48 by admin