Skip to content

Instantly share code, notes, and snippets.

@ojii
Created October 27, 2016 03:59
Show Gist options
  • Save ojii/916c61282da3979a0fad5fa21b6755a1 to your computer and use it in GitHub Desktop.
Save ojii/916c61282da3979a0fad5fa21b6755a1 to your computer and use it in GitHub Desktop.
#!/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