32 lines
1.7 KiB
Python
Executable File
32 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Prepare historical DDK includes. Refuse ambiguous header/library choices."""
|
|
import os, pathlib, sys, shutil
|
|
root, out = map(pathlib.Path,sys.argv[1:3]); out.mkdir(parents=True, exist_ok=True)
|
|
inc=os.environ.get('NT4_DDK_INCLUDE'); lib=os.environ.get('NT4_NDIS_LIB')
|
|
if inc:
|
|
dirs=[pathlib.Path(p) for p in inc.split(':')]
|
|
else:
|
|
dirs=[]
|
|
for name in ('ndis.h','ntddk.h'):
|
|
matches=[p for p in root.rglob('*') if p.is_file() and p.name.lower()==name]
|
|
if len(matches)!=1: sys.exit(f'{name}: ambiguous/missing {matches}; set NT4_DDK_INCLUDE (colon-separated directories)')
|
|
if matches[0].parent not in dirs: dirs.append(matches[0].parent)
|
|
# Lowercase aliases plus original basename, reject different contents for same name.
|
|
for d in dirs:
|
|
for p in d.iterdir():
|
|
if not p.is_file() or p.suffix.lower() not in ('.h','.inc'): continue
|
|
for name in {p.name,p.name.lower(),p.name.upper()}:
|
|
dest=out/name
|
|
if dest.exists() and dest.read_bytes()!=p.read_bytes(): sys.exit(f'Header conflict: {p} / {dest}')
|
|
if not dest.exists(): shutil.copyfile(p,dest)
|
|
if not lib:
|
|
paths=[p for p in root.rglob('*') if p.is_file() and p.name.lower()=='ndis.lib']
|
|
x86=[p for p in paths if any(s.lower() in ('i386','x86','386') for s in p.parts)]
|
|
# Prefer the retail x86 library over checked/debug and other CPUs.
|
|
free=[p for p in x86 if "free" in [s.lower() for s in p.parts]]
|
|
paths=free if free else x86
|
|
if len(paths)!=1: sys.exit(f'NDIS.LIB ambiguous/missing {paths}; set NT4_NDIS_LIB to x86 library')
|
|
lib=str(paths[0])
|
|
if not pathlib.Path(lib).is_file(): sys.exit('NDIS.LIB not found')
|
|
print(str(pathlib.Path(lib).resolve()))
|