Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created October 24, 2016 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisswarren/4e6216662a5c3a51d6b89c55279dd51c to your computer and use it in GitHub Desktop.
Save louisswarren/4e6216662a5c3a51d6b89c55279dd51c to your computer and use it in GitHub Desktop.
Generate C make files automatically
import re
import sys
args = sys.argv[1:]
def find_dependencies(lines):
deps = set()
for line in lines:
match = re.match('#include "(.*)"', line)
if match:
deps.add(match.groups()[0])
return deps
for fname in args:
with open(fname) as f:
deps = find_dependencies(f.readlines())
print("{}: {}".format(fname, ' '.join(map(str, sorted(deps)))))
print("\t${CC} ${CFLAGS}", fname)
print()
@milesrout
Copy link

deps = set()
for line in lines:
    ...
    deps.add(...)
return deps

No @accumulate. 1/10 for effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment