-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
172 lines (143 loc) · 6.3 KB
/
Copy pathMakefile
File metadata and controls
172 lines (143 loc) · 6.3 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
# codex — OpenAI Codex CLI packaged for jailbroken iOS.
#
# Every step is a script under Scripts/ so the GitHub Actions workflow and a
# local checkout run the same code. This Makefile only wires them together and
# owns the one thing that differs between the two packages: the layout.
SHELL := /bin/bash
ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
CONFIG_DIR := $(ROOT_DIR)/Configuration
include $(CONFIG_DIR)/upstream.env
VERSION_FILE := $(CONFIG_DIR)/version.txt
PACKAGE_VERSION := $(strip $(shell cat "$(VERSION_FILE)" 2>/dev/null))
PACKAGE_ID ?= wiki.qaq.codex
BUILD_DIR := $(ROOT_DIR)/build
SRC_DIR := $(BUILD_DIR)/src
SCRATCH_DIR := $(BUILD_DIR)/ios-$(ARCH)
BIN_PATH_FILE := $(BUILD_DIR)/bin-path.txt
PKG_DIR := $(BUILD_DIR)/Packages
SOURCE_PREPARER := $(ROOT_DIR)/Scripts/prepare-source.sh
IOS_BUILDER := $(ROOT_DIR)/Scripts/build-ios.sh
DEB_PACKAGER := $(ROOT_DIR)/Scripts/package-deb.sh
VERSION_APPLIER := $(ROOT_DIR)/Scripts/apply-version.sh
DEVICE_INSTALLER := $(ROOT_DIR)/Scripts/install-device.sh
# Which bootstrap layout the .deb is for. roothide is relocated into the jbroot
# it picked this boot and its *C* bootstrap programs resolve unprefixed paths
# inside it via libvroot; a rootless bootstrap lives at a fixed /var/jb that
# every path in the package has to name. One arm64 binary backs both — only
# the layout and the architecture label differ. The Rust binary itself is not
# vroot-linked; runtime shell lookup is a probe, in patches/.
PACKAGE_FLAVOR ?= roothide
ifeq ($(PACKAGE_FLAVOR),roothide)
PACKAGE_PREFIX :=
PACKAGE_ARCHITECTURE := iphoneos-arm64e
else ifeq ($(PACKAGE_FLAVOR),rootless)
PACKAGE_PREFIX := /var/jb
PACKAGE_ARCHITECTURE := iphoneos-arm64
else
$(error PACKAGE_FLAVOR must be roothide or rootless, got '$(PACKAGE_FLAVOR)')
endif
DEB_OUTPUT ?= $(PKG_DIR)/$(PACKAGE_ID)_$(PACKAGE_VERSION)_$(PACKAGE_ARCHITECTURE).deb
ifeq ($(PACKAGE_VERSION),)
$(error $(VERSION_FILE) is missing or empty; run make set-version VERSION=x.y.z)
endif
.PHONY: all help print-version print-upstream print-deb-path set-version \
bump-upstream follow-upstream check source build package deb deb-roothide \
deb-rootless debs checksums install clean
.NOTPARALLEL:
all: debs
help:
@echo "codex $(PACKAGE_VERSION) — OpenAI Codex CLI for jailbroken iOS"
@echo "upstream: $(UPSTREAM_REPO) @ $(UPSTREAM_REF)"
@echo "target: $(ARCH)-apple-ios$(MIN_IOS) rustc $(RUST_TOOLCHAIN)"
@echo
@echo " check Validate the scripts, the config, and the patch set"
@echo " source Fetch upstream at the pinned ref and apply patches/"
@echo " build Cross-compile the CLI and Code Mode host for iOS"
@echo " deb Package one flavor (PACKAGE_FLAVOR=$(PACKAGE_FLAVOR))"
@echo " deb-roothide Package for roothide (unprefixed, iphoneos-arm64e)"
@echo " deb-rootless Package for rootless (/var/jb, iphoneos-arm64)"
@echo " debs Both packages plus SHA256SUMS — what CI releases"
@echo " install Install onto a device over SSH and smoke-test it"
@echo " clean Remove build/"
@echo
@echo " make set-version VERSION=1.2.3 Set the package version"
@echo " make bump-upstream REF=<sha> Repin upstream and rebuild"
@echo " make follow-upstream Pin to newest stable rust-vX.Y.Z"
print-version:
@echo "$(PACKAGE_VERSION)"
print-upstream:
@echo "$(UPSTREAM_REF)"
print-deb-path:
@echo "$(DEB_OUTPUT)"
set-version:
@test -n "$(VERSION)" || { echo "usage: make set-version VERSION=1.2.3" >&2; exit 64; }
@"$(VERSION_APPLIER)" "$(VERSION)"
check:
@echo "==> shell syntax"
@for script in "$(ROOT_DIR)"/Scripts/*.sh; do bash -n "$$script" || exit 1; done
@if command -v shellcheck >/dev/null; then \
shellcheck --severity=warning "$(ROOT_DIR)"/Scripts/*.sh; \
else \
echo " (shellcheck not installed; syntax check only)"; \
fi
@echo "==> config"
@[[ "$(PACKAGE_VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$$ ]] || \
{ echo "error: version '$(PACKAGE_VERSION)' must look like 1.2.3 or 1.2.3-2" >&2; exit 65; }
@[[ "$(MIN_IOS)" =~ ^[0-9]+\.[0-9]+$$ ]] || \
{ echo "error: MIN_IOS '$(MIN_IOS)' must look like 15.0" >&2; exit 65; }
@[[ "$(UPSTREAM_REF)" =~ ^[0-9a-f]{40}$$ ]] || \
echo " warning: UPSTREAM_REF is not a full commit sha; builds are not reproducible"
@[[ "$(RUSTY_V8_REF)" =~ ^[0-9a-f]{40}$$ ]] || \
{ echo "error: RUSTY_V8_REF is not a full commit sha" >&2; exit 65; }
@echo "==> patch set"
@ls "$(ROOT_DIR)"/patches/*.patch >/dev/null
@for patch in "$(ROOT_DIR)"/patches/*.patch; do \
test -s "$$patch" || { echo "error: $$patch is empty" >&2; exit 65; }; \
done
@echo "==> packaging inputs"
@for input in Packaging/DEBIAN/control Packaging/codex.entitlements \
Packaging/codex.launcher.sh Packaging/release-notes.md \
Packaging/etc/codex/config.toml; do \
test -f "$(ROOT_DIR)/$$input" || { echo "error: missing $$input" >&2; exit 66; }; \
done
@plutil -lint "$(ROOT_DIR)/Packaging/codex.entitlements"
@"$(ROOT_DIR)/Scripts/release-notes.sh" "v$(PACKAGE_VERSION)" >/dev/null
@echo "ok"
source:
@"$(SOURCE_PREPARER)" "$(SRC_DIR)"
build: source
@mkdir -p "$(BUILD_DIR)"
@"$(IOS_BUILDER)" "$(SRC_DIR)" "$(SCRATCH_DIR)" >"$(BIN_PATH_FILE)"
package:
@mkdir -p "$(PKG_DIR)"
@PACKAGE_ID="$(PACKAGE_ID)" "$(DEB_PACKAGER)" \
"$$(cat "$(BIN_PATH_FILE)")" \
"$(DEB_OUTPUT)" \
"$(PACKAGE_VERSION)" \
"$(PACKAGE_ARCHITECTURE)" \
"$(PACKAGE_PREFIX)"
deb: build package
deb-roothide:
@$(MAKE) --no-print-directory PACKAGE_FLAVOR=roothide deb
deb-rootless:
@$(MAKE) --no-print-directory PACKAGE_FLAVOR=rootless deb
debs: build
@$(MAKE) --no-print-directory PACKAGE_FLAVOR=roothide package
@$(MAKE) --no-print-directory PACKAGE_FLAVOR=rootless package
@$(MAKE) --no-print-directory checksums
checksums:
@cd "$(PKG_DIR)" && shasum -a 256 \
"$(PACKAGE_ID)_$(PACKAGE_VERSION)_iphoneos-arm64.deb" \
"$(PACKAGE_ID)_$(PACKAGE_VERSION)_iphoneos-arm64e.deb" \
| tee SHA256SUMS
install: debs
@"$(DEVICE_INSTALLER)" "$(PKG_DIR)"
bump-upstream:
@test -n "$(REF)" || { echo "usage: make bump-upstream REF=<sha>" >&2; exit 64; }
@sed -i '' -e "s|^UPSTREAM_REF=.*|UPSTREAM_REF=$(REF)|" "$(CONFIG_DIR)/upstream.env"
@echo "repinned upstream to $(REF)"
@$(MAKE) --no-print-directory build
follow-upstream:
@"$(ROOT_DIR)/Scripts/follow-upstream.sh"
clean:
rm -rf "$(BUILD_DIR)"