#!/usr/bin/env python3

import os
from helpers import parse_configfile
from subprocess import check_call

def main():
    mydir = os.getcwd()
    extra_args = parse_configfile('common_options')
    extra_args += parse_configfile('mplayer_options')

    env = os.environ.copy()
    PKG_CONFIG_PATH = '%s/build_libs/lib/pkgconfig:%s' % (
        mydir, env.get('PKG_CONFIG_PATH', ''))
    env['PKG_CONFIG_PATH'] = PKG_CONFIG_PATH

    # The --extra-cflags and --extra-ldflags parameters should not be
    # necessary to find the libraries, but they're there to ensure those
    # directories appear first in the search path in case there's another
    # version of the library installed on the system.

    args = ['--extra-cflags=-I%s/build_libs/include' % mydir,
            '--extra-ldflags=-L%s/build_libs/lib' % mydir]

    os.chdir('mplayer')
    check_call(['./configure'] + args + extra_args, env=env)

main()
