[buildout]
extends =
  ../bzip2/buildout.cfg
  ../gdbm/buildout.cfg
  ../gettext/buildout.cfg
  ../libexpat/buildout.cfg
  ../libffi/buildout.cfg
  ../ncurses/buildout.cfg
  ../openssl/buildout.cfg
  ../patch/buildout.cfg
  ../readline/buildout.cfg
  ../sqlite3/buildout.cfg
  ../zlib/buildout.cfg
  ../file/buildout.cfg
  ../xz-utils/buildout.cfg

parts =
    python2.7

[bootstrap2.7]
recipe = zc.recipe.egg
eggs = zc.buildout
suffix =
scripts =
    buildout=bootstrap2.7
arguments = sys.argv[1:] + ["bootstrap"]
python = python2.7

[python2.7-lib-patches]
# Patches that apply to both CPython & PyPy.
patches =
  ${:_profile_base_location_}/asyncore_poll_insteadof_select.patch#ab6991c0ee6e25aeb8951e71f280a2f1
  ${:_profile_base_location_}/fix_compiler_module_issue_20613.patch#94443a77f903e9de880a029967fa6aa7
  ${:_profile_base_location_}/py27-subproc-closefds-fast.patch#e495e44491694a8972da11739206f2e6

[python2.7]
recipe = slapos.recipe.cmmi
shared = true
package_version = 2.7.18
package_version_suffix =
md5sum = fd6cc8ec0a78c44036f825e739f36e5a

version = 2.7
executable = @@LOCATION@@/bin/python${:version}

patch-options = -p1
patches = ${python2.7-lib-patches:patches}
  ${:_profile_base_location_}/disabled_module_list.patch#e038a8016475574c810cbaaf0e42f4ac
  ${:_profile_base_location_}/pytracemalloc_pep445.patch#9f3145817afa2b7fad801fde8447e396
url =
  http://www.python.org/ftp/python/${:package_version}/Python-${:package_version}${:package_version_suffix}.tar.xz
pre-configure =
  sed -i \
    -e "s/if 'curses' in ln:/if 'curses' in ln.split()[0]:/" \
    -e '/"SQLITE_OMIT_LOAD_EXTENSION"/s/^/#/' \
    setup.py
configure-options =
  --enable-ipv6
  --enable-unicode=ucs4
  --with-system-expat
  --with-system-ffi
  --with-threads
# Profiled build:
make-binary =
make-targets = make profile-opt && make install
# Mangle shebang to use installed Python. This is not only a convenience:
# when building system packages (e.g. re6st-node using OBS), some OS like
# recent RedHat would otherwise mangle them, either failing ('python' is
# ambiguous and 'python2' is not supported anymore) or replacing with
# something that's really wrong (/usr/bin/python...).
post-install = cd '%(prefix)s' &&
  find -executable -type f -print0 |
  xargs -0 grep -I -m 1 '' |
  sed -n 's,:#! */usr/bin/env \+python2\?$,,p' |
  xargs -d '\n' sed -i '1s,.*,#!%(executable)s,'

# the entry "-Wl,-rpath=${file:location}/lib" below is needed by python-magic,
# which would otherwise load the system libmagic.so with ctypes
environment =
  PATH=${patch:location}/bin:${xz-utils:location}/bin:%(PATH)s
  CPPFLAGS=-I${zlib:location}/include -I${readline:location}/include -I${libexpat:location}/include -I${libffi:location}/include -I${ncurses:location}/include -I${ncurses:location}/include -I${bzip2:location}/include  -I${gdbm:location}/include -I${openssl:location}/include -I${sqlite3:location}/include -I${gettext:location}/include -fPIC
  LDFLAGS=-L${bzip2:location}/lib -L${gdbm:location}/lib -L${gettext:location}/lib -L${libexpat:location}/lib -L${libffi:location}/lib -L${ncurses:location}/lib -L${openssl:location}/lib -L${sqlite3:location}/lib -L${readline:location}/lib -L${zlib:location}/lib -Wl,-rpath=${bzip2:location}/lib -Wl,-rpath=${file:location}/lib -Wl,-rpath=${gdbm:location}/lib -Wl,-rpath=${gettext:location}/lib -Wl,-rpath=${libexpat:location}/lib -Wl,-rpath=${libffi:location}/lib -Wl,-rpath=${ncurses:location}/lib -Wl,-rpath=${openssl:location}/lib -Wl,-rpath=${readline:location}/lib -Wl,-rpath=${sqlite3:location}/lib -Wl,-rpath=${zlib:location}/lib
