Add jpkg package CI

ober

4fe43fb719856087e4e62c64800f21ee7aa571f5

diff --git a/.build.yml b/.build.yml
new file mode 100644
index 0000000..dac4a52
--- /dev/null
+++ b/.build.yml
@@ -0,0 +1,40 @@
+image: debian/stable
+packages:
+  - build-essential
+  - g++
+  - pkg-config
+  - libncurses-dev
+  - uuid-dev
+  - zlib1g-dev
+  - liblz4-dev
+  - libpcre2-dev
+  - libvterm-dev
+  - libx11-dev
+  - git
+  - curl
+  - unzip
+  - zip
+sources:
+  - https://git.sr.ht/~lisp/jerboa
+  - https://git.sr.ht/~lisp/jerboa-emacs
+artifacts:
+  - jerboa-emacs/jerboa-emacs-0.1.0.jpkg
+tasks:
+  - build-jerboa-tools: |
+      cd jerboa
+      make jerboa
+      echo 'export PATH="$HOME/jerboa/dist:$PATH"' >> ~/.buildenv
+  - package-emacs: |
+      cd jerboa-emacs
+      J="$HOME/jerboa/dist/jerboa"
+      "$J" pkg verify
+      "$J" pkg policy
+      "$J" pkg build
+      "$J" pkg pack --output "$PWD/jerboa-emacs-0.1.0.jpkg"
+      "$J" pkg verify "$PWD/jerboa-emacs-0.1.0.jpkg"
+      "$J" pkg verify --reproduce
+  - build-emacs: |
+      cd jerboa-emacs
+      JERBUILD_TOOL="$HOME/jerboa/dist/jerbuild" \
+      JERBUILD="$HOME/jerboa/dist/jerbuild" \
+      make jemacs-jerbuild
diff --git a/Makefile b/Makefile
index 8678ba0..6d50cbe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,16 @@
 VENDOR    ?= $(CURDIR)/vendor
+BIN_DIR   ?= $(HOME)/.local/bin
 
 # Standalone jerbuild toolchain. This mirrors the bootstrap path used by
 # jerboa-code/jerboa-shell: prefer project-local tools, then sibling Jerboa,
 # then PATH, and otherwise fetch a release into .jerboa/bin.
 JERBOA_VERSION ?= v0.2.0
 JERBOA_TOOL_DIR ?= $(CURDIR)/.jerboa/bin
-JERBUILD_TOOL ?= $(shell if [ -x ./jerbuild ] && [ -x ./jerboa ]; then echo ./jerbuild; \
-	elif [ -x "$(JERBOA_TOOL_DIR)/jerbuild" ] && [ -x "$(JERBOA_TOOL_DIR)/jerboa" ]; then echo "$(JERBOA_TOOL_DIR)/jerbuild"; \
-	elif [ -x ../jerboa/dist/jerbuild ] && [ -x ../jerboa/dist/jerboa ]; then echo ../jerboa/dist/jerbuild; \
+JERBUILD_TOOL ?= $(shell if [ -x ./jerbuild ]; then echo ./jerbuild; \
+	elif [ -x "$(JERBOA_TOOL_DIR)/jerbuild" ]; then echo "$(JERBOA_TOOL_DIR)/jerbuild"; \
+	elif [ -x ../jerboa/dist/jerbuild ]; then echo ../jerboa/dist/jerbuild; \
 	elif [ -x ../jerboa/jerbuild ]; then echo ../jerboa/jerbuild; \
-	elif command -v jerbuild >/dev/null 2>&1 && command -v jerboa >/dev/null 2>&1; then command -v jerbuild; \
+	elif command -v jerbuild >/dev/null 2>&1; then command -v jerbuild; \
 	else echo "$(JERBOA_TOOL_DIR)/jerbuild"; fi)
 JH = $(shell "$(JERBUILD_TOOL)" --jerboa-home 2>/dev/null)
 SSH ?= ssh
@@ -146,7 +147,7 @@ SCHEME_CHEZ_DIR = $(shell if [ -n "$(SCHEME_MT)" ]; then ls -d "$(SCHEME_PREFIX)
 CHEZ_DIR ?= $(SCHEME_CHEZ_DIR)
 export CHEZ_DIR
 
-.PHONY: all vendor-deps vendor-update check-pcre2-system-deps check-vterm-system-deps deps ensure-vendor-jerboa-tools ensure-jerboa-tools build-jerbuild jemacs-jerbuild jerbuild-check scintilla-vendor-deps scintilla-vendor-clean build rebuild run test-tier0 test-tier2 test-tier3 test-tier4 test-tier5 test-org test-extra test clean clean-generated \
+.PHONY: all vendor-deps vendor-update check-pcre2-system-deps check-vterm-system-deps deps ensure-vendor-jerboa-tools ensure-jerboa-tools build-jerbuild jemacs-jerbuild jerbuild-check scintilla-vendor-deps scintilla-vendor-clean build rebuild run test-tier0 test-tier2 test-tier3 test-tier4 test-tier5 test-org test-extra test clean clean-generated install \
         test-org-duration test-org-element test-org-fold test-org-footnote \
         test-org-lint test-org-num test-org-property test-org-src test-org-tempo \
         test-vtscreen test-debug-repl test-qt test-qt-e2e build-qt binary-qt \
@@ -179,6 +180,7 @@ all:
 	@echo "  run            Build and run TUI editor"
 	@echo "  run-qt         Build and run Qt editor"
 	@echo "  binary         Build TUI binary (./jemacs) — embeds Scheme, links system libs"
+	@echo "  install        Build + install TUI binary to $(BIN_DIR)/jemacs"
 	@echo "  jemacs-jerbuild Build host TUI launcher via 'jerbuild build' (.jerbuild)"
 	@echo "  static-tui     Build static TUI binary on this Linux host (./jemacs)"
 	@echo "  static-qt      Build fully static jemacs-qt binary via Docker"
@@ -335,15 +337,15 @@ ensure-jerboa-tools:
 	@set -e; \
 	if [ -x "$(JERBUILD_TOOL)" ] && "$(JERBUILD_TOOL)" --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using Jerboa toolchain: $(JERBUILD_TOOL) ==="; \
-	elif [ -x ./jerbuild ] && [ -x ./jerboa ] && ./jerbuild --jerboa-home >/dev/null 2>&1; then \
+	elif [ -x ./jerbuild ] && ./jerbuild --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using project-local ./jerbuild ==="; \
-	elif [ -x "$(JERBOA_TOOL_DIR)/jerbuild" ] && [ -x "$(JERBOA_TOOL_DIR)/jerboa" ] && "$(JERBOA_TOOL_DIR)/jerbuild" --jerboa-home >/dev/null 2>&1; then \
+	elif [ -x "$(JERBOA_TOOL_DIR)/jerbuild" ] && "$(JERBOA_TOOL_DIR)/jerbuild" --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using downloaded Jerboa toolchain: $(JERBOA_TOOL_DIR) ==="; \
-	elif [ -x ../jerboa/dist/jerbuild ] && [ -x ../jerboa/dist/jerboa ] && ../jerboa/dist/jerbuild --jerboa-home >/dev/null 2>&1; then \
+	elif [ -x ../jerboa/dist/jerbuild ] && ../jerboa/dist/jerbuild --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using sibling Jerboa build: ../jerboa/dist/jerbuild ==="; \
 	elif [ -x ../jerboa/jerbuild ] && ../jerboa/jerbuild --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using sibling Jerboa build: ../jerboa/jerbuild ==="; \
-	elif command -v jerbuild >/dev/null 2>&1 && command -v jerboa >/dev/null 2>&1 && jerbuild --jerboa-home >/dev/null 2>&1; then \
+	elif command -v jerbuild >/dev/null 2>&1 && jerbuild --jerboa-home >/dev/null 2>&1; then \
 	  echo "=== Using Jerboa toolchain from PATH: $$(command -v jerbuild) ==="; \
 	else \
 	  echo "=== Fetching Jerboa $(JERBOA_VERSION) release tools into $(JERBOA_TOOL_DIR) ==="; \
@@ -790,6 +792,15 @@ binary: check-vterm-system-deps build pty_shim.$(SHLIB_EXT) vterm_shim.$(SHLIB_E
 	  JERBOA_SCINTILLA_DIR=$(JERBOA_SCINTILLA_LIBDIR) SCI_VENDOR_DIR=$(SCINTILLA_VENDOR) \
 	  $(SCHEME) $(LIBDIRS) --script build-binary.ss
 
+install: binary
+	mkdir -p $(BIN_DIR)
+	install -m 0755 jemacs $(BIN_DIR)/jemacs
+	install -m 0755 pty_shim.$(SHLIB_EXT) $(BIN_DIR)/pty_shim.$(SHLIB_EXT)
+	install -m 0755 vterm_shim.$(SHLIB_EXT) $(BIN_DIR)/vterm_shim.$(SHLIB_EXT)
+	install -m 0755 jerboa_scintilla_shim.$(SHLIB_EXT) $(BIN_DIR)/jerboa_scintilla_shim.$(SHLIB_EXT)
+	install -m 0755 jerboa_pcre2_shim.$(SHLIB_EXT) $(BIN_DIR)/jerboa_pcre2_shim.$(SHLIB_EXT)
+	@echo "Installed jemacs to $(BIN_DIR)/jemacs"
+
 # =============================================================================
 # Static binary build support (native Linux musl)
 # =============================================================================
diff --git a/jpkg.policy.sexp b/jpkg.policy.sexp
new file mode 100644
index 0000000..3f5702c
--- /dev/null
+++ b/jpkg.policy.sexp
@@ -0,0 +1,3 @@
+(policy
+  (mode dev)
+  (allow (native-build) (build-network) (ffi)))
diff --git a/jpkg.sexp b/jpkg.sexp
new file mode 100644
index 0000000..0ea1088
--- /dev/null
+++ b/jpkg.sexp
@@ -0,0 +1,14 @@
+(package
+  (name "@lisp/jerboa-emacs")
+  (version "0.1.0")
+  (description "Emacs-like editor for Jerboa with terminal and Qt frontends")
+  (license "UNLICENSED")
+  (source "https://git.sr.ht/~lisp/jerboa-emacs")
+  (jerboa ">=0.2.0")
+  (modules ((root "src")))
+  (dependencies ())
+  (dev-dependencies ())
+  (capabilities ((native-code reason: "terminal, Scintilla, PCRE2, Qt, and shell FFI shims")
+                 (network build: #t test: #f)
+                 (ffi libraries: ("pcre2-8" "vterm" "scintilla" "Qt6Widgets"))
+                 (executables ("jemacs")))))