[buildout]
extends =
  ../fontconfig/buildout.cfg
  ../libexpat/buildout.cfg
parts =
  phantomjs

[phantomjs]
recipe = slapos.recipe.build
slapos_promise =
  file:phantomjs-slapos

base = https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux
i386-linux-gnu   = ${:base}-i686.tar.bz2   9c1426eef5b04679d65198b1bdd6ef88
x86_64-linux-gnu = ${:base}-x86_64.tar.bz2 f278996c3edd0e8d8ec4893807f27d71

install =
  import os
  extract_dir = self.extract(self.download(*options[multiarch()].split()))
  workdir = guessworkdir(extract_dir)
  self.copyTree(workdir, location)
  with open(os.path.join(location, "phantomjs-slapos"), 'w') as wrapper:
    wrapper.write("""#!/bin/sh -e
  cd %(location)s
  export LD_LIBRARY_PATH=%(location)s:${freetype:location}/lib/:${fontconfig:location}/lib/:${libexpat:location}/lib
  export PATH=${fontconfig:location}/bin:$PATH
  exec %(location)s/bin/phantomjs "$@"
  """ % options)
    os.fchmod(wrapper.fileno(), 0o755)