Deploy docs to gh-pages branch from Travis builds

Build docs in Travis and push them to the gh-pages branch, which makes
them available at http://behdad.github.io/harfbuzz/
diff --git a/.ci/deploy-docs.sh b/.ci/deploy-docs.sh
new file mode 100755
index 0000000..8c60a22
--- /dev/null
+++ b/.ci/deploy-docs.sh
@@ -0,0 +1,25 @@
+set -o errexit -o nounset
+
+if [ "$TRAVIS_OS_NAME" == "linux" -a "$CC" == "gcc" -a "$TRAVIS_PULL_REQUEST" == "false" -a "$TRAVIS_BRANCH" == "master" ]
+then
+	DOCSDIR=build-docs
+	REVISION=$(git rev-parse --short HEAD)
+
+	rm -rf $DOCSDIR || exit
+	mkdir $DOCSDIR
+	cd $DOCSDIR
+
+	cp ../docs/html/* .
+
+	git init
+	git config user.name "Travis CI"
+	git config user.email "[email protected]"
+	git remote add upstream "https://[email protected]/$TRAVIS_REPO_SLUG.git"
+	git fetch upstream
+	git reset upstream/gh-pages
+
+	touch .
+	git add -A .
+	git commit -m "Rebuild docs for $REVISION"
+	git push -q upstream HEAD:gh-pages
+fi
diff --git a/.travis.yml b/.travis.yml
index 817811c..798f5ee 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,6 +13,7 @@
     - CFLAGS="-Werror --coverage"
     - CXXFLAGS="-Werror --coverage"
     - LDFLAGS="--coverage"
+    - secure: "EysLG1MB6WCvDVpls5jsJAYsXcbHTmSFYl11UlAQCNfU+MBv7qiuOR6im3tM4ISzt4TY+OQXxEktMFRT+8govLR4UWo8dwmZ4P/2GqMbsZNPVSLkbDEy6hVv7xe5X4mp+npHthY1Z1YOLKGAh/u1PymySZz6qAzsCZ6Fq/H5Ri8="
 install:
   - if [ "$TRAVIS_OS_NAME" == "linux" ]; then pip install --user nose; fi
   - if [ "$TRAVIS_OS_NAME" == "linux" ]; then pip install --user cpp-coveralls; fi # for coveralls.io code coverage tracking
@@ -23,11 +24,14 @@
 script:
   - NOCONFIGURE=1 ./autogen.sh
   - export CONFIGURE_OPTS="--with-freetype --with-glib --with-gobject --with-cairo --with-icu --with-graphite2"
+  - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CC" == "gcc" ]; then export CONFIGURE_OPTS="$CONFIGURE_OPTS  --enable-gtk-doc"; fi
   - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export CONFIGURE_OPTS="$CONFIGURE_OPTS --with-coretext"; fi
   - ./configure $CONFIGURE_OPTS
   - make
   - make check
   - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CC" == "gcc" ]; then rm -f src/.libs/NONE.gcov; touch src/NONE; coveralls; fi
+after_success:
+  - bash .ci/deploy-docs.sh
 notifications:
   irc: "irc.freenode.org#harfbuzz"
   email: [email protected]