GrapefruiTgirl |
01-23-2010 02:11 AM |
Building Firefox 3.6 - A "Profile Guided Optimization" (PGO) Automated Build Script
So, Firefox 3.6 just came out a day or two ago, and is definitely improved over previous versions. And, just in time, I finally figured out what the heck I'm doing with this PGO build stuff, so here's a script that will build you a PGO Firefox 3.6 (or whatever version you like).
This script (as is much stuff I write) is very Slackware-centric, but can be fairly easily adapted to suit your Linux distro if it is not Slackware. This is based on the Slack 13.0/64 SlackBuild, and a bunch of other stuff I've gleaned from mozilla.org and elsewhere on the net.
Examine the script carefully to learn how it works. It can create a ready-to-install SlackPackage for Slackware 64, or it can make a generic Firefox tarball which you can manually extract & install somewhere.
Be careful with compiler optimization flags; the ones in the script work for me, but may not work for you (I'm using a E2160 Core2 Intel CPU and GCC 4.3.3) but too many flags will break the build.
The resulting build is FAST, both in page rendering type of areas, as well as chrome and GUI operations-- a LOT faster, speedier, and more responsive than a stock build.
An added bonus, for those who aren't aware: FF 3.6 has a new theme engine (if I can call it that) that allows lightweight UI themes called 'personas' to be instantly skinned onto the browser; no restart, no installing, just instant cool colorful themes!
Here goes:
Code:
#!/bin/sh
# This script is POSIX compliant and comes with no warranty.
# Tune it up or otherwise adjust as you see fit.
# By Sasha - Jan 22 2010
# My gcc used = 4.3.3
#
# PGO (Profile Guided Optimization) Firefox build
# for 64bit Slackware 13.0
# Works for me with FF 3.6 (freshly released Jan 22/2010)
# Script based on Slackware 13/64 SlackBuild and other
# examples from here and there, including mozilla.org.
#
# This whole build is a multi-stage clobber-build
# which takes the better part of 1.5 hours, including
# time spent playing with the half-built browser half
# way through the build to generate profiling info.
#
# FF 3.6 build depends on libnotify from Galago and
# some junk from your Wireless Tools package (yes, wtf?!)
# BEGIN:
# First, see that we aren't root, because we _are_ going to
# fire up the new browser half-way through the build, to generate
# some profiling information. Don't wanna browse as root, and
# also, root is not allowed to connect to the X server by
# default, so the build will fail when the browser cannot be started.
echo "Checking UID and file ownership.."
if [ $(id -u) = 0 ]; then
echo "You should not do this as root."
echo "Please change to another UID before running this script."
exit 1
else
# ensure everything is our UID:GID or quit
# (in case any of it is root owned)
if [ "$(chown -R $(id -u):$(id -g) ./* 2>&1 >/dev/null)" ]; then
echo "Stuff in here is not chownable to our UID:GID."
echo "Please fix it and run this script again."
exit 1
fi;
fi;
# my favorite compiler optimizations:
CFLAGS="-fPIC -O3 -Wall -pipe -march=native -mtune=native -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
CPPFLAGS="${CFLAGS} -I/usr/include"
MAKEFLAGS="-j3"
# FF apparently won't build properly with autoconf != 2.13 so
# in case this is still the case, I installed autoconf 2.13 in
# /usr/local/bin and this PATH makes it be found first, before
# my regular autoconf 2.6:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:.
export PATH CPPFLAGS CXXFLAGS CFLAGS MAKEFLAGS
CWD=$(pwd) # where am I now (start base dir)
TMP=$CWD/temp # a slackpkg will be constructed in here.
LIBDIR=lib64 # slack64 libdir.
SRCDIR=$CWD/SOURCE # FF source dir.
OBJDIR=$CWD/OBJDIR # build dest dir.
PKGDIR=$CWD/PGO_FINISHED_PROD # slack package or tarball ends up in here.
PROFIL=$CWD/_PROFILEPROFILE # PGO profile folder
# (stick your places.sqlite in there if you want)
MOZAPP=browser # in mozconfig, which mozilla component to build
APP=firefox # self evident.
VERSION=3.6 # self evident.
EXTENSION=en-US.linux # FF tarball name includes this piece.
# but may change depending on your locale.
ARCH=x86_64 # architecture.
BUILD=1 #
# Download all the parts here?
# make sure we have all the necessary pieces for
# creating a slackpackage, and the source archive too:
for i in firefox.png mimeTypes.rdf.gz firefox.moz_plugin_path.diff.gz \
mozilla-firefox.desktop slack-desc $APP-$VERSION.source.tar.bz2; do
if [ ! -f "$CWD/$i" ]; then
echo "Error: $CWD/$i missing. Get it somewhere and try again."
exit 1
fi;
done
# clean away old build dirs and make fresh ones:
rm -Rf $SRCDIR $OBJDIR $TMP $PKGDIR
mkdir -p $SRCDIR $OBJDIR $PROFIL $TMP $PKGDIR
# run-script.sh ##################################################
# create the app startup script for profile generation:
cat << EOF > run-$APP.sh
#!/bin/sh
NO_EM_RESTART=1
DISPLAY=:0.0
export NO_EM_RESTART DISPLAY
$OBJDIR/dist/bin/$APP -no-remote -profile $PROFIL
EOF
chmod a+x run-$APP.sh
# /run-script.sh ##################################################
# extract the FF source tar.bz2 into $SRCDIR..
echo "Extracting source.."
cd $SRCDIR
tar xf $CWD/$APP-$VERSION.source.tar.bz2 || exit 1
sync
SRCDIR=$(pwd)/$(ls)
cd $SRCDIR || exit 1
#/usr/local/bin/autoreconf || exit 1
# Pat Volkerding says:
# Fix a long standing bug that's prevented staying current on GTK+.
# Thanks to the BLFS folks. :-)
cat << EOF >> layout/build/Makefile.in
ifdef MOZ_ENABLE_CANVAS
EXTRA_DSO_LDOPTS += \$(XLDFLAGS) -lX11 -lXrender
endif
EOF
# mozconfig #######################################################
# and create our mozconfig in $SRCDIR:
cat << EOF > mozconfig
# FF PGO-build mozconfig file
# option to say use objdir (build dir):
mk_add_options MOZ_OBJDIR=$OBJDIR
# startup script, for generating profile info for optimize:
mk_add_options PROFILE_GEN_SCRIPT=$CWD/run-$APP.sh
# which mozilla app to build:
ac_add_options --enable-application=$MOZAPP
########################################: Stuff that always worked:
###################### (mostly) stuff from the -current slackbuild:
ac_add_options --enable-official-branding
ac_add_options --prefix=/usr --libdir=/usr/$LIBDIR
ac_add_options --host="x86_64-slackware-linux-gnu"
ac_add_options --with-default-mozilla-five-home=/usr/$LIBDIR/$APP-$VERSION
ac_add_options --with-system-zlib
ac_add_options --enable-default-toolkit=cairo-gtk2
ac_add_options --enable-crypto
ac_add_options --enable-svg
ac_add_options --enable-canvas
ac_add_options --enable-xft
ac_add_options --enable-xinerama
ac_add_options --enable-optimize="-fPIC -Os -Wall -pipe -march=native -mtune=native -fomit-frame-pointer"
ac_add_options --enable-reorder
ac_add_options --enable-strip
ac_add_options --enable-system-cairo
ac_add_options --enable-cpp-rtti
ac_add_options --enable-single-profile
ac_add_options --disable-ldap
ac_add_options --disable-accessibility
ac_add_options --disable-debug
ac_add_options --disable-tests
ac_add_options --disable-logging
ac_add_options --disable-pedantic
ac_add_options --disable-installer
ac_add_options --disable-mailnews
ac_add_options --disable-composer
ac_add_options --disable-profilesharing
# End official slackbuild opts
########################################: stuff I'm 98% sure always works:
ac_add_options --with-gxx-include-dir=/usr/include/c++/4.3.3
ac_add_options --quiet
ac_add_options --with-system-bz2
ac_add_options --with-pthreads
ac_add_options --enable-threads=posix
ac_add_options --enable-system-lcms
ac_add_options --enable-system-sqlite
ac_add_options --enable-pango
ac_add_options --enable-install-strip
ac_add_options --disable-updater
ac_add_options --disable-gnomeui
ac_add_options --disable-gnomevfs
########################################: stuff I'm 95% sure works fine:
#ac_add_options --enable-libxul
#ac_add_options --with-system-jpeg
#ac_add_options --with-system-nssac_add_options
ac_add_options --disable-crashreporter
ac_add_options --disable-help-viewer
ac_add_options --disable-debug-modules
ac_add_options --disable-debugger-info-modules
ac_add_options --disable-parental-controls
ac_add_options --disable-safe-browsing
ac_add_options --disable-startup-notification
########################################: Completely Experimental below..
########################################: Questionable/Optional stuff
########################################: that may, or just may not work:
#ac_add_options --enable-javaxpcom
#ac_add_options --enable-oji
#ac_add_options --enable-xpcom-fastload
#ac_add_options --enable-plugins
#ac_add_options --enable-jemalloc
#ac_add_options --enable-mathml
#ac_add_options --disable-xpcom-obsolete
#ac_add_options --enable-svg-foreignobject
# ac_add_options --enable-chrome-format=jar
# ac_add_options --enable-native-uconv # not needed/not recommended
# ac_add_options --enable-image-encoders=all # should not need
# ac_add_options --enable-update-channel=release # needed by moz.org people only?
# ac_add_options --enable-prebinding # OSX only?
# ac_add_options --enable-reflow-perf # try without.. may slow down FF for non-devel user?
# ac_add_options --enable-glitz # this thing won't install into lib64
# END of mozconfig file
EOF
# /mozconfig #######################################################
# configure the sources:
cd $OBJDIR
echo ; echo "Info: Running configure in 5" ; sleep 5
$SRCDIR/configure || exit 1
# make the sources:
cd $SRCDIR
echo ; echo "Info: Starting non-PGO build in 5" ; sleep 5
make -s -f client.mk build MOZ_MAKE_FLAGS="${MAKEFLAGS}" || exit 1
# make PGO build in same objdir, on top of what's already built:
echo ; echo "Info: Done non-PGO build... Continuing in 5" ; sleep 5
make -s -f client.mk profiledbuild MOZ_MAKE_FLAGS="${MAKEFLAGS}" || exit 1
# Here is when the profiling build should fire up. Use it for a while,
# do some browsing, give it a hard time; sometimes a bad build will
# run for 5, 10 or 15 minutes until it hits a snag, bug, segfault
# or whatever, so you want to make it happen NOW, not when you've
# got 25 tabs open tomorrow and the whole thing locks up on you.
# When you're done, and confident that the browser is stable,
# click File->Quit and the build will resume.
# OPTIONS HERE (functions):
make_tarball () {
# make tarball: This makes a generic tarball of the newly
# compiled Firefox and related components, and zips it up
# into a bzip2 archive. You can then do what you like with
# it, such as install it manually, or just unpack it somewhere
# and use it as-is.
# Package it into a tarball to fix symlinks & gather all pieces:
( cd $OBJDIR
echo ; echo "Info: Packaging tarball in 5" ; sleep 5
make package ) || exit 1
#move tarball to $CWD (start directory)
( cd $PKGDIR
cp -fvt . $OBJDIR/dist/$APP-$VERSION.$EXTENSION-$ARCH.tar.bz2
) || exit 1
cd $CWD
# Now do what you want with the finished tarball in $PKGDIR.
}
# 2) make slackpkg:
make_slackpkg () {
# make a slackware package according to the general idea
# of what happens in the Slack13.0/64 SlackBuild script:
( cd $OBJDIR
echo ; echo "Info: Creating slackpkg dir structure in 5" ; sleep 5
make install DESTDIR=$TMP
# We don't need these things:
rm -Rf $TMP/usr/$LIBDIR/$APP-devel-$VERSION
rm -Rf $TMP/usr/include
)
( cd $TMP/usr/$LIBDIR/$APP-$VERSION
zcat $CWD/mimeTypes.rdf > defaults/profile/mimeTypes.rdf || exit 1
zcat $CWD/firefox.moz_plugin_path.diff.gz \
| sed -e "s#usr/lib#usr/$LIBDIR#g" \
| patch -p1 --verbose --backup --suffix=.orig || exit 1
# Clean up if the above patch was successful:
# On my system, that patch is successful, but a bit fuzzy :/
rm -f firefox.orig
) || exit 1
mkdir -p $TMP/usr/$LIBDIR/mozilla/plugins
mkdir -p $TMP/usr/share/applications
cat $CWD/mozilla-$APP.desktop > $TMP/usr/share/applications/mozilla-$APP.desktop
mkdir -p $TMP/usr/share/pixmaps
cat $CWD/$APP.png > $TMP/usr/share/pixmaps/$APP.png
# These files/directories are usually created if Firefox is run
# as root which technically should be never. Anyhow, if we don't
# see these items, put stubbies in place (whatever those are) to
# prevent startup errors:
( cd $TMP/usr/$LIBDIR/$APP-$VERSION
if [ -d extensions/talkback\@mozilla.org ]; then
if [ ! -r extensions/talkback\@mozilla.org/chrome.manifest ]; then
echo > extensions/talkback\@mozilla.org/chrome.manifest
fi
fi
if [ ! -d updates ]; then
mkdir -p updates/0
fi
)
# Install icons/imgs/license/slack-desc:
mkdir -p $TMP/usr/$LIBDIR/$APP-$VERSION/chrome/icons/default
install -m 644 $SRCDIR/other-licenses/branding/$APP/default16.png $TMP/usr/$LIBDIR/$APP-$VERSION/icons/
install -m 644 $SRCDIR/other-licenses/branding/$APP/default16.png $TMP/usr/$LIBDIR/$APP-$VERSION/chrome/icons/default/
install -p -c -m 644 $SRCDIR/LICENSE $TMP/usr/$LIBDIR/$APP-$VERSION/
mkdir $TMP/install
cat $CWD/slack-desc > $TMP/install/slack-desc
cd $TMP
# whip up the Slackpackage:
echo "Ready to zip up the slackpkg."
echo "1) su to root."
echo "2) Make sure you are in this folder: $TMP"
echo "3) Now, as root, type:"
echo "makepkg -l y -c y $PKGDIR/mozilla-$APP-$VERSION-$ARCH-$BUILD.tgz"
} # end of make_slackpkg()
#NOTE: Below here, uncomment whichever function-call you
# plan to use: either "make_slackpkg" or "make_tarball"
# You can probably do both if you have some reason to do so..
#make_tarball
make_slackpkg
#EOF
Have fun!
Sasha
|