author Mike Hommey <>
Tue, 23 Feb 2016 09:42:40 +0900
changeset 323709 41b457611bbf2127b95495f2bb5fa0cf716e9146
child 324338 5069f5724e096916b540aabe2d0c7b5ed00ccbef
permissions -rw-r--r--
Bug 1250294 - Make configure a Python script that invokes the old r=ted

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

from __future__ import print_function, unicode_literals

import glob
import itertools
import os
import subprocess
import sys

base_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(base_dir, 'python', 'which'))
from which import which, WhichError

# If feel dirty replicating this from python/mozbuild/mozbuild/,
# but the end goal being that the configure script would go away...
shell = 'sh'
if 'MOZILLABUILD' in os.environ:
    shell = os.environ['MOZILLABUILD'] + '/msys/bin/sh'
if sys.platform == 'win32':
    shell = shell + '.exe'

def find_program(file):
        return which(file)
    except WhichError:
        return None

def autoconf_refresh(configure):
    if os.path.exists(configure):
        mtime = os.path.getmtime(configure)
        aclocal = os.path.join(base_dir, 'build', 'autoconf', '*.m4')
        for input in itertools.chain(
            (configure + '.in',
             os.path.join(os.path.dirname(configure), 'aclocal.m4')),
            if os.path.getmtime(input) > mtime:

    for ac in ('autoconf-2.13', 'autoconf2.13', 'autoconf213'):
        autoconf = find_program(ac)
        if autoconf:
        fink = find_program('fink')
        if fink:
            autoconf = os.path.normpath(os.path.join(
                fink, '..', '..', 'lib', 'autoconf2.13', 'bin', 'autoconf'))

    if not autoconf:
        raise RuntimeError('Could not find autoconf 2.13')

    print('Refreshing %s' % configure, file=sys.stderr)

    with open(configure, 'wb') as fh:
            shell, autoconf, '--localdir=%s' % os.path.dirname(configure),
            configure + '.in'], stdout=fh)

def main(args):
    old_configure = os.environ.get('OLD_CONFIGURE')

    if not old_configure:
        raise Exception('The OLD_CONFIGURE environment variable must be set')

    # We need to replace backslashes with forward slashes on Windows because
    # this path actually ends up literally as $0, which breaks autoconf's
    # detection of the source directory.
    old_configure = os.path.abspath(old_configure).replace(os.sep, '/')

    except RuntimeError as e:
        print(e.message, file=sys.stderr)
        return 1

    return[shell, old_configure] + args)

if __name__ == '__main__':