1#!/usr/bin/env python3 2 3"This tool is intended to be used from meson" 4 5import os, sys, shutil 6 7if len (sys.argv) < 3: 8 sys.exit (__doc__) 9 10OUTPUT = sys.argv[1] 11CURRENT_SOURCE_DIR = sys.argv[2] 12 13# make sure input files are unique 14sources = sorted(set(sys.argv[3:])) 15 16with open (OUTPUT, "wb") as f: 17 f.write ("".join ('#include "{}"\n'.format (os.path.relpath (os.path.abspath (x), CURRENT_SOURCE_DIR)) for x in sources if x.endswith (".cc")).encode ()) 18 19# copy it also to the source tree, but only if it has changed 20baseline_filename = os.path.join (CURRENT_SOURCE_DIR, os.path.basename (OUTPUT)) 21with open(baseline_filename, "rb") as baseline: 22 with open(OUTPUT, "rb") as generated: 23 if baseline.read() != generated.read(): 24 shutil.copyfile (OUTPUT, baseline_filename) 25