build: build jsed with installed jerbuild (no jerboa checkout)
ober
2e2651cfd1f9baf753a82c4b3aaedc816bbfda47
--- a/.jerbuild +++ b/.jerbuild @@ -1,7 +1,10 @@ -;; Build jsed with a standalone jerbuild binary. +;; Build jsed with a standalone jerbuild binary: `jerbuild build`. +;; +;; jerbuild bundles Chez Scheme + the jerboa stdlib, so NO jerboa source +;; checkout and NO separately-built Chez is required. The only external tool +;; is a C compiler (cc) for the final link. Pure Jerboa — no jerboa-native-rs +;; and no DuckDB. (entry "main.ss") (output "jsed") -(requires "cc") -(notes "Pure Jerboa build. jerboa-native-rs and DuckDB are not required.") (libdirs "lib") --- a/Makefile +++ b/Makefile @@ -1,36 +1,41 @@ -JERBOA_HOME ?= $(HOME)/mine/jerboa -SCHEME ?= $(JERBOA_HOME)/.chez/bin/scheme +# jerbuild bundles Chez Scheme + the jerboa stdlib under ~/.cache/jerbuild/, +# so building jsed needs only `jerbuild` + a C compiler — no jerboa source +# checkout and no separately-built Chez. +JERBUILD ?= jerbuild +JH := $(shell $(JERBUILD) --jerboa-home 2>/dev/null) +ifeq ($(JH),) +$(error jerbuild not found on PATH (or '$(JERBUILD) --jerboa-home' failed). Install jerbuild, or set JERBUILD=/path/to/jerbuild) +endif + +LIBDIRS := --libdirs lib:$(JH)/lib JSED_BIN := jsed -LIBDIRS := lib -.PHONY: all build clean test install +.PHONY: all build binary run test clean install + +all: binary + +# Standalone native binary via .jerbuild (entry main.ss -> jsed). +binary: + $(JERBUILD) build -all: build +build: binary -build: - @echo "Building jsed..." - $(SCHEME) --libdirs $(LIBDIRS) --compile-imported-libraries --script main.ss --version 2>/dev/null || true - @echo "Build complete. Run with: $(SCHEME) --libdirs $(LIBDIRS) --script main.ss" +# Run from source without building the binary. +run: + $(JERBUILD) exec $(LIBDIRS) main.ss clean: - find lib -name '*.so' -delete 2>/dev/null || true + find lib \( -name '*.so' -o -name '*.wpo' \) -delete 2>/dev/null || true rm -f $(JSED_BIN) -test: - @echo "Running basic tests..." - @echo "hello world" | $(SCHEME) --libdirs $(LIBDIRS) --script main.ss 's/hello/goodbye/' - @echo "Test: line numbers" - @printf "a\nb\nc\n" | $(SCHEME) --libdirs $(LIBDIRS) --script main.ss '=' - @echo "Test: delete" - @printf "a\nb\nc\n" | $(SCHEME) --libdirs $(LIBDIRS) --script main.ss '2d' - @echo "Test: substitute global" - @echo "aaa" | $(SCHEME) --libdirs $(LIBDIRS) --script main.ss 's/a/b/g' - @echo "Test: hold space" - @printf "1\n2\n3\n" | $(SCHEME) --libdirs $(LIBDIRS) --script main.ss -n '1h;2{x;p};3{x;p}' - @echo "All tests passed." +install: binary + install -d $(HOME)/.local/bin + install -m 0755 $(JSED_BIN) $(HOME)/.local/bin/$(JSED_BIN) -install: build - @echo '#!/bin/sh' > $(JSED_BIN) - @echo 'exec $(SCHEME) --libdirs $(LIBDIRS) --script main.ss "$$@"' >> $(JSED_BIN) - @chmod +x $(JSED_BIN) - @echo "Created ./$(JSED_BIN) wrapper script" +test: binary + @echo "--- s/// ---"; echo "hello world" | ./$(JSED_BIN) 's/hello/goodbye/' + @echo "--- = (line #) ---"; printf "a\nb\nc\n" | ./$(JSED_BIN) '=' + @echo "--- 2d ---"; printf "a\nb\nc\n" | ./$(JSED_BIN) '2d' + @echo "--- s///g ---"; echo "aaa" | ./$(JSED_BIN) 's/a/b/g' + @echo "--- hold space ---"; printf "1\n2\n3\n" | ./$(JSED_BIN) -n '1h;2{x;p};3{x;p}' + @echo "All tests passed." --- a/lib/sed/pcre2.sls +++ b/lib/sed/pcre2.sls @@ -16,8 +16,14 @@ ;; Load shared library — guarded so static binaries (JERBOA_STATIC) don't ;; abort at library init; pcre2 calls will fail at use time instead. + ;; Try the platform-appropriate names so the same binary works on + ;; Linux (.so), macOS (.dylib, incl. Homebrew), and FreeBSD. (define init (or (guard (e [#t #f]) (load-shared-object "libpcre2-8.so") #t) + (guard (e [#t #f]) (load-shared-object "libpcre2-8.dylib") #t) + (guard (e [#t #f]) (load-shared-object "libpcre2-8.so.0") #t) + (guard (e [#t #f]) (load-shared-object "/opt/homebrew/lib/libpcre2-8.dylib") #t) + (guard (e [#t #f]) (load-shared-object "/usr/local/lib/libpcre2-8.dylib") #t) #f)) ;;; FFI declarations — use string for PCRE2_SPTR (auto null-terminated), --- a/main.ss +++ b/main.ss @@ -1,4 +1,4 @@ -#!/usr/bin/env scheme-script +#!chezscheme ;;; Sed main entry point and file processing (import (except (chezscheme) compile-program) (sed ast) (sed parser) (sed engine))