#!/usr/bin/env python3 """Build game/db without either Makefile's production installation default.""" import argparse from pathlib import Path import subprocess def main(): p = argparse.ArgumentParser(description=__doc__) p.add_argument('--source', type=Path, required=True, help='directory containing server/ and extern/') p.add_argument('--output', type=Path, required=True) p.add_argument('--target', choices=['game', 'db'], required=True) p.add_argument('--jobs', type=int, default=1) a = p.parse_args() source, output = a.source.resolve(), a.output.resolve() for destination in (output, (output/'bin').resolve(), (output/'work').resolve()): if destination == Path('/usr/metin2/server') or Path('/usr/metin2/server') in destination.parents: p.error('build outputs must not be inside the production server tree') for name in ('bin', 'work', 'obj-'+a.target): (output/name).mkdir(parents=True, exist_ok=True) # DB uses DBDIR, game uses GAMEDIR. Always override both, even when building one target. subprocess.run(['gmake', '-j%d' % max(1, a.jobs), 'BINDIR='+str(output/'work'), 'GAMEDIR='+str(output/'bin'), 'DBDIR='+str(output/'bin'), 'OBJDIR='+str(output/('obj-'+a.target))], cwd=source/'server'/a.target/'src', check=True) if __name__ == '__main__': main()