[buildout]
extends =
  ../bzip2/buildout.cfg
  ../gdbm/buildout.cfg
  ../libexpat/buildout.cfg
  ../libffi/buildout.cfg
  ../ncurses/buildout.cfg
  ../openssl/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../sqlite3/buildout.cfg
  ../zlib/buildout.cfg

[pycparser-shared]
# XXX:
recipe = slapos.recipe.cmmi
shared = true
url = https://github.com/eliben/pycparser/archive/release_v2.20.tar.gz
md5sum = a5d9ea5350a8edb8239af73913ea2858
configure-command = :
make-binary =
make-targets = python setup.py install --install-lib @@LOCATION@@

[pypy2]
recipe = slapos.recipe.cmmi
shared = true
url = https://downloads.python.org/pypy/pypy2.7-v7.3.1-src.tar.bz2
md5sum = 7608bd58940ffc5403632c2c786d83bb
configure-command =
  sed -i '/"_tkinter":/s/^/#/' lib_pypy/tools/build_cffi_imports.py
  cat <<EOF > Makefile
  PREFIX = @@LOCATION@@
  export PYPY_USESSION_BASENAME=slapos
  export TMPDIR=\$(realpath ..)
  all: pypy/goal/pypy-c lib_pypy/tools/build_cffi_imports.py
  	\$^
  c_src_dir:
  	cd pypy/goal && PYTHONPATH=${pycparser-shared:location} $${PYTHON:-python2}  ../../rpython/bin/rpython --batch --source --opt=jit --shared targetpypystandalone
  	ln -s ../usession-\$\$PYPY_USESSION_BASENAME-\$\$USER/testing_1 \$@
  pypy/goal/pypy-c: c_src_dir
  	\$(MAKE) -C \$<
  	mv \$</libpypy-c.so \$</pypy-c pypy/goal
  	touch \$@
  install:
  	mkdir -p \$(PREFIX)/bin \$(PREFIX)/include
  	find lib_pypy lib-python/2.7 -type d '(' '(' -name __pycache__ -o -name _tkinter -o -name test -o -name tests ')' -prune -o -print ')' \
  	|while read d; do mkdir -p \$(PREFIX)/\$\$d && find \$\$d -maxdepth 1 -type f ! -name '*.o' ! -name '*.c' |xargs -r cp -t \$(PREFIX)/\$\$d; done
  	d=lib-python/2.7/test && mkdir -p \$(PREFIX)/\$\$d && for x in __init__ pystone regrtest test_support; do echo \$\$d/\$\$x.py; done |xargs -r cp -t \$(PREFIX)/\$\$d
  	cd lib-python && cp conftest.py stdlib-version.* \$(PREFIX)/lib-python
  	cp -r include/pypy_*.h include/PyPy.h pypy/module/cpyext/include/* pypy/module/cpyext/parse/* \$(PREFIX)/include
  	cd pypy/goal && cp libpypy-c.so \$(PREFIX)/bin && cp pypy-c \$(PREFIX)/bin/pypy
environment =
  C_INCLUDE_PATH=${bzip2:location}/include:${gdbm:location}/include:${libexpat:location}/include:${ncurses:location}/include:${ncurses:location}/include/ncursesw:${openssl:location}/include:${sqlite3:location}/include:${zlib:location}/include
  LDFLAGS=-L${bzip2:location}/lib -L${gdbm:location}/lib -L${libexpat:location}/lib -L${libffi:location}/lib -L${ncurses:location}/lib -L${openssl:location}/lib -L${sqlite3:location}/lib -L${zlib:location}/lib -Wl,-rpath=${bzip2:location}/lib -Wl,-rpath=${gdbm:location}/lib -Wl,-rpath=${libexpat:location}/lib -Wl,-rpath=${libffi:location}/lib -Wl,-rpath=${ncurses:location}/lib -Wl,-rpath=${openssl:location}/lib -Wl,-rpath=${sqlite3:location}/lib -Wl,-rpath=${zlib:location}/lib
  PATH=${pkgconfig:location}/bin:%(PATH)s
  PKG_CONFIG_PATH=${libffi:location}/lib/pkgconfig
