@@ -9,7 +9,36 @@ LD_LIBRARY_PATH := $(GHOSTTY_ZIG_OUT)/lib
99# Stamp file to track whether the cmake build has run.
1010STAMP := $(BUILD_DIR ) /.ghostty-built
1111
12- .PHONY : build test clean
12+ # Cross-compilation target definitions.
13+ # Each entry maps a make target suffix to GOOS, GOARCH, zig target triple,
14+ # and the CC/CXX target flag for zig cc.
15+ CROSS_TARGETS := linux-amd64 linux-arm64 macos-amd64 macos-arm64 windows-amd64 windows-arm64
16+
17+ linux-amd64_GOOS := linux
18+ linux-amd64_GOARCH := amd64
19+ linux-amd64_ZIG := x86_64-linux-gnu
20+
21+ linux-arm64_GOOS := linux
22+ linux-arm64_GOARCH := arm64
23+ linux-arm64_ZIG := aarch64-linux-gnu
24+
25+ macos-amd64_GOOS := darwin
26+ macos-amd64_GOARCH := amd64
27+ macos-amd64_ZIG := x86_64-macos
28+
29+ macos-arm64_GOOS := darwin
30+ macos-arm64_GOARCH := arm64
31+ macos-arm64_ZIG := aarch64-macos
32+
33+ windows-amd64_GOOS := windows
34+ windows-amd64_GOARCH := amd64
35+ windows-amd64_ZIG := x86_64-windows-gnu
36+
37+ windows-arm64_GOOS := windows
38+ windows-arm64_GOARCH := arm64
39+ windows-arm64_ZIG := aarch64-windows-gnu
40+
41+ .PHONY : build test clean cross $(addprefix cross-,$(CROSS_TARGETS ) )
1342
1443$(STAMP ) :
1544 cmake -B $(BUILD_DIR ) -DCMAKE_BUILD_TYPE=Release
@@ -22,5 +51,24 @@ build: $(STAMP)
2251test : $(STAMP )
2352 PKG_CONFIG_PATH=$(PKG_CONFIG_PATH ) DYLD_LIBRARY_PATH=$(DYLD_LIBRARY_PATH ) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH ) go test ./...
2453
54+ # cross builds all cross-compilation targets.
55+ cross : $(addprefix cross-,$(CROSS_TARGETS ) )
56+
57+ # cross-<target> cross-compiles the Go package for the given target using
58+ # zig cc and the libghostty-vt static library built by CMake.
59+ define CROSS_RULE
60+ cross-$(1 ) : $(STAMP )
61+ CGO_ENABLED=1 \
62+ CC="zig cc -target $$($(1 ) _ZIG) " \
63+ CXX="zig c++ -target $$($(1 ) _ZIG) " \
64+ GOOS=$$($(1 ) _GOOS) \
65+ GOARCH=$$($(1 ) _GOARCH) \
66+ CGO_CFLAGS="-I$(CURDIR ) /$(BUILD_DIR ) /ghostty-$(1 ) /include -DGHOSTTY_STATIC" \
67+ CGO_LDFLAGS="-L$(CURDIR ) /$(BUILD_DIR ) /ghostty-$(1 ) /lib -lghostty-vt" \
68+ go build . ./sys/...
69+ endef
70+
71+ $(foreach t,$(CROSS_TARGETS),$(eval $(call CROSS_RULE,$(t))))
72+
2573clean :
2674 rm -rf $(BUILD_DIR )
0 commit comments