-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
135 lines (109 loc) · 3.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
PROJECTS = chubby-hat hc245t-bypass-esd
PANELS = hc245t-bypass-esd-panel
# Turn on increased build verbosity by defining BUILD_VERBOSE in your main
# Makefile or in your environment. You can also use V=1 on the make command
# line.
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE=$(V)
endif
ifndef BUILD_VERBOSE
$(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.)
BUILD_VERBOSE = 0
endif
ifeq ($(BUILD_VERBOSE),0)
Q = @
else
Q =
endif
KICAD_CLI ?= kicad-cli
PDFUNITE ?= pdfunite
PCB_HELPER ?= ./scripts/pcb_helper.py
OPENSCAD ?= openscad
PLOTS=$(addprefix exports/plots/, $(PROJECTS))
PLOTS_SCH=$(addsuffix -sch.pdf, $(PLOTS))
PLOTS_PCB=$(addsuffix -pcb.pdf, $(PLOTS))
PLOTS_ALL=$(PLOTS_SCH) $(PLOTS_PCB)
GERBER_DIRS=$(addprefix production/gbr/, $(PROJECTS) $(PANELS))
GERBER_ZIPS=$(addsuffix .zip, $(GERBER_DIRS))
all: $(PLOTS_ALL) $(GERBER_ZIPS)
.PHONY: all
exports/plots/%-sch.pdf: source/*/%.kicad_sch
$(Q)$(KICAD_CLI) sch export pdf \
"$<" \
--output "$@"
exports/plots/%-pcb.pdf: source/*/%.kicad_pcb
$(eval tempdir := $(shell mktemp -d))
$(eval copper := $(shell $(PCB_HELPER) \
--pcb source/template/template.kicad_pcb \
copper \
))
$(Q)rm -f $@
$(Q)for layer in $(copper); do \
$(KICAD_CLI) pcb export pdf \
--include-border-title \
--layers "$$layer,Edge.Cuts" \
"$<" \
--output "$(tempdir)/$*-$$layer.pdf"; \
if [ -f "$@" ]; then \
cp "$@" "$(tempdir)/$*.pdf"; \
$(PDFUNITE) "$(tempdir)/$*.pdf" "$(tempdir)/$*-$$layer.pdf" "$@" 2>/dev/null; \
else \
mv "$(tempdir)/$*-$$layer.pdf" "$@"; \
fi \
done
$(Q)rm -r $(tempdir)
production/gbr/%.zip: source/*/%.kicad_pcb
$(eval stackup := Edge.Cuts $(shell $(PCB_HELPER) \
--pcb source/template/template.kicad_pcb \
stackup \
))
$(Q)rm -rf production/gbr/$*
$(Q)mkdir -p production/gbr/$*
$(Q)for layer in $(stackup); \
do \
$(KICAD_CLI) pcb export gerber \
--subtract-soldermask \
--layers $$layer \
"$<" \
--output "production/gbr/$*/$*-$$layer.gbr"; \
done
$(Q)$(KICAD_CLI) pcb export drill \
--excellon-separate-th \
--units mm \
"$<" \
--output "production/gbr/$*/"
$(Q)zip $@ production/gbr/$*/*
# special targets to make pattern
PATTERN=$(addprefix assets/art/, $(addsuffix -pattern.svg, chubby-hat))
pattern: $(PATTERN)
.PNONY: pattern
assets/art/chubby-hat-pattern.svg: source/chubby-hat/chubby-hat.kicad_pcb scripts/pattern.scad
$(Q)$(eval tempdir := $(shell mktemp -d))
$(Q)$(KICAD_CLI) pcb export svg \
--exclude-drawing-sheet \
--page-size-mode 2 \
--layers "F.Mask,F.SilkS" \
"$<" \
--output "$(tempdir)/$*-mask.svg"
@echo
$(Q)$(KICAD_CLI) pcb export svg \
--exclude-drawing-sheet \
--page-size-mode 2 \
--layers "User.6" \
"$<" \
--output "$(tempdir)/$*-edge.svg"
@echo
$(Q)$(OPENSCAD) scripts/pattern.scad \
-D size=3 \
-D margin=2 \
-D 'edge="$(tempdir)/$*-edge.svg"' \
-D 'mask="$(tempdir)/$*-mask.svg"' \
-o $@
$(Q)sed --expression 's/stroke\S*="\S*"//g' --in-place $@
$(Q)rm -r $(tempdir)
clean:
$(Q)rm -rf $(PLOTS_ALL)
$(Q)rm -rf $(GERBER_DIRS)
$(Q)rm -rf $(GERBER_ZIPS)
$(Q)rm -rf $(PATTERN)
.PHONY: clean