aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: f023892523d2868944db50f0c48f00e901a03857 (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# hoardom makefile
# supports: make, make install, make deb, make pkg, make clean

NAME        := hoardom
VERSION     := $(shell grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
DESCRIPTION := Domain hoarding made less painful
MAINTAINER  := crt

PREFIX      ?= /usr/local
BINDIR      := $(PREFIX)/bin
DATADIR     := $(PREFIX)/share
APPDIR      := $(DATADIR)/applications
ICONDIR     := $(DATADIR)/icons/hicolor/256x256/apps
ICON_FILE   := dist/AppIcon.ico

CARGO       ?= cargo
CARGO_FLAGS ?=

BUILDDIR    := target/release
BINARY      := $(BUILDDIR)/$(NAME)
GUI_BINARY  := $(BUILDDIR)/$(NAME)-app

# packaging scratch dirs
PKG_ROOT    := target/pkg-root
DEB_ROOT    := target/deb-root
MAC_ROOT    := target/mac-root
MAC_APP     := target/mac-root/$(NAME).app

# ---- build ----

.PHONY: all build release debug clean install uninstall deb pkg app

all: release

release:
	$(CARGO) build --release $(CARGO_FLAGS)

debug:
	$(CARGO) build $(CARGO_FLAGS)

# build the gui wrapper (requires gui feature)
app: release
	$(CARGO) build --release --features gui $(CARGO_FLAGS)

# ---- install (linux / mac) ----

install: release
	@echo "installing $(NAME) to $(DESTDIR)$(BINDIR)"
	install -d $(DESTDIR)$(BINDIR)
	install -m 755 $(BINARY) $(DESTDIR)$(BINDIR)/$(NAME)
	@# install gui wrapper too if it was built
	@if [ -f $(GUI_BINARY) ]; then \
		install -m 755 $(GUI_BINARY) $(DESTDIR)$(BINDIR)/$(NAME)-app; \
	fi
ifeq ($(shell uname), Darwin)
	@echo "installing macOS app bundle"
	install -d $(DESTDIR)/Applications
	$(MAKE) _mac_app APP_DEST=$(DESTDIR)/Applications
else
	@echo "installing desktop file"
	install -d $(DESTDIR)$(APPDIR)
	install -m 644 dist/$(NAME).desktop $(DESTDIR)$(APPDIR)/$(NAME).desktop
	install -d $(DESTDIR)$(ICONDIR)
	install -m 644 $(ICON_FILE) $(DESTDIR)$(ICONDIR)/$(NAME).ico
endif
	@echo "done, $(NAME) is ready to go"

uninstall:
	rm -f $(DESTDIR)$(BINDIR)/$(NAME)
	rm -f $(DESTDIR)$(BINDIR)/$(NAME)-app
	rm -f $(DESTDIR)$(APPDIR)/$(NAME).desktop
	rm -f $(DESTDIR)$(ICONDIR)/$(NAME).ico
ifeq ($(shell uname), Darwin)
	rm -rf $(DESTDIR)/Applications/$(NAME).app
endif
	@echo "uninstalled"

# ---- debian .deb package ----

deb: release
	@echo "building deb package v$(VERSION)"
	rm -rf $(DEB_ROOT)

	# binary
	install -d $(DEB_ROOT)/usr/bin
	install -m 755 $(BINARY) $(DEB_ROOT)/usr/bin/$(NAME)

	# desktop file + icon
	install -d $(DEB_ROOT)/usr/share/applications
	install -m 644 dist/$(NAME).desktop $(DEB_ROOT)/usr/share/applications/$(NAME).desktop
	install -d $(DEB_ROOT)/usr/share/icons/hicolor/256x256/apps
	install -m 644 $(ICON_FILE) $(DEB_ROOT)/usr/share/icons/hicolor/256x256/apps/$(NAME).ico

	# control file
	install -d $(DEB_ROOT)/DEBIAN
	printf 'Package: $(NAME)\n\
Version: $(VERSION)\n\
Section: utils\n\
Priority: optional\n\
Architecture: $(shell dpkg --print-architecture 2>/dev/null || echo amd64)\n\
Maintainer: $(MAINTAINER)\n\
Description: $(DESCRIPTION)\n\
 TUI and CLI tool for searching domain availability across TLD lists.\n\
 Includes favorites, scratchpad, export, and custom list support.\n' > $(DEB_ROOT)/DEBIAN/control

	dpkg-deb --build --root-owner-group $(DEB_ROOT) target/$(NAME)_$(VERSION)_$(shell dpkg --print-architecture 2>/dev/null || echo amd64).deb
	@echo "deb built: target/$(NAME)_$(VERSION)_*.deb"

# ---- macOS .pkg package ----

pkg: app
	@echo "building macOS pkg v$(VERSION)"
	rm -rf $(PKG_ROOT) $(MAC_ROOT)

	# cli binary package
	install -d $(PKG_ROOT)/cli$(PREFIX)/bin
	install -m 755 $(BINARY) $(PKG_ROOT)/cli$(PREFIX)/bin/$(NAME)

	pkgbuild \
		--root $(PKG_ROOT)/cli \
		--identifier ch.teleco.$(NAME).cli \
		--version $(VERSION) \
		--install-location / \
		target/$(NAME)-cli.pkg

	# app bundle package
	install -d $(PKG_ROOT)/app
	$(MAKE) _mac_app APP_DEST=$(PKG_ROOT)/app

	pkgbuild \
		--component $(PKG_ROOT)/app/$(NAME).app \
		--identifier ch.teleco.$(NAME).app \
		--version $(VERSION) \
		--install-location /Applications \
		target/$(NAME)-app.pkg

	# distribution xml so the installer actually has permission to write to /Applications
	printf '<?xml version="1.0" encoding="utf-8"?>\n\
<installer-gui-script minSpecVersion="1">\n\
    <title>$(NAME) $(VERSION)</title>\n\
    <options customize="never" require-scripts="false"/>\n\
    <domains enable_localSystem="true"/>\n\
    <choices-outline>\n\
        <line choice="cli"/>\n\
        <line choice="app"/>\n\
    </choices-outline>\n\
    <choice id="cli" title="CLI Tool">\n\
        <pkg-ref id="ch.teleco.$(NAME).cli"/>\n\
    </choice>\n\
    <choice id="app" title="App Bundle">\n\
        <pkg-ref id="ch.teleco.$(NAME).app"/>\n\
    </choice>\n\
    <pkg-ref id="ch.teleco.$(NAME).cli" version="$(VERSION)" installKBytes="$(shell echo $$(( $$(stat -f%z $(BINARY)) / 1024 )))">#$(NAME)-cli.pkg</pkg-ref>\n\
    <pkg-ref id="ch.teleco.$(NAME).app" version="$(VERSION)" installKBytes="$(shell echo $$(( $$(stat -f%z $(BINARY)) / 1024 )))">#$(NAME)-app.pkg</pkg-ref>\n\
</installer-gui-script>\n' > $(PKG_ROOT)/distribution.xml

	productbuild \
		--distribution $(PKG_ROOT)/distribution.xml \
		--package-path target \
		target/$(NAME)-$(VERSION).pkg
	rm -f target/$(NAME)-cli.pkg target/$(NAME)-app.pkg
	rm -rf $(PKG_ROOT)
	@echo "pkg built: target/$(NAME)-$(VERSION).pkg"

# ---- internal: macOS .app bundle ----

_mac_app:
	@test -n "$(APP_DEST)" || (echo "APP_DEST not set" && exit 1)
	install -d $(APP_DEST)/$(NAME).app/Contents/MacOS
	install -d $(APP_DEST)/$(NAME).app/Contents/Resources

	# gui wrapper as the executable (or shell launcher as fallback)
	@if [ -f $(GUI_BINARY) ]; then \
		echo "using native gui wrapper"; \
		install -m 755 $(GUI_BINARY) $(APP_DEST)/$(NAME).app/Contents/MacOS/$(NAME)-app; \
	else \
		echo "gui wrapper not built, using shell launcher fallback"; \
		install -m 755 dist/mac-launcher.sh $(APP_DEST)/$(NAME).app/Contents/MacOS/$(NAME)-app; \
	fi

	# the actual tui binary (gui wrapper spawns this, shell launcher also needs it)
	install -m 755 $(BINARY) $(APP_DEST)/$(NAME).app/Contents/MacOS/$(NAME)

	# Info.plist
	printf '<?xml version="1.0" encoding="UTF-8"?>\n\
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n\
<plist version="1.0">\n\
<dict>\n\
    <key>CFBundleExecutable</key>\n\
    <string>$(NAME)-app</string>\n\
    <key>CFBundleIdentifier</key>\n\
    <string>ch.teleco.$(NAME)</string>\n\
    <key>CFBundleName</key>\n\
    <string>$(NAME)</string>\n\
    <key>CFBundleDisplayName</key>\n\
    <string>hoardom</string>\n\
    <key>CFBundleVersion</key>\n\
    <string>$(VERSION)</string>\n\
    <key>CFBundleShortVersionString</key>\n\
    <string>$(VERSION)</string>\n\
    <key>CFBundlePackageType</key>\n\
    <string>APPL</string>\n\
    <key>CFBundleIconFile</key>\n\
    <string>icon.icns</string>\n\
    <key>LSMinimumSystemVersion</key>\n\
    <string>10.12</string>\n\
    <key>NSHighResolutionCapable</key>\n\
    <true/>\n\
</dict>\n\
</plist>\n' > $(APP_DEST)/$(NAME).app/Contents/Info.plist

	# app icon
	cp dist/AppIcon.icns $(APP_DEST)/$(NAME).app/Contents/Resources/icon.icns

# ---- clean ----

clean:
	$(CARGO) clean
	rm -rf $(PKG_ROOT) $(DEB_ROOT) $(MAC_ROOT)
	rm -f target/$(NAME)_*.deb target/$(NAME)-*.pkg