cosmopolitan/tool/scripts/get-deps.py
Justine Tunney 6f7d0cb1c3
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
2022-09-12 23:36:56 -07:00

38 lines
907 B
Python
Executable file

#!/usr/bin/env python.com
#
# OVERVIEW
#
# One-Off Makefile Rule Generator
#
# EXAMPLES
#
# tool/scripts/get-deps.py examples/hello.c
# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2'
#
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)