Skip to content

Instantly share code, notes, and snippets.

@edsammy
Last active October 20, 2025 15:55
Show Gist options
  • Select an option

  • Save edsammy/21d256f764db68f7f5238bce2add4004 to your computer and use it in GitHub Desktop.

Select an option

Save edsammy/21d256f764db68f7f5238bce2add4004 to your computer and use it in GitHub Desktop.
kibot stuff
#!/bin/bash
function convert_path {
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'
}
function debug_run {
# Interactive docker mode
# Set MYIP to local IP address to use xdisplay
$WINPTY docker run --rm -it \
-v $STUDLABS_KICAD_LIBS:/root/studlabs/repo/STUDLABS_KICAD_LIBS \
-v $HARP:/root/studlabs/tools/harp \
-v $PWD:/root/studlabs/repo/$DIR_NAME \
-e DISPLAY=$MYIP:0.0 \
studlabs_kiauto
exit 1
}
if [ -z "$STUDLABS_KICAD_LIBS" ]; then
echo "Missing STUDLABS_KICAD_LIBS environment variable"
echo -e "\t export STUDLABS_KICAD_LIBS=<path/to/STUDLABS_KICAD_LIBS>"
exit 1
fi
if [ -z "$HARP" ]; then
# Below only seemed to work on Windows
#HARP=$(dirname $(echo $PATH | sed -e 's/:/\n/g' | grep harp))
echo "Missing HARP environment variable"
echo -e "\t export HARP=<path/to/harp>"
exit 1
fi
if [[ "$OSTYPE" == "msys" ]]; then
STUDLABS_KICAD_LIBS=$(convert_path $studlabs_KICAD_LIBS)
HARP=$(convert_path $HARP)
DIR_NAME=${PWD##*/}
PWD=$(convert_path $PWD/)
else
DIR_NAME=${PWD##*/}
fi
if [[ $1 == -d ]]; then
debug_run
fi
$WINPTY docker run --rm -it \
-v $STUDLABS_KICAD_LIBS:/root/studlabs/repo/STUDLABS_KICAD_LIBS \
-v $HARP:/root/studlabs/tools/harp \
-v $PWD:/root/studlabs/repo/$DIR_NAME \
studlabs_kiauto sh -c "cd /root/studlabs/repo/$DIR_NAME; make $1"
BOARD_DIR_NAME = $(notdir $(CURDIR:%/=%))
GERB = $(PWD)/output/gerbers
DATE = `date +%m_%d_%Y_%H%M%S`
HARP_PATH = $(HOME)/very/tools/harp
KIBOT_TEMPLATES = $(HARP_PATH)/KIBOT_TEMPLATES
DEBUG_FLAG = $(DEBUG)
PCBS := $(wildcard */*.kicad_pcb)
.PHONY: all bom step sch_pdf position gerbers_zip drawing fab
all: bom step sch_pdf position gerbers_zip drawing fab
bom:
kibot $(DEBUG) -c $(KIBOT_TEMPLATES)/bom.kibot.yaml
step:
kibot $(DEBUG) -c $(KIBOT_TEMPLATES)/step.kibot.yaml
sch_pdf:
kibot $(DEBUG) -c $(KIBOT_TEMPLATES)/sch.kibot.yaml --skip-pre run_erc,run_drc
position:
kibot $(DEBUG) -c $(KIBOT_TEMPLATES)/position.kibot.yaml
gerbers:
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/gerbers_$(LAYERS)layer.kibot.yaml
gerbers_zip: gerbers
cd $(GERB)/raw; zip ../$(BOARD_DIR_NAME)_rev_$(REV)-gerbers.zip *
rm -rf $(GERB)/raw
drawing:
rm -f output/fabrication/*-Assembly.pdf
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/fabrication.kibot.yaml front_assembly
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/fabrication.kibot.yaml back_assembly
pdftk output/fabrication/*-F_Fab.pdf background $(HARP_PATH)/assets/frame.pdf output output/fabrication/temp-F_Fab.pdf
pdftk output/fabrication/*-B_Fab.pdf background $(HARP_PATH)/assets/frame.pdf output output/fabrication/temp-B_Fab.pdf
pdftk output/fabrication/temp-F_Fab.pdf output/fabrication/temp-B_Fab.pdf cat output output/fabrication/$(BOARD_DIR_NAME)_rev_$(REV)-Assembly.pdf
rm output/fabrication/*-*_Fab.pdf
fab:
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/fabrication.kibot.yaml fabrication_drawing
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/fabrication.kibot.yaml drill_map_pdf
pdftk output/fabrication/*-Fabrication-tmp.pdf background $(HARP_PATH)/assets/frame.pdf output output/fabrication/$(BOARD_DIR_NAME)_rev_$(REV)-Fabrication-tmp2.pdf
pdftk output/fabrication/*-DrillMap-tmp.pdf background output/fabrication/$(BOARD_DIR_NAME)_rev_$(REV)-Fabrication-tmp2.pdf output output/fabrication/$(BOARD_DIR_NAME)_rev_$(REV)-Fabrication.pdf
rm output/fabrication/*-tmp*.pdf
drill_map:
kibot $(DEBUG) -b $(wildcard *.kicad_pcb) -c $(KIBOT_TEMPLATES)/fabrication.kibot.yaml drill_map
export_3d:
#remove old pics if they exist, --force to ignore if they dont exist
rm --force output/3d/*-*.jpg
pcbnew_do -v $(DEBUG) --rec_width 3840 --rec_height 2160 3d_export $(wildcard *.kicad_pcb) output/3d/
# interactive debug with `ssvncviewer :0`
zip_all: readme
cd $(PWD)/output; zip -r ../$(IMPN)_rev_$(REV).zip *
readme:
cd $(PWD)/output; echo \
"Internal Part Number: $(IMPN)\n\
Date: $(DATE)\n\
Contact Engineer: $(CONTACT)\n\
Directory Structure:\n\`\`\`" > README.md; \
tree -I 'README.md' >> README.md; echo "\`\`\`" >> README.md
debug:
echo $(BOARD_DIR_NAME)
clean:
rm -rf output/
LAYERS = 2
REV = 1.2.3
include ~/very/tools/harp/Makefiles/main.mk
rev:
@echo $(REV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment