#!/usr/bin/env python3

import sys
import tempfile
import os
import shutil

if __name__ == "__main__":
    target = sys.argv[1]

    with tempfile.TemporaryDirectory(prefix="intercalate-") as tmp:
        op = os.path.join(tmp, "out")
        with open(op, "wb") as o:
            for i, p in enumerate(sorted(sys.argv[2:])):
                if i > 0:
                    o.write(b"\n")
                with open(p, "rb") as f:
                    o.write(f.read())

        shutil.copy(op, target)
