-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (137 loc) · 5.32 KB
/
Copy pathMakefile
File metadata and controls
166 lines (137 loc) · 5.32 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
# hake (hako-edit) — minimal cross-platform build with icon
#
# Windows: icon embedded into .exe via windres (real OS icon).
# macOS: icon attached via Rez/SetFile if Xcode CLT installed (best-effort);
# otherwise icon/hake.icns is shipped alongside.
# Linux: ELF can't embed icons; icon/hake.png is shipped alongside for use
# with a .desktop entry.
#
# BUNDLE_HAKO=1 (default): also build the `hako` agent binary from ../hako-code/hako.c.
# hake will find and spawn it at runtime for the Rei panel.
# BUNDLE_HAKO=0: build hake only. Rei pane shows install guidance (:install-agent)
# until a hako binary is on the system; the editor can install it in place.
# NO_AGENT=1: build an editor with NO agent path at all. The Rei pane stays inert and
# says "this build ships without an agent" — it never errors. Implies BUNDLE_HAKO=0.
CC ?= gcc
CFLAGS ?= -O2 -Wall
LDLIBS ?= -lpthread
BUNDLE_HAKO ?= 1
NO_AGENT ?= 0
HAKO_SRC ?= ../hako-code/hako.c
ifeq ($(NO_AGENT),1)
CFLAGS += -DHAKE_NO_AGENT
BUNDLE_HAKO := 0
endif
ICON_DIR = icon
BIN = hake
ifeq ($(OS),Windows_NT)
PLATFORM = windows
BIN := hake.exe
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PLATFORM = macos
else ifeq ($(UNAME_S),FreeBSD)
PLATFORM = freebsd
else
PLATFORM = linux
endif
endif
# macOS universal2 toggle: make UNIVERSAL=1 → fat binary (arm64 + x86_64).
ifeq ($(PLATFORM),macos)
ifeq ($(UNIVERSAL),1)
CFLAGS += -arch arm64 -arch x86_64
endif
endif
ifeq ($(BUNDLE_HAKO),1)
TARGETS = $(BIN) hako
else
TARGETS = $(BIN)
endif
.PHONY: all clean icons install uninstall
all: $(TARGETS)
# Build the `hako` agent alongside hake when BUNDLE_HAKO=1.
hako: $(HAKO_SRC)
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
# ---------- icons ----------
# Regenerate icon/hake.{icns,ico,png} from icon/hake.svg.
# Requires rsvg-convert or ImageMagick. iconutil (macOS) → .icns, magick → .ico.
icons:
@cd $(ICON_DIR) && bash build-icons.sh
# ---------- Windows: embed icon via resource (optional — skip if .ico missing) ----------
ifeq ($(PLATFORM),windows)
HAS_ICO := $(wildcard $(ICON_DIR)/hake.ico)
ifeq ($(HAS_ICO),)
$(BIN): hake.c
$(CC) $(CFLAGS) hake.c -o $@ $(LDLIBS)
else
hake.rc:
@printf 'IDI_ICON1 ICON "$(ICON_DIR)/hake.ico"\n' > $@
hake.res: hake.rc $(ICON_DIR)/hake.ico
windres $< -O coff -o $@
$(BIN): hake.c hake.res
$(CC) $(CFLAGS) hake.c hake.res -o $@ $(LDLIBS)
endif
endif
# ---------- macOS: build, then attach icon if tools exist ----------
ifeq ($(PLATFORM),macos)
$(BIN): hake.c
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
@if command -v Rez >/dev/null 2>&1 && command -v SetFile >/dev/null 2>&1; then \
printf 'read %c%s%c (-16455) "%s/hake.icns";\n' "'" "icns" "'" "$(ICON_DIR)" > .hake.r; \
Rez -append .hake.r -o $(BIN) && SetFile -a C $(BIN) && \
echo "icon attached to $(BIN)" || echo "icon attach failed (non-fatal)"; \
rm -f .hake.r; \
else \
echo "Rez/SetFile not found — install Xcode CLT to attach icon (xcode-select --install)"; \
fi
endif
# ---------- Linux: plain build, icon shipped alongside ----------
ifeq ($(PLATFORM),linux)
$(BIN): hake.c
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
@echo "built $(BIN). For a desktop icon: copy $(ICON_DIR)/hake.png to ~/.local/share/icons/ and create a .desktop entry."
endif
# ---------- FreeBSD: plain build ----------
ifeq ($(PLATFORM),freebsd)
$(BIN): hake.c
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
endif
clean:
rm -f hake hake.exe hako hake.rc hake.res .hake.r
# ---------- install / uninstall ----------
PREFIX ?=
ICONS ?= 1
_uname_s := $(shell uname -s 2>/dev/null)
_resolve_prefix = $(if $(PREFIX),$(PREFIX),$(if $(shell test -w /usr/local/bin && echo y),/usr/local,$(HOME)/.local))
install: $(BIN)
@dest="$(_resolve_prefix)"; \
mkdir -p "$$dest/bin"; \
install -m 0755 $(BIN) "$$dest/bin/$(BIN)"; \
echo "installed: $$dest/bin/$(BIN)"; \
if [ -f hako ]; then \
install -m 0755 hako "$$dest/bin/hako-bundled"; \
echo "installed: $$dest/bin/hako-bundled (BUNDLE_HAKO subprocess wire)"; \
fi; \
if [ "$(_uname_s)" = "Darwin" ] && command -v xattr >/dev/null 2>&1; then \
xattr -d com.apple.quarantine "$$dest/bin/$(BIN)" 2>/dev/null || true; \
fi; \
if [ "$(_uname_s)" = "Linux" ] && [ "$(ICONS)" = "1" ] && [ -f $(ICON_DIR)/hake.png ]; then \
mkdir -p "$$HOME/.local/share/applications" "$$HOME/.local/share/icons/hicolor/256x256/apps"; \
install -m 0644 $(ICON_DIR)/hake.png "$$HOME/.local/share/icons/hicolor/256x256/apps/hake.png"; \
printf "[Desktop Entry]\nType=Application\nName=hake\nComment=Mithraeum modal terminal editor\nExec=$$dest/bin/$(BIN)\nIcon=hake\nTerminal=true\nCategories=Development;TextEditor;\n" > "$$HOME/.local/share/applications/hake.desktop"; \
echo "installed: icon + .desktop entry"; \
fi; \
case ":$$PATH:" in *":$$dest/bin:"*) ;; *) echo "note: $$dest/bin not in PATH";; esac
uninstall:
@for prefix in $(PREFIX) /usr/local $$HOME/.local /opt/local /opt; do \
[ -z "$$prefix" ] && continue; \
for b in $(BIN) hako-bundled; do \
path="$$prefix/bin/$$b"; \
if [ -e "$$path" ] || [ -L "$$path" ]; then rm -f "$$path" && echo "removed: $$path"; fi; \
done; \
done
@rm -f "$$HOME/.local/share/applications/hake.desktop" 2>/dev/null || true
@for d in $$HOME/.local/share/icons/hicolor/*/apps; do \
[ -d "$$d" ] && rm -f "$$d/hake.png" 2>/dev/null; \
done