michael@0: dnl This Source Code Form is subject to the terms of the Mozilla Public michael@0: dnl License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: AC_DEFUN([MOZ_PYTHON], michael@0: [ michael@0: michael@0: dnl We honor the Python path defined in an environment variable. This is used michael@0: dnl to pass the virtualenv's Python from the main configure to SpiderMonkey's michael@0: dnl configure, for example. michael@0: if test -z "$PYTHON"; then michael@0: MOZ_PATH_PROGS(PYTHON, $PYTHON python2.7 python) michael@0: if test -z "$PYTHON"; then michael@0: AC_MSG_ERROR([python was not found in \$PATH]) michael@0: fi michael@0: else michael@0: AC_MSG_RESULT([Using Python from environment variable \$PYTHON]) michael@0: fi michael@0: michael@0: _virtualenv_topsrcdir= michael@0: _virtualenv_populate_path= michael@0: michael@0: dnl If this is a mozilla-central, we'll find the virtualenv in the top michael@0: dnl source directory. If this is a SpiderMonkey build, we assume we're at michael@0: dnl js/src and try to find the virtualenv from the mozilla-central root. michael@0: for base in $MOZILLA_CENTRAL_PATH $_topsrcdir $_topsrcdir/../..; do michael@0: possible=$base/python/mozbuild/mozbuild/virtualenv.py michael@0: michael@0: if test -e $possible; then michael@0: _virtualenv_topsrcdir=$base michael@0: _virtualenv_populate_path=$possible michael@0: break michael@0: fi michael@0: done michael@0: michael@0: if test -z $_virtualenv_populate_path; then michael@0: AC_MSG_ERROR([Unable to find Virtualenv population script. In order michael@0: to build, you will need mozilla-central's virtualenv. michael@0: michael@0: If you are building from a mozilla-central checkout, you should never see this michael@0: message. If you are building from a source archive, the source archive was michael@0: likely not created properly (it is missing the virtualenv files). michael@0: michael@0: If you have a copy of mozilla-central available, define the michael@0: MOZILLA_CENTRAL_PATH environment variable to the top source directory of michael@0: mozilla-central and relaunch configure.]) michael@0: michael@0: fi michael@0: michael@0: if test -z $DONT_POPULATE_VIRTUALENV; then michael@0: AC_MSG_RESULT([Creating Python environment]) michael@0: dnl This verifies our Python version is sane and ensures the Python michael@0: dnl virtualenv is present and up to date. It sanitizes the environment michael@0: dnl for us, so we don't need to clean anything out. michael@0: $PYTHON $_virtualenv_populate_path \ michael@0: $_virtualenv_topsrcdir $MOZ_BUILD_ROOT $MOZ_BUILD_ROOT/_virtualenv \ michael@0: $_virtualenv_topsrcdir/build/virtualenv_packages.txt || exit 1 michael@0: michael@0: case "$host_os" in michael@0: mingw*) michael@0: PYTHON=`cd $MOZ_BUILD_ROOT && pwd -W`/_virtualenv/Scripts/python.exe michael@0: ;; michael@0: *) michael@0: PYTHON=$MOZ_BUILD_ROOT/_virtualenv/bin/python michael@0: ;; michael@0: esac michael@0: fi michael@0: michael@0: AC_SUBST(PYTHON) michael@0: michael@0: AC_MSG_CHECKING([Python environment is Mozilla virtualenv]) michael@0: $PYTHON -c "import mozbuild.base" michael@0: if test "$?" != 0; then michael@0: AC_MSG_ERROR([Python environment does not appear to be sane.]) michael@0: fi michael@0: AC_MSG_RESULT([yes]) michael@0: michael@0: PYTHON_SITE_PACKAGES=`$PYTHON -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib()"` michael@0: if test -z "$PYTHON_SITE_PACKAGES"; then michael@0: AC_MSG_ERROR([Could not determine python site packages directory.]) michael@0: fi michael@0: AC_SUBST([PYTHON_SITE_PACKAGES]) michael@0: michael@0: ]) michael@0: