Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
679 lines (620 loc) · 37.8 KB
/
Copy pathMakefile
File metadata and controls
679 lines (620 loc) · 37.8 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# ─────────────────────────────────────────────────────────────────────────────
# Chip Hippo – TTL breadboard designer & simulator
# Electron desktop app (Vanilla JS + Node.js)
# ─────────────────────────────────────────────────────────────────────────────
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown")
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# Workspace directories
WORKSPACE ?= $(realpath $(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
BUILD_DIR ?= $(WORKSPACE)/build
DIST_DIR ?= $(WORKSPACE)/dist
DATA_DIR ?= $(WORKSPACE)/data
SRC_DIR ?= $(WORKSPACE)/src
WEB_DIR ?= $(WORKSPACE)/src/web
APP_DIR ?= $(WORKSPACE)/src/app
SHELL := /bin/bash
# ── Shared dev environment ────────────────────────────────────────────────────
# One place to set the values every dev target sees. Copy dev.env.example →
# dev.env (git-ignored) and edit it; `-include` is after the ?= defaults so
# dev.env wins over them, while a one-off `make VAR=value` still wins over both.
DEV_ENV_VARS :=
-include $(WORKSPACE)/dev.env
export $(DEV_ENV_VARS)
# Bare `make` builds an unsigned local dmg (macOS). Signed/release targets and
# the full multi-platform matrix arrive with the packaging backlog stage.
.DEFAULT_GOAL := dmg
# Neutralize signing for one electron-builder call: disable keychain
# auto-discovery so the output is unsigned regardless of any identities in the
# keychain. Paired per-recipe with `-c.mac.notarize=false` to also force
# notarization off. Signed builds arrive with the packaging backlog stage.
UNSIGNED_ENV := CSC_IDENTITY_AUTO_DISCOVERY=false
# A Mac App Store build signs with the Apple Distribution (the .app) and Mac
# Installer Distribution (the .pkg) identities, both of which live in the login
# keychain. A Developer ID .p12 handed over in CSC_LINK — which is what the
# direct/release builds use — is INVALID for MAS: electron-builder would sign
# with it and fall back to an ad-hoc signature the store rejects and macOS will
# not launch. So locally we strip CSC_LINK and let keychain auto-discovery find
# the right ones. In CI the store job supplies real MAS certs and sets
# MAS_PROVISIONING_PROFILE_BASE64; that marker is how we know not to strip.
ifeq ($(strip $(MAS_PROVISIONING_PROFILE_BASE64)),)
MAS_SIGN_ENV := env -u CSC_LINK -u CSC_KEY_PASSWORD CSC_IDENTITY_AUTO_DISCOVERY=true
else
MAS_SIGN_ENV :=
endif
# electron-builder applies ONE name qualifier to BOTH identity searches — the
# .app's and the .pkg installer's — so it has to be the substring common to
# "Apple Distribution: Jason Figge (2C564TQ2FY)" and "3rd Party Mac Developer
# Installer: Jason Figge (2C564TQ2FY)". Anything more specific (e.g. "Apple
# Distribution") filters the installer search down to nothing and the build
# dies with "Cannot find valid 3rd Party Mac Developer Installer". Override
# per-account.
MAS_CSC_NAME ?= Jason Figge (2C564TQ2FY)
# App Store Connect refuses a second upload carrying a build number it has
# already seen, and the MARKETING version cannot be the thing that moves: the
# version record was created against CFBundleShortVersionString exactly, so
# bumping `version` in src/package.json orphans the build from the record it
# belongs to. What moves is CFBundleVersion, which is what this sets — e.g.
#
# make mas MAS_BUILD_VERSION=1.0.1
#
# THREE COMPONENTS AT MOST. Apple defines CFBundleVersion as a period-separated
# list of at most three non-negative integers, and App Store Connect REJECTS a
# fourth: a `<marketing>.<n>` build number (1.0.0.1) reads as four and bounces
# on upload. So the build number is its own three-part counter that only has to
# be unique and ascending — it does NOT have to look like the marketing version,
# and 1.0.1 as a build number under a 1.0.0 marketing version is correct.
#
# Empty by default, in which case electron-builder uses `version` for both and
# a first upload of a version needs no ceremony.
MAS_BUILD_VERSION ?=
MAS_BUILD_VERSION_ARG := $(if $(MAS_BUILD_VERSION),-c.mac.bundleVersion=$(MAS_BUILD_VERSION),)
# ─── Version / Info ───────────────────────────────────────────────────────────
version:
@echo "Version: $(VERSION)"
info:
@echo "Build Information:"
@echo " Version: $(VERSION)"
@echo " Branch: $(BRANCH)"
@echo " Commit: $(COMMIT)"
@echo " Build Time: $(BUILD_TIME)"
# ─── Dependencies ─────────────────────────────────────────────────────────────
install:
@echo "Installing Node.js dependencies..."
@cd $(SRC_DIR) && npm ci
@echo "--------------------------------"
# ─── Development ──────────────────────────────────────────────────────────────
debug:
@echo "Starting Electron in debug mode (hot-reload)..."
@cd $(SRC_DIR) && npx electron app/main.js --hot-reload --user-data-dir=$(DATA_DIR)
@echo "--------------------------------"
# ─── Formatting ───────────────────────────────────────────────────────────────
# Covers the build tooling under scripts/ too (a sibling of src/, so prettier
# is pointed at it explicitly alongside the app/web globs below).
fmt:
@echo "Formatting JavaScript / CSS / HTML..."
@cd $(SRC_DIR) && npx prettier --write \
"web/**/*.{js,css,html}" \
"app/**/*.js" \
"../scripts/*.mjs" \
"../website/**/*.js" > /dev/null
@echo "--------------------------------"
fmt-check:
@echo "Checking formatting (prettier --check)..."
@cd $(SRC_DIR) && npx prettier --check \
"web/**/*.{js,css,html}" \
"app/**/*.js" \
"../scripts/*.mjs" \
"../website/**/*.js"
@echo "--------------------------------"
# ─── Linting ──────────────────────────────────────────────────────────────────
# Run from the REPO ROOT (not src/) so ESLint's base path — the boundary it
# refuses to lint outside of, silently — covers scripts/ too, not just src/.
# eslint.config.js's blocks anchor back to src/ via their own `basePath`.
lint:
@echo "Linting JavaScript..."
@cd $(WORKSPACE) && $(SRC_DIR)/node_modules/.bin/eslint \
--config $(SRC_DIR)/eslint.config.js \
"src/web/scripts/**/*.js" \
"src/app/**/*.js" \
"scripts/**/*.mjs" \
"website/**/*.js"
@echo "--------------------------------"
# ─── License headers ──────────────────────────────────────────────────────────
# Stamp the GPL-3.0 header onto any first-party src/ JS+CSS or build script
# that is missing it (see CLAUDE.md → "License headers" for the scope).
license-headers:
@echo "Stamping GPL-3.0 license headers..."
@node $(WORKSPACE)/scripts/license-header.mjs
@echo "--------------------------------"
# ─── Testing ──────────────────────────────────────────────────────────────────
# Timeout so a leaked handle / never-resolving promise fails the run loudly
# instead of hanging the suite (and CI) forever.
#
# It is NOT a per-test budget, which is what the old 60s was picked as. Node
# runs each FILE as a test of its own, so the flag also caps the file wrapper —
# i.e. the SUM of that file's subtests. The number therefore has to be set from
# the slowest FILE on the slowest machine, and the floor is the auto-route
# corpus (Feature 360): a subtest per shipped example circuit, each routed
# through the real router. Real work, not a hang, and the whole point of that
# test is that it is real.
#
# 60s left that file no headroom at all, so it passed here and TIMED OUT on
# every CI run from the day it landed. Measured against a failing run's own log,
# a GitHub ubuntu runner takes 1.5x the CPU-bound tests and a median 2.35x the
# suite — and the corpus is contended by the files running beside it. 300s
# served while it was 54 subtests (~48s on a dev Mac); at 96 over 94 examples
# it takes ~460s on a 4-core Linux container, and timed out. 900s is twice
# that; a genuine hang still fails, it just takes fifteen minutes to say so.
TEST_TIMEOUT ?= 900000
# Digital (hneemann/Digital, with its lib/ beside it) for the two Digital
# export checks in export-digital-cli.test.js. It lives in the git-ignored
# data/ folder, so on a machine without it (CI) this is empty and those two
# tests SKIP; `make test` runs them when it is there (~6 min more, one java
# per bench). `make test-fast` leaves them out. Override: DIGITAL_JAR=/path.
DIGITAL_JAR ?= $(wildcard $(WORKSPACE)/data/digital/Digital.jar)
# `make test` is the COMPLETE run — the one to trust before calling work done,
# and the one CI runs. `make test-fast` is the quick confirmation while
# iterating (~2.5 min against ~8): every test file still runs, but one whose
# cost is a corpus — today the auto-route corpus — samples it
# (CHIPHIPPO_TEST_FAST=1, read through web/scripts/tests/test-depth.js) and
# reports the rest as SKIPPED, each saying `make test` runs it.
test: test-license-headers
@echo "Running JavaScript unit tests..."
@cd $(SRC_DIR) && DIGITAL_JAR="$(DIGITAL_JAR)" node --test --test-timeout=$(TEST_TIMEOUT) \
"app/tests/**/*.test.js" \
"web/scripts/tests/**/*.test.js"
@echo "--------------------------------"
test-fast: test-license-headers
@echo "Running JavaScript unit tests (FAST: the slow corpus sampled — make test runs it whole)..."
@cd $(SRC_DIR) && CHIPHIPPO_TEST_FAST=1 DIGITAL_JAR= node --test --test-timeout=$(TEST_TIMEOUT) \
"app/tests/**/*.test.js" \
"web/scripts/tests/**/*.test.js"
@echo "--------------------------------"
# The language guards on their own — the fast loop while translating. All five
# also run as part of `make test` (the globs above pick them up); this target
# exists so a catalog edit can be checked in a second rather than a minute.
# · i18n — the resolver (main) and the t()/tf() seam (renderer)
# · i18n-catalogs — THE UNTRANSLATED-STRING GUARD: every locale covers
# en.json exactly, keeps its {placeholders} and plural
# shapes, and every key the source asks for exists
# · no-hardcoded-* — the two leak scanners: a display literal that never
# entered the catalog, in the renderer and in main
test-i18n:
@echo "Running language tests (catalog completeness + hardcoded-string guards)..."
@cd $(SRC_DIR) && node --test --test-timeout=$(TEST_TIMEOUT) \
app/tests/i18n.test.js \
app/tests/no-hardcoded-native-strings.test.js \
web/scripts/tests/i18n.test.js \
web/scripts/tests/i18n-catalogs.test.js \
web/scripts/tests/no-hardcoded-strings.test.js
@echo "--------------------------------"
# Guard: every first-party src/ JS+CSS file and build script must carry the
# GPL-3.0 header. Fix any failure with `make license-headers`.
test-license-headers:
@echo "Checking GPL-3.0 license headers (guard)..."
@node $(WORKSPACE)/scripts/license-header.mjs --check
@echo "--------------------------------"
# ─── Icons ────────────────────────────────────────────────────────────────────
# Regenerate every app-icon raster (macOS .png, Windows .ico, Linux set + logo)
# from src/web/chiphippo-icon.svg and src/web/chiphippo-mac-icon.svg. Runs under
# Electron (a transparent offscreen window rasterises the SVGs; qlmanage would
# flatten their transparency onto white); outputs are committed and consumed at
# build + run time.
icons:
@echo "Regenerating app icons from the SVG sources..."
@cd $(SRC_DIR) && npx electron $(WORKSPACE)/scripts/make-icons.mjs
@echo "--------------------------------"
# ─── Datasheets ───────────────────────────────────────────────────────────────
# REPORT which datasheet crops the pin-assignments window wants and does not
# have, so they can be produced by hand. It does NOT generate anything.
#
# This target used to re-crop every PNG under src/web/datasheets/ out of the
# source PDFs, under Electron via pdfjs. It never cropped them well enough to
# ship — the crops are cut by hand and committed — so the generator and its crop
# manifest are gone (the manifest went in c398291, which left the generator
# importing a file that no longer existed, i.e. the target has been broken
# rather than merely imprecise ever since).
#
# What was actually wanted from the tooling is the bookkeeping: a part with no
# crop is INVISIBLE, because chip-pinout.js drops the <figure> on a load error
# and the window looks exactly like one for a part that never had a datasheet.
# So this walks the catalog, checks the committed files, and names the gaps in
# both directions — missing crops to cut, and orphaned files no part asks for.
# Plain Node: no PDFs, no Electron, no network, and nothing is written.
datasheets:
@echo "Checking datasheet crops for the pinout window..."
@node $(WORKSPACE)/scripts/check-datasheets.mjs
@echo "--------------------------------"
# Ask every datasheet URL Settings ▸ Data Sheets ▸ Download… would fetch
# whether it still answers with a PDF. The one target here that goes to the
# NETWORK, which is exactly why it is not part of `make test`: the suite must
# not go red because a vendor's server is slow. Each unique URL is requested
# once; a failure names every part that shares it. `--strict` (add it by hand)
# exits 1 on a failure.
datasheet-urls:
@echo "Checking the datasheet download URLs (network)..."
@node $(WORKSPACE)/scripts/check-datasheet-urls.mjs
@echo "--------------------------------"
# `make spice-golden` regenerates Spice Lite's golden references
# (features/spice-lite-3-plan.md, Phase 0): every case in
# src/web/scripts/tests/spice-golden-cases.js as an ngspice deck
# (scripts/spice-deck.mjs), its numbers written to tests/spice-golden/*.json.
# Those are committed, so `make test` (spice-golden.test.js) needs no ngspice;
# without it this says so and changes nothing. GOLDEN=<case or area …> redoes
# only those.
spice-golden:
@echo "Regenerating the Spice Lite golden references (ngspice)..."
@node $(WORKSPACE)/scripts/spice-golden.mjs $(GOLDEN)
@echo "--------------------------------"
# ─── Demos ────────────────────────────────────────────────────────────────────
# Regenerate the loadable demo schematics in demos/ (a .chiphippo layout + a .hex
# ROM image each). The generator computes every wire from the model and then runs
# each demo through the simulation engine, asserting the LED blinks / the LCD
# prints "HI" before writing the files. Plain Node — no Electron needed.
#
# The second generator writes the per-chip demonstration projects: ONE PROJECT
# PER CATALOG GROUP (NAND, Flip-flop, Multiplexer…) holding a desktop for every
# chip in it — a logic bench per 74xx part, each proved out by enumerating its
# whole truth table (or clocking it edge by edge) through the engine before the
# file is written. It writes each of those desktops a SECOND time, on its own,
# to src/web/demos/<ref>.json — the copy that ships inside the app, which a
# chip's pin-assignments window offers as its example circuit. One build, two
# outputs, so the two can never drift.
demos:
@echo "Regenerating + validating the demo schematics..."
@node $(WORKSPACE)/scripts/make-demos.mjs
@node $(WORKSPACE)/scripts/make-gate-demos.mjs
@echo "--------------------------------"
# ─── Performance ────────────────────────────────────────────────────────────────
# Two measurements of the same busy circuit (web/scripts/bench/busy-circuit.js:
# a chained counter with decoders, displays and LEDs, one clock driving it all).
#
# `make bench` times the ENGINE headless under node --test — ms per tick, where
# a tick goes, settle/step passes per tick, and per-chip evaluation counts —
# with BENCH_SLICES (default 8) and BENCH_EDGES (400). Not part of `make test`.
#
# `make profile` runs the real app on it and records a DevTools trace + CPU
# profile (PROFILE_SLICES, PROFILE_SECONDS, PROFILE_SPEED "×4", PROFILE_OUT),
# reporting engine vs views vs browser rendering on the main thread. It
# launches Electron on a throwaway --user-data-dir, never data/.
#
# `make bench` also runs the Spice Lite ISLANDS bench (web/scripts/bench/
# islands.bench.js — independent sub-circuits on one desk, driven as
# SimController drives them: ms, ticks, settles, passes, chip evaluations and
# `outputs`-hook calls per simulated second, and each oscillator's measured
# period). BENCH_JSON=path writes its numbers as JSON (a path relative to the
# repo root); `make bench-compare BASE=a.json HEAD=b.json` sets two side by
# side. BENCH_ONLY=islands skips the busy-circuit tick bench.
#
# `make perf-desk` writes a second fixture as a project to open by hand:
# data/perf-two-board.chiphippo (PERF_OUT to override, PERF_HZ for the clock)
# — web/scripts/bench/two-board-circuit.js, twelve chips filling two snapped
# Full 830 kits, checked edge by edge on both engines before it is written.
# PROFILE_FIXTURE=two-board makes `make profile` run it instead.
BENCH_JSON ?=
BENCH_ONLY ?=
bench:
@echo "Benchmarking the simulation engine..."
@if [ "$(BENCH_ONLY)" != "islands" ]; then cd $(SRC_DIR) && node --test --test-timeout=$(TEST_TIMEOUT) web/scripts/bench/engine.bench.js; fi
@cd $(SRC_DIR) && BENCH_JSON="$(if $(BENCH_JSON),$(abspath $(BENCH_JSON)))" node --test --test-timeout=$(TEST_TIMEOUT) web/scripts/bench/islands.bench.js
@echo "--------------------------------"
bench-compare:
@node $(WORKSPACE)/scripts/bench-compare.mjs "$(abspath $(BASE))" "$(abspath $(HEAD))"
profile:
@echo "Profiling the app on a busy circuit..."
@node $(WORKSPACE)/scripts/profile-desk.mjs
@echo "--------------------------------"
perf-desk:
@echo "Writing + validating the two-board performance circuit..."
@node $(WORKSPACE)/scripts/make-perf-desk.mjs
@echo "--------------------------------"
# ─── User guide (Feature 230) ───────────────────────────────────────────────────
# One Markdown source (src/web/docs/*.md) drives three outputs: the in-app
# Help ▸ Chip Hippo User Guide window, this hosted website build, and the PDF.
# Rebuild the bundled marked+DOMPurify renderer the in-app viewer imports
# (web/scripts/vendor/markdown.js) from web/scripts/vendor/markdown-entry.js.
# A generated artifact — reformat it too so `make fmt-check` stays clean.
vendor-markdown:
@echo "Rebuilding the vendored Markdown renderer..."
@cd $(SRC_DIR) && npm run vendor-markdown --silent
@cd $(SRC_DIR) && npx prettier --write web/scripts/vendor/markdown.js > /dev/null
@echo "--------------------------------"
# Render src/web/docs/*.md into the Chip Hippo–themed static site under
# website/docs/, copy the images, and write website/sitemap.xml; then write
# website/chips.html, the supported-chips list, from the parts catalog.
docs:
@echo "Building the hosted user guide..."
@node $(WORKSPACE)/scripts/build-docs.mjs
@node $(WORKSPACE)/scripts/build-chips-page.mjs
@echo "--------------------------------"
PDF_OUT ?= $(WORKSPACE)/docs/chip-hippo-user-guide.pdf
# Stitch the same Markdown into one printable PDF (cover + contents + a
# section per page) via a hidden Electron window's printToPDF. Needs a
# display server on headless Linux/CI (xvfb-run); macOS runs it hidden.
pdf:
@echo "Building user-guide PDF..."
@mkdir -p $(dir $(PDF_OUT))
@cd $(SRC_DIR) && PDF_OUT="$(PDF_OUT)" npx electron $(WORKSPACE)/scripts/build-pdf.mjs
@echo " → $(PDF_OUT)"
@echo "--------------------------------"
# ─── Build ────────────────────────────────────────────────────────────────────
build: build-mac
# Fast, unsigned `--dir` packaging smoke-test: exercises the full
# electron-builder pack (asar, file globs, icons) without producing an
# installer. UNSIGNED_ENV keeps the output unsigned regardless of any keychain
# identities.
build-mac: build-setup build-install
@echo "Building Electron app for macOS (dir, unsigned)..."
@cd $(BUILD_DIR)/src; env $(UNSIGNED_ENV) npx electron-builder --mac --dir --publish never -c.mac.notarize=false
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
# Per-platform `--dir` packaging smoke-tests (no installer). CI runs the matching
# one on each native runner to prove the app packs; a given host can only build
# its own platform (mac needs macOS, etc.).
build-linux: build-setup build-install
@echo "Building Electron app for Linux (dir, unsigned)..."
@cd $(BUILD_DIR)/src; env $(UNSIGNED_ENV) npx electron-builder --linux --dir --publish never
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
build-win: build-setup build-install
@echo "Building Electron app for Windows (dir, unsigned)..."
@cd $(BUILD_DIR)/src; env $(UNSIGNED_ENV) npx electron-builder --win --dir --publish never
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
dmg: build-setup build-install
@echo "Building macOS .dmg (unsigned, un-notarized)…"
@cd $(BUILD_DIR)/src; env $(UNSIGNED_ENV) npx electron-builder --mac dmg --publish never -c.mac.notarize=false
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
build-setup:
@echo "Preparing build directory..."
@rm -rf $(BUILD_DIR)/src || true
@mkdir -p $(BUILD_DIR)/src
@rsync -a --exclude=node_modules $(SRC_DIR)/ $(BUILD_DIR)/src/
build-install:
@echo "Installing Node.js dependencies (build dir)..."
@cd $(BUILD_DIR)/src; npm install > /dev/null
@echo "--------------------------------"
# ─── Distribution packages ────────────────────────────────────────────────────
# Real installers per platform — the entrypoints the Release workflow runs on
# native runners. `dist` builds all three, but a given host can only build its
# own (a mac .dmg needs macOS, an .exe needs a Windows runner, etc.).
#
# Signing is driven by the ENVIRONMENT, not forced off like the convenience
# builds above: dist-mac signs + when creds are present. macOS reads CSC_LINK /
# CSC_KEY_PASSWORD (a Developer ID .p12) — absent ⇒ electron-builder emits an
# unsigned .app with no failure, so this works before any certificate exists (in
# CI those come from repository secrets; see .github/workflows/release.yml).
# Notarization is driven the same way and is NOT pinned off here: with Apple's
# credentials in the environment (APPLE_ID + APPLE_APP_SPECIFIC_PASSWORD +
# APPLE_TEAM_ID, or APPLE_API_KEY + APPLE_API_KEY_ID + APPLE_API_ISSUER) a
# signed build is notarized; without them electron-builder skips it and says so.
# A `-c.mac.notarize=false` here once shipped every release un-notarized however
# many secrets were configured — a signed download Gatekeeper still blocks.
dist: dist-mac dist-linux dist-win
dist-mac: build-setup build-install
@echo "Building macOS distribution (dmg + zip; signed if a cert is present)..."
@cd $(BUILD_DIR)/src; npx electron-builder --mac --publish never
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
dist-linux: build-setup build-install
@echo "Building Linux distribution (AppImage + deb)..."
@cd $(BUILD_DIR)/src; npx electron-builder --linux --publish never
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
dist-win: build-setup build-install
@echo "Building Windows distribution (nsis installer + portable)..."
@cd $(BUILD_DIR)/src; npx electron-builder --win --publish never
@echo " → $(BUILD_DIR)/src/dist/"
@echo "--------------------------------"
# ─── Store distributions ──────────────────────────────────────────────────────
# The Mac App Store channel. Unlike the direct builds these need Apple-issued
# material that cannot live in the repo — a provisioning profile per flavour,
# git-ignored under src/packaging/ (see STORE-PUBLISHING.md). Both targets GATE
# on their profile and skip cleanly without one, so a fresh clone still builds
# everything else. The gate and the build are ONE shell line (`; \` after the
# `fi`) so `exit 0` aborts the whole target rather than just its first line.
#
# What makes a store build different at RUNTIME is one gate, not a branch:
# src/app/store-build.js reads Electron's process.mas, and the self-updater
# switches itself off (Feature 280).
mas:
@if [ ! -f "$(SRC_DIR)/packaging/embedded.provisionprofile" ]; then \
echo "No MAS provisioning profile (src/packaging/embedded.provisionprofile) — skipping Mac App Store build."; \
exit 0; \
fi; \
$(MAKE) build-setup build-install && \
echo "Building Mac App Store package (.pkg, universal)..." && \
( cd $(BUILD_DIR)/src && $(MAS_SIGN_ENV) CSC_NAME="$(MAS_CSC_NAME)" npx electron-builder --mac mas --universal --publish never -c.mac.notarize=false $(MAS_BUILD_VERSION_ARG) ) && \
echo " → $(BUILD_DIR)/src/dist/ (upload the .pkg with Transporter)" && \
echo "--------------------------------"
# The local sandbox smoke-test: same entitlements, same sandbox, signed for
# development so it runs on THIS machine without going near the store. Run it
# before `make mas` — it is the only way to find out what the sandbox denies.
#
# It deliberately does NOT pin CSC_NAME the way `mas` does: the development
# profile embeds "Apple Development: Jason Figge (F457H24AUH)", and that
# parenthetical is NOT A TEAM ID and NOT A MISMATCH — Apple names development
# certificates after a per-developer identifier, where the distribution ones
# carry the team. Both certs are under team 2C564TQ2FY (it is the OU field:
# `security find-certificate -c "<CN>" -p | openssl x509 -noout -subject`).
# What matters here is only that the STRING differs, so pinning the
# distribution name would filter out the one certificate this profile
# authorizes.
mas-dev:
@if [ ! -f "$(SRC_DIR)/packaging/development.provisionprofile" ]; then \
echo "No MAS development profile (src/packaging/development.provisionprofile) — skipping MAS dev build."; \
exit 0; \
fi; \
$(MAKE) build-setup build-install && \
echo "Building Mac App Store DEV package (local sandbox smoke-test)..." && \
( cd $(BUILD_DIR)/src && $(MAS_SIGN_ENV) npx electron-builder --mac mas-dev --publish never -c.mac.notarize=false ) && \
echo " → $(BUILD_DIR)/src/dist/" && \
echo "--------------------------------"
# ─── Release ──────────────────────────────────────────────────────────────────
# Cut a release (Model A — "shipped pointer"):
# validate -> preflight (on main, clean, in sync with origin) -> gate on tests
# -> bump src/package.json on main -> fast-forward `release` to main -> tag
# -> atomic push of main + release + tag (the tag push triggers the build).
# `release` stays a strict fast-forward of `main`, so history is linear and the
# branch always points at exactly what was last shipped. The tag push is what
# fires .github/workflows/release.yml (which builds + publishes the installers).
# Usage: make release VERSION=1.2.3
MAIN_BRANCH ?= main
RELEASE_BRANCH ?= release
release:
@set -e; \
NEW="$(VERSION)"; \
if ! [[ "$$NEW" =~ ^[0-9]+\.[0-9]+\.[0-9]+$$ ]]; then \
echo "Error: version must be in x.y.z format (got '$$NEW')."; \
echo "Usage: make release VERSION=1.2.3"; exit 1; \
fi; \
ORIG=$$(git rev-parse --abbrev-ref HEAD); \
trap 'git checkout "$$ORIG" --quiet 2>/dev/null || true' EXIT; \
if [ "$$ORIG" != "$(MAIN_BRANCH)" ]; then \
echo "Error: release must be run from '$(MAIN_BRANCH)' (currently on '$$ORIG')."; exit 1; \
fi; \
if ! git diff-index --quiet HEAD --; then \
echo "Error: working tree has uncommitted changes; commit or stash first."; exit 1; \
fi; \
CURRENT=$$(cd $(SRC_DIR) && node -p "require('./package.json').version"); \
if [ "$$NEW" = "$$CURRENT" ]; then \
echo "Error: new version equals the current version ($$CURRENT)."; exit 1; \
fi; \
echo "Fetching origin..."; \
git fetch --quiet --tags origin; \
if git rev-parse -q --verify "refs/tags/v$$NEW" >/dev/null; then \
echo "Error: tag v$$NEW already exists."; exit 1; \
fi; \
if ! git merge-base --is-ancestor origin/$(MAIN_BRANCH) $(MAIN_BRANCH); then \
echo "Error: local '$(MAIN_BRANCH)' is behind/diverged from origin; pull or rebase first."; exit 1; \
fi; \
echo ""; \
echo " Current version: $$CURRENT"; \
echo " New version: $$NEW"; \
echo " Flow: bump on $(MAIN_BRANCH) -> ff '$(RELEASE_BRANCH)' -> tag v$$NEW -> push (triggers build)"; \
echo ""; \
read -p "Run tests and cut release v$$NEW? [y/N] " ans; \
if [[ "$$ans" != "y" && "$$ans" != "Y" ]]; then echo "Aborted."; exit 1; fi; \
echo "Running test suite..."; \
if ! $(MAKE) test; then echo "Tests failed; aborting release (no changes made)."; exit 1; fi; \
echo "Bumping version on $(MAIN_BRANCH)..."; \
(cd $(SRC_DIR) && npm version "$$NEW" --no-git-tag-version >/dev/null); \
sed -i.bak -E \
-e "s|(id=\"hero-version\">)v[0-9]+\.[0-9]+\.[0-9]+|\1v$$NEW|" \
-e "s|(id=\"dl-version\">)[0-9]+\.[0-9]+\.[0-9]+|\1$$NEW|" \
-e "s|(id=\"footer-version\">)v[0-9]+\.[0-9]+\.[0-9]+|\1v$$NEW|" \
website/index.html && rm -f website/index.html.bak; \
git add src/package.json src/package-lock.json website/index.html; \
git commit -m "Release v$$NEW" >/dev/null; \
echo "Fast-forwarding $(RELEASE_BRANCH) to $(MAIN_BRANCH)..."; \
if git show-ref --verify --quiet refs/remotes/origin/$(RELEASE_BRANCH); then \
git checkout -B $(RELEASE_BRANCH) origin/$(RELEASE_BRANCH) --quiet; \
elif git show-ref --verify --quiet refs/heads/$(RELEASE_BRANCH); then \
git checkout $(RELEASE_BRANCH) --quiet; \
else \
git checkout -b $(RELEASE_BRANCH) --quiet; \
fi; \
git merge --ff-only $(MAIN_BRANCH) --quiet; \
git tag -a "v$$NEW" -m "Release v$$NEW"; \
echo "Pushing $(MAIN_BRANCH) + $(RELEASE_BRANCH) + tag v$$NEW (atomic)..."; \
if ! git push --atomic origin $(MAIN_BRANCH) $(RELEASE_BRANCH) "v$$NEW"; then \
echo "Push failed. Local commit/tag were created but nothing was pushed."; \
echo "Retry with: git push --atomic origin $(MAIN_BRANCH) $(RELEASE_BRANCH) v$$NEW"; \
exit 1; \
fi; \
echo "Released v$$NEW — the Release workflow will build and publish the installers."; \
SLUG=$$(git remote get-url origin 2>/dev/null | sed -E 's#^.*github\.com[:/]##; s#\.git$$##'); \
if [ -n "$$SLUG" ]; then \
echo " Release: https://github.com/$$SLUG/releases/tag/v$$NEW"; \
fi
# ─── Website ──────────────────────────────────────────────────────────────────
# Regenerate website/versions.json from the GitHub Releases API so the download
# buttons + version history track real release assets. Needs a token to avoid the
# unauthenticated rate limit: GITHUB_TOKEN=$(gh auth token) make site
# CI runs this in .github/workflows/deploy-site.yml, then publishes website/ to
# GitHub Pages (chiphippo.com). The custom domain comes from website/CNAME.
site:
@echo "Regenerating website/versions.json from GitHub Releases..."
@node $(WORKSPACE)/scripts/build-versions.mjs --repo jfigge/chiphippo --out $(WORKSPACE)/website/versions.json
@echo "--------------------------------"
# ─── Clean ────────────────────────────────────────────────────────────────────
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@echo "--------------------------------"
# ─── Mac App Store upload ─────────────────────────────────────────────────────
# Hand the built .pkg to App Store Connect. The CI job (release.yml store-mas)
# runs the same altool call; this is the manual route for a build made here.
#
# The path is DERIVED from what is on disk, never typed: electron-builder names
# the package after CFBundleShortVersionString, so a hardcoded name silently
# uploads a stale package the moment the version moves — and once it no longer
# exists at all, altool fails naming a file rather than the reason.
#
# Auth is an App Store Connect API key (an app-specific password cannot do this
# headless under 2FA). The .p8 is found under ~/.appstoreconnect/private_keys.
ASC_KEY_ID ?= X3M2YK7357
ASC_ISSUER_ID ?= 245bb0e6-5b7e-47e4-946b-60e8ee1bc19c
upload:
@PKG=$$(ls -t "$(BUILD_DIR)/src/dist/mas-universal"/*.pkg 2>/dev/null | head -1); \
if [ -z "$$PKG" ]; then \
echo "No .pkg under $(BUILD_DIR)/src/dist/mas-universal — run 'make mas' first."; \
exit 1; \
fi; \
echo "Uploading $$(basename "$$PKG") to App Store Connect..."; \
xcrun altool --upload-app -t macos -f "$$PKG" \
--apiKey $(ASC_KEY_ID) --apiIssuer $(ASC_ISSUER_ID) && \
echo " → uploaded; it must finish PROCESSING before it can be attached" && \
echo " → node scripts/asc-release.mjs status" && \
echo "--------------------------------"
# ─── Help ─────────────────────────────────────────────────────────────────────
help:
@echo ""
@echo " Chip Hippo — TTL breadboard designer & simulator"
@echo ""
@echo " Targets:"
@echo " install Install Node.js dependencies (npm ci)"
@echo " debug Run Electron with hot-reload (primary dev workflow)"
@echo " fmt Format JS/CSS/HTML (prettier)"
@echo " fmt-check Check formatting without writing (prettier --check)"
@echo " lint Lint JS (eslint)"
@echo " test Run license-header guard + JS unit tests"
@echo " test-fast Quick confirmation run: every test file, the slow corpus sampled"
@echo " bench Time the simulation engine headless on a busy circuit"
@echo " bench-compare Compare two bench JSONs (BASE=… HEAD=…)"
@echo " profile Record a DevTools profile of the app running a busy circuit"
@echo " perf-desk Write the two-board perf circuit to data/ (validated first)"
@echo " license-headers Stamp the GPL-3.0 header on any file missing it"
@echo " icons Regenerate app-icon rasters from the SVG sources"
@echo " datasheets Report datasheet crops missing from the pinout window"
@echo " datasheet-urls Check every datasheet download URL still serves a PDF"
@echo " spice-golden Regenerate Spice Lite's ngspice references (needs ngspice)"
@echo " demos Regenerate + validate demos/ and the bundled examples"
@echo " vendor-markdown Rebuild the bundled marked+DOMPurify renderer"
@echo " docs Build the hosted user guide (website/docs/) + website/chips.html"
@echo " pdf Build the user-guide PDF (PDF_OUT=path to override)"
@echo " build Build Electron app for macOS (dir only, unsigned)"
@echo " build-linux Package smoke-test for Linux (dir only, unsigned)"
@echo " build-win Package smoke-test for Windows (dir only, unsigned)"
@echo " dmg Build unsigned macOS .dmg (default 'make')"
@echo " dist Build installers for all platforms (host builds its own)"
@echo " release Bump version, tag, and push to trigger a release (VERSION=x.y.z)"
@echo " dist-mac Build macOS installer (dmg + zip; signed if a cert is present)"
@echo " dist-linux Build Linux installer (AppImage + deb)"
@echo " dist-win Build Windows installer (nsis + portable)"
@echo " mas Build the Mac App Store package (.pkg; skips without a profile)"
@echo " mas-dev Build a local MAS sandbox smoke-test (skips without a profile)"
@echo " upload Upload the built store .pkg to App Store Connect"
@echo " site Regenerate website/versions.json from GitHub Releases"
@echo " clean Remove build and dist directories"
@echo " version Print version string"
@echo " info Print full build information"
.PHONY: version info install debug fmt fmt-check lint license-headers icons \
datasheets datasheet-urls spice-golden demos vendor-markdown docs pdf test test-fast test-license-headers \
bench bench-compare profile perf-desk \
build build-mac build-linux build-win dmg release dist dist-mac \
dist-linux dist-win mas mas-dev upload site build-setup build-install \
clean help