[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://phantomjs.googlecode.com/files/phantomjs-1.9.0-linux-i686.tar.bz2 2e94dcad7660d24309abe01011461693
x86-64 = https://phantomjs.googlecode.com/files/phantomjs-1.9.0-linux-x86_64.tar.bz2 8075fa873d8741c7ae9093c80a589a1f

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)