aboutsummaryrefslogtreecommitdiff
path: root/kicad/lib/tools/make_eboard_lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'kicad/lib/tools/make_eboard_lib.sh')
-rwxr-xr-xkicad/lib/tools/make_eboard_lib.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/kicad/lib/tools/make_eboard_lib.sh b/kicad/lib/tools/make_eboard_lib.sh
new file mode 100755
index 0000000..1399513
--- /dev/null
+++ b/kicad/lib/tools/make_eboard_lib.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Build kicad/lib/eboard.kicad_sym:
+# - symbols generated by kipart from the CSV files in this folder,
+# - plus ready-made symbols from the *.kicad_sym files in this folder
+# (e.g. the HR911130A symbol from a KiCad library merge request).
+#
+# kicad/lib/tools/make_eboard_lib.sh
+#
+# Needs kipart (pipx install kipart).
+set -eu
+here=$(cd "$(dirname "$0")" && pwd)
+command -v kipart >/dev/null 2>&1 || {
+ echo "kipart not found; install it with: pipx install kipart" >&2
+ exit 1
+}
+out=$here/../eboard.kicad_sym
+tmp=$(mktemp -d)
+trap 'rm -rf "$tmp"' EXIT
+
+kipart -b --bundle-style none -w -o "$tmp/raw.kicad_sym" \
+ "$here"/ch347f.csv "$here"/rtl8211f.csv "$here"/sm410561n.csv
+python3 -I "$here/kicad_sym_grid.py" "$tmp/raw.kicad_sym" > "$tmp/grid.kicad_sym"
+
+# append the top-level symbols of the extra libraries
+python3 -I - "$tmp/grid.kicad_sym" "$here"/*.kicad_sym > "$out" <<'EOF'
+import re, sys
+
+
+def match_paren(t, i):
+ depth, j = 0, i
+ while True:
+ c = t[j]
+ if c == '"':
+ j += 1
+ while t[j] != '"':
+ j += 2 if t[j] == "\\" else 1
+ elif c == "(":
+ depth += 1
+ elif c == ")":
+ depth -= 1
+ if depth == 0:
+ return j + 1
+ j += 1
+
+
+base = open(sys.argv[1]).read()
+blocks = []
+for path in sys.argv[2:]:
+ t = open(path).read()
+ i = t.index("(", 1)
+ while True:
+ m = re.compile(r'\(symbol "').search(t, i)
+ if not m:
+ break
+ e = match_paren(t, m.start())
+ blocks.append(t[m.start():e])
+ i = e
+end = base.rstrip().rfind(")")
+sys.stdout.write(base[:end] + "".join(" " + b + "\n" for b in blocks) + ")\n")
+EOF
+echo "wrote $out"