mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 23:13:34 +00:00
29 lines
638 B
Python
29 lines
638 B
Python
|
#!/usr/bin/env python.com
|
||
|
|
||
|
import os
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
def GetDeps(path):
|
||
|
sys.stdout.write('o/$(MODE)/%s.o:' % (os.path.splitext(path)[0]))
|
||
|
deps = set()
|
||
|
def Dive(path):
|
||
|
if path in deps:
|
||
|
return
|
||
|
deps.add(path)
|
||
|
sys.stdout.write(' \\\n\t\t%s' % (path))
|
||
|
with open(path) as f:
|
||
|
code = f.read()
|
||
|
for dep in re.findall(r'[.#]include "([^"]+)"', code):
|
||
|
Dive(dep)
|
||
|
Dive(path)
|
||
|
sys.stdout.write('\n')
|
||
|
|
||
|
for arg in sys.argv[1:]:
|
||
|
if os.path.isdir(arg):
|
||
|
for dirpath, dirs, files in os.walk(arg):
|
||
|
for filepath in files:
|
||
|
GetDeps(os.path.join(dirpath, filepath))
|
||
|
else:
|
||
|
GetDeps(arg)
|