hghooks /

"""Executes make command.


    changegroup.runmake = python:hghooks.runmake:hook

    makecmd = gmake     # (optional) default: "make"
    maketargets = all   # (optional) default: none
    makevars = FOO=BAR  # (optional) default: none
    sudouser = hgbuild  # (optional) default: not sudo-ing
from mercurial import commands
import subprocess

def runmake(ui, repo, targets=[], vars={}, sudo=False):
    """Runs make command with the specified environment and targets."""
    args = []

    if sudo:
        sudouser = ui.config('runmake', 'sudouser')
        if not sudouser:
            raise ValueError('sudouser not specified.')

        args += ['sudo', '-u', sudouser]

    args += [ui.config('runmake', 'makecmd', 'make')]
    args += ["%s=%s" % (k, v) for (k, v) in vars.iteritems()]
    args += targets

    subprocess.check_call(args, cwd=repo.root)

def hook(ui, repo, hooktype, **kwargs):
    commands.update(ui, repo, clean=True)
    runmake(ui, repo, targets=ui.configlist('runmake', 'maketargets', []),
            vars=dict(e.split('=', 1) for e in ui.configlist('runmake', 'makevars', [])),
            sudo=bool(ui.config('runmake', 'sudouser')))