Created
October 27, 2016 03:59
-
-
Save ojii/916c61282da3979a0fad5fa21b6755a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import subprocess | |
import sys | |
def scan(formula, keys): | |
info = subprocess.check_output(['brew', 'info', formula]) | |
for line in map(str.strip, info.decode('utf-8').splitlines()): | |
for key, target in keys.items(): | |
if line.startswith('%s: ' % key): | |
target.append(line.split(' ', 1)[1].strip()) | |
def run(formulas): | |
ldflags = [] | |
cppflags = [] | |
pkg_config_paths = [] | |
for formula in formulas: | |
scan(formula, { | |
'LDFLAGS': ldflags, | |
'CPPFLAGS': cppflags, | |
'PKG_CONFIG_PATH': pkg_config_paths | |
}) | |
return ldflags, cppflags, pkg_config_paths | |
def output(ldflags, cppflags, pkg_config_paths, fobj): | |
fobj.write("LDFLAGS='") | |
fobj.write(' '.join(ldflags)) | |
fobj.write("' ") | |
fobj.write("CPPFLAGS='") | |
fobj.write(' '.join(cppflags)) | |
fobj.write("' ") | |
fobj.write("PKG_CONFIG_PATH='") | |
fobj.write(':'.join(pkg_config_paths)) | |
fobj.write("'") | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('formulas', nargs='+') | |
args = parser.parse_args() | |
ldflags, cppflags, pkg_config_paths = run(args.formulas) | |
output(ldflags, cppflags, pkg_config_paths, sys.stdout) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment