all: plot-zip positions

gerbers:
	kicad-cli pcb export gerbers 48ish_soldered.kicad_pcb --board-plot-params -o 48ish_soldered_out/mbk
	kicad-cli pcb export gerbers 48ish_soldered_cfx.kicad_pcb --board-plot-params -o 48ish_soldered_out/cfx

drills:
	kicad-cli pcb export drill 48ish_soldered.kicad_pcb --excellon-separate-th -o 48ish_soldered_out/mbk
	kicad-cli pcb export drill 48ish_soldered_cfx.kicad_pcb --excellon-separate-th -o 48ish_soldered_out/cfx

positions:
	kicad-cli pcb export pos 48ish_soldered.kicad_pcb --format csv --units mm --side back --smd-only -o 48ish_soldered_mbk-bottom-pos.csv
	kicad-cli pcb export pos 48ish_soldered_cfx.kicad_pcb --format csv --units mm --side back --smd-only -o 48ish_soldered_cfx-bottom-pos.csv
	# replace headers with what jlcpcb wants - see https://jlcpcb.com/help/article/How-to-generate-the-BOM-and-Centroid-file-from-KiCAD
	sed -e 's/Ref/Designator/' -e 's/PosX/Mid X/' -e 's/PosY/Mid Y/' -e 's/Rot/Rotation/' -e 's/Side/Layer/' -i 48ish_soldered_mbk-bottom-pos.csv
	sed -e 's/Ref/Designator/' -e 's/PosX/Mid X/' -e 's/PosY/Mid Y/' -e 's/Rot/Rotation/' -e 's/Side/Layer/' -i 48ish_soldered_cfx-bottom-pos.csv

plot: gerbers drills

plot-zip: gerbers drills
	zip -FSr 48ish_soldered_mbk_out.zip 48ish_soldered_out/mbk
	zip -FSr 48ish_soldered_cfx_out.zip 48ish_soldered_out/cfx
