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

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

depends =
  ${liberation-fonts:location}
  ${ipaex-fonts:location}

x86 = https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-i686.tar.bz2 9c1426eef5b04679d65198b1bdd6ef88
x86-64 = https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 f278996c3edd0e8d8ec4893807f27d71

script =
  if not self.options.get('url'): self.options['url'], self.options['md5sum'] = self.options[guessPlatform()].split(' ')
  extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
  workdir = guessworkdir(extract_dir)
  self.copyTree(workdir, "%(location)s")
  wrapper_location = os.path.join("%(location)s", "phantomjs-slapos")
  wrapper = open(wrapper_location, 'w')
  wrapper.write("""#!${dash:location}/bin/dash
  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 $*""")
  wrapper.flush()
  wrapper.close()
  os.chmod(wrapper_location, 0755)
