#!/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"