from __future__ import print_function import sys import argparse import ee.kicad as kicad out_file = sys.stdout def p(msg): global out_file print(msg, file=out_file) def work(args): 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 s in sch.schematics: p("SCH_FILES += {}".format(s.path)) 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("") p("") p("# Utility targets") p(".PHONY: schematic pcb gerber") p("schematic: $(SCH_FILES)") p("pcb: {}".format(args.pcb)) parser = argparse.ArgumentParser(description="Create a Makefile with all dependencies") parser.add_argument("--sch", required=True, metavar="SCH", help="Schematic file") parser.add_argument("--pcb", required=True, 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 args.out: with open(args.out, "w") as f: out_file = f work(args) else: work(args)