# On Travis CI:
# The job exceeded the maximum time limit for jobs, and has been terminated.

# On CentOS 6.7:
# Python 2.7 installation woes
# yum -y install mercurial git
# Update to Python 2.7
# yum install -y centos-release-scl
# yum install -y python27

cat > sources.list <<EOF
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe
EOF
sudo mv sources.list /etc/apt/

sudo apt-get update
sudo apt-get -y install git mercurial

# Workaround for:
# *** MERCURIAL NOT CONFIGURED ***
export NO_MERCURIAL_SETUP_CHECK=1

# https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Linux_Prerequisites
# Install all system prerequisites
wget -O bootstrap.py https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py 

python bootstrap.py --application-choice=browser --no-interactive

# Only continue if we get:
# "Your system should be ready to build Firefox for Desktop!"

# Get mozilla-central from Mozilla through Mercurial
REV=$(wget -q https://github.com/therealglazou/bluegriffon/raw/bg2/config/mozilla_central_revision.txt -O -)
hg clone http://hg.mozilla.org/mozilla-central bluegriffon-source -r $REV
# TODO: http://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository
# git clone https://github.com/mozilla/gecko-dev bluegriffon-source ...

# Get BlueGriffon's tree through
cd bluegriffon-source
# git too old # git clone -b bg2 --single-branch https://github.com/therealglazou/bluegriffon --depth 1
git clone -b bg2 https://github.com/therealglazou/bluegriffon --depth 1

patch -p 1 < bluegriffon/config/content.patch

cat > .mozconfig <<EOF
mk_add_options MOZ_OBJDIR=$HOME/bin/opt/trunk
ac_add_options --disable-debug
ac_add_options --enable-optimize
ac_add_options --enable-strip
ac_add_options --enable-elf-hack
export LDFLAGS="-static-libstdc++"
export HOST_LDFLAGS="-static-libstdc++"
mk_add_options MOZ_MAKE_FLAGS="-s -j8"
ac_add_options --enable-application=bluegriffon
mk_add_options MOZ_TOOLKIT_SEARCH=
ac_add_options --disable-tests
ac_add_options --enable-default-toolkit=cairo-gtk2
ac_add_options --disable-crashreporter
ac_add_options --disable-updater
ac_add_options --disable-update-packaging
ac_add_options --disable-webrtc
ac_add_options --enable-media-navigator
mk_add_options MOZ_MEDIA_NAVIGATOR=1
EOF

# Update the compiler from what comes with trusty; TODO: Is this necessary?
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get -y install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

# build the bluegriffon-ng or the bg2 branch
./mach clobber # = "make clean"
./mach build # = "make"

# On precise I get:
# c++ -o host_stdc++compat.o -c -std=gnu++0x -D_GLIBCXX_USE_CXX11_ABI=0 -MD -MP -MF .deps/host_stdc++compat.o.pp -DNDEBUG=1 -DTRIMMED=1 -DMOZ_LIBSTDCXX_VERSION=197654 -I/media/20c95b94-60bb-42af-807b-0baccadb5f18/home/user/bluegriffon-source/build/unix/stdc++compat -I/media/20c95b94-60bb-42af-807b-0baccadb5f18/home/user/bluegriffon-source/obj-x86_64-unknown-linux-gnu/build/unix/stdc++compat -I/media/20c95b94-60bb-42af-807b-0baccadb5f18/home/user/bluegriffon-source/obj-x86_64-unknown-linux-gnu/dist/include -I/media/20c95b94-60bb-42af-807b-0baccadb5f18/home/user/bluegriffon-source/obj-x86_64-unknown-linux-gnu/dist/include/nspr /media/20c95b94-60bb-42af-807b-0baccadb5f18/home/user/bluegriffon-source/build/unix/stdc++compat/stdc++compat.cpp
# bluegriffon-source/build/unix/stdc++compat/stdc++compat.cpp:181:5: error: ‘runtime_error’ does not name a type
#      runtime_error::runtime_error(char const* s)
#     ^
# Does this mean that precise is too old?

# Actually on trusty I get the same error, but I didn't get it when using trusty on Travis CI; that is strange!
