-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (97 loc) · 6.37 KB
/
Makefile
File metadata and controls
114 lines (97 loc) · 6.37 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
APP_NAME := Brouter
BUNDLE_ID := com.brouter.app
VERSION := 0.0.0
BUILD_DIR := build
DIST_DIR := dist
APP_DIR := $(DIST_DIR)/$(APP_NAME).app
# Prefer per-user install without sudo.
INSTALL_DIR_USER := $(HOME)/Applications
INSTALL_DIR_SYSTEM := /Applications
.PHONY: all build clean install install-system uninstall open-default-browser-settings test
all: build
clean:
rm -rf "$(BUILD_DIR)" "$(DIST_DIR)"
build: clean
mkdir -p "$(DIST_DIR)"
rm -rf "$(APP_DIR)"
# Create the .app bundle (AppleScript applet)
osacompile -o "$(APP_DIR)" "src/Brouter.applescript"
# Add our Bash router executable
mkdir -p "$(APP_DIR)/Contents/MacOS"
cp "src/brouter.sh" "$(APP_DIR)/Contents/MacOS/brouter"
chmod +x "$(APP_DIR)/Contents/MacOS/brouter"
# Patch Info.plist generated by osacompile (keep required defaults)
PLIST="$(APP_DIR)/Contents/Info.plist"; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleName" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleName string $(APP_NAME)" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleDisplayName" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDisplayName string $(APP_NAME)" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleIdentifier" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleIdentifier string $(BUNDLE_ID)" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleVersion" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $(VERSION)" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleShortVersionString" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string $(VERSION)" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :LSMinimumSystemVersion" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string 10.13" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleExecutable" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleExecutable string droplet" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :LSApplicationCategoryType" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :LSApplicationCategoryType string public.app-category.utilities" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleURLTypes" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string Web" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleTypeRole string Viewer" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string http" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:1 string https" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :NSUserActivityTypes" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :NSUserActivityTypes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :NSUserActivityTypes:0 string NSUserActivityTypeBrowsingWeb" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Delete :CFBundleDocumentTypes" "$$PLIST" >/dev/null 2>&1 || true; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0 dict" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:CFBundleTypeName string 'HTML Document'" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:CFBundleTypeRole string Viewer" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:LSHandlerRank string Default" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:LSItemContentTypes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:LSItemContentTypes:0 string public.html" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1 dict" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1:CFBundleTypeName string 'XHTML Document'" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1:CFBundleTypeRole string Viewer" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1:LSHandlerRank string Default" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1:LSItemContentTypes array" "$$PLIST" >/dev/null; \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:1:LSItemContentTypes:0 string public.xhtml" "$$PLIST" >/dev/null
@echo "Built: $(APP_DIR)"
install: build
mkdir -p "$(INSTALL_DIR_USER)"
rm -rf "$(INSTALL_DIR_USER)/$(APP_NAME).app"
cp -R "$(APP_DIR)" "$(INSTALL_DIR_USER)/"
# Refresh LaunchServices registration
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
-f "$(INSTALL_DIR_USER)/$(APP_NAME).app" || true
@echo "Installed: $(INSTALL_DIR_USER)/$(APP_NAME).app"
install-system: build
@echo "Installing to /Applications may require sudo"
sudo rm -rf "$(INSTALL_DIR_SYSTEM)/$(APP_NAME).app"
sudo cp -R "$(APP_DIR)" "$(INSTALL_DIR_SYSTEM)/"
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
-f "$(INSTALL_DIR_SYSTEM)/$(APP_NAME).app" || true
@echo "Installed: $(INSTALL_DIR_SYSTEM)/$(APP_NAME).app"
uninstall:
rm -rf "$(INSTALL_DIR_USER)/$(APP_NAME).app"
uninstall-system:
sudo rm -rf "$(INSTALL_DIR_SYSTEM)/$(APP_NAME).app"
open-default-browser-settings:
@# Best-effort deep link; macOS changes these frequently.
@if [ "$$(sw_vers -productVersion | cut -d. -f1)" -ge 13 ]; then \
open "x-apple.systempreferences:com.apple.Desktop-Settings.extension?DefaultWebBrowser" || \
open "x-apple.systempreferences:com.apple.Desktop-Settings.extension?General"; \
else \
open "x-apple.systempreferences:com.apple.preference.general"; \
fi
lint:
git ls-files --cached --others --exclude-standard -- '*.sh' | xargs shellcheck
test: lint
src/test-brouter.sh