import argparse import sys import ee.kicad as kicad out_file = sys.stdout def p(msg): global out_file print(msg, file=out_file) def work(args): if args.sch: sch = kicad.read_schematics(args.sch) p("# This file is generated") p("ifeq ($(EE),)") p(" $(error EE must be set)") p("endif") p("") p("SCH_FILES =") for path in sorted([s.path for s in sch.schematics]): p("SCH_FILES += {}".format(path)) if args.pcb: if args.gerber: p("# Gerber rules") p("ifeq ($(GERBER_ZIP),)") p(" $(error GERBER_ZIP must be set)") p("endif") p("gerbers: $(GERBER_ZIP)") p("$(GERBER_ZIP): $(SCH_FILES)") p("\t@echo GERBER") p("\t$(EE) kicad-gerber \\") p("\t\t--output-dir $(GERBER_DIR) \\") p("\t\t--pcb $(PROJECT).kicad_pcb \\") p("\t\t$(GERBER_ARGS)") p("\tmkdir -p $(dir $@)") p("\t(cd $(GERBER_DIR); zip tmp.zip $(foreach GBR,$(GERBERS),$(notdir $(GBR))))") p("\tmv $(GERBER_DIR)/tmp.zip $@") p("EE_OUTPUTS += $(GERBER_ZIP)") p("") parser = argparse.ArgumentParser(description="Create a Makefile with all dependencies") parser.add_argument("--sch", metavar="SCH", help="Schematic file") parser.add_argument("--pcb", metavar="PCB", help="PCB file") parser.add_argument("--out", metavar="OUT", help="Output file") parser.add_argument("--gerber", action="store_true", help="Enable gerber.zip target") args = parser.parse_args() if not args.sch and not args.pcb: print("At least one of --sch or --pcb has to be used", file=sys.stderr) if args.out: with open(args.out, "w") as f: out_file = f work(args) else: work(args)