-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (110 loc) · 5.41 KB
/
Copy pathMakefile
File metadata and controls
124 lines (110 loc) · 5.41 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
APP_NAME := DriveDockOSS
APP_DISPLAY_NAME := DriveDockOSS
APP_BUNDLE_ID ?= io.github.codingEzio.DriveDockOSS
APP_SUPPORT_NAME ?= $(APP_NAME)
MARKETING_VERSION ?= 0.1.1
BUILD_VERSION ?= 2
APP := build/$(APP_NAME).app
CONTENTS := $(APP)/Contents
MACOS := $(CONTENTS)/MacOS
RESOURCES := $(CONTENTS)/Resources
INFO_PLIST := $(CONTENTS)/Info.plist
EXECUTABLE := $(MACOS)/$(APP_NAME)
DEFAULT_CONFIG := config/default-config.json
BUNDLED_CONFIG := $(RESOURCES)/default-config.json
APP_ICON_SVG := assets/app-icon.svg
APP_ICON_ICONSET := build/AppIcon.iconset
APP_ICON := $(RESOURCES)/AppIcon.icns
ICON_BUILDER := scripts/pngs-to-icns.py
SWIFT_CACHE := $(CURDIR)/build/cache/swift
CLANG_CACHE := $(CURDIR)/build/cache/clang
DEVELOPER_DIR ?= $(shell xcode-select -p)
MACOS_DEPLOYMENT_TARGET ?= 15.6
SWIFT_TARGET := arm64-apple-macosx$(MACOS_DEPLOYMENT_TARGET)
INSTALL_DIR := $(HOME)/Applications
INSTALLED_APP := $(INSTALL_DIR)/$(APP_NAME).app
INSTALL_BACKUP_DIR := build/install-backups
LOCAL_CODE_SIGN_IDENTITY ?=
-include Config/Local.xcconfig
LOCAL_BUILD_CONFIG := $(wildcard Config/Local.xcconfig)
ifeq ($(strip $(LOCAL_CODE_SIGN_IDENTITY)),)
CODE_SIGN_IDENTITY ?= -
else
CODE_SIGN_IDENTITY ?= $(shell DEVELOPER_DIR="$(DEVELOPER_DIR)" security find-identity -v -p codesigning 2>/dev/null | grep -Fq '"$(LOCAL_CODE_SIGN_IDENTITY)"' && printf '%s' '$(LOCAL_CODE_SIGN_IDENTITY)' || printf '%s' '-')
endif
.PHONY: build clean doctor install launch release setup-hooks test validate
SWIFT_SOURCES := $(sort $(wildcard src/*.swift))
build: $(EXECUTABLE) validate test
$(EXECUTABLE): $(SWIFT_SOURCES) Info.plist.in $(DEFAULT_CONFIG) $(APP_ICON_SVG) $(ICON_BUILDER) Makefile $(LOCAL_BUILD_CONFIG)
mkdir -p "$(MACOS)" "$(RESOURCES)" "$(SWIFT_CACHE)" "$(CLANG_CACHE)"
sed -e "s#__APP_DISPLAY_NAME__#$(APP_DISPLAY_NAME)#g" -e "s#__APP_EXECUTABLE__#$(APP_NAME)#g" -e "s#__APP_BUNDLE_ID__#$(APP_BUNDLE_ID)#g" -e "s#__APP_NAME__#$(APP_NAME)#g" -e "s#__APP_SUPPORT_NAME__#$(APP_SUPPORT_NAME)#g" -e "s#__MARKETING_VERSION__#$(MARKETING_VERSION)#g" -e "s#__BUILD_VERSION__#$(BUILD_VERSION)#g" -e "s#__MACOS_DEPLOYMENT_TARGET__#$(MACOS_DEPLOYMENT_TARGET)#g" Info.plist.in > "$(INFO_PLIST)"
cp "$(DEFAULT_CONFIG)" "$(BUNDLED_CONFIG)"
mkdir -p "$(APP_ICON_ICONSET)"
magick -background none "$(APP_ICON_SVG)" -resize 16x16 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_16x16.png"
magick -background none "$(APP_ICON_SVG)" -resize 32x32 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_32x32.png"
magick -background none "$(APP_ICON_SVG)" -resize 64x64 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_32x32@2x.png"
magick -background none "$(APP_ICON_SVG)" -resize 128x128 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_128x128.png"
magick -background none "$(APP_ICON_SVG)" -resize 256x256 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_256x256.png"
magick -background none "$(APP_ICON_SVG)" -resize 512x512 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_512x512.png"
magick -background none "$(APP_ICON_SVG)" -resize 1024x1024 -depth 8 "PNG32:$(APP_ICON_ICONSET)/icon_512x512@2x.png"
python3 "$(ICON_BUILDER)" "$(APP_ICON_ICONSET)" "$(APP_ICON)"
env DEVELOPER_DIR="$(DEVELOPER_DIR)" SWIFT_MODULE_CACHE_PATH="$(SWIFT_CACHE)" CLANG_MODULE_CACHE_PATH="$(CLANG_CACHE)" MACOSX_DEPLOYMENT_TARGET="$(MACOS_DEPLOYMENT_TARGET)" swiftc -O -target "$(SWIFT_TARGET)" -framework AppKit -framework Foundation -framework SwiftUI -o "$(EXECUTABLE)" $(SWIFT_SOURCES)
find "$(APP)" -type d -exec chmod 755 {} +
find "$(APP)" -type f -exec chmod 644 {} +
chmod 755 "$(EXECUTABLE)"
codesign --force --sign "$(CODE_SIGN_IDENTITY)" "$(APP)"
validate:
plutil -lint "$(INFO_PLIST)"
test "$$(plutil -extract LSMinimumSystemVersion raw -o - "$(INFO_PLIST)")" = "$(MACOS_DEPLOYMENT_TARGET)"
file "$(EXECUTABLE)"
test -s "$(APP_ICON)"
codesign --verify --strict "$(APP)"
test:
python3 tests/check-config-contract.py
python3 tests/check-commit-msg-hook.py
python3 tests/check-source-boundary.py
setup-hooks:
./scripts/setup-hooks.sh
install: build
@if [ "$(RUN)" != "1" ]; then \
echo "dry-run: would install $(APP) to $(INSTALLED_APP)"; \
echo "apply: make install RUN=1"; \
else \
mkdir -p "$(INSTALL_DIR)"; \
if [ -e "$(INSTALLED_APP)" ]; then \
mkdir -p "$(INSTALL_BACKUP_DIR)"; \
backup="$(INSTALL_BACKUP_DIR)/$(APP_NAME)-$$(date +%Y%m%d-%H%M%S)-$$$$.app"; \
mv "$(INSTALLED_APP)" "$$backup"; \
echo "moved previous install to $$backup"; \
fi; \
cp -R "$(APP)" "$(INSTALLED_APP)"; \
find "$(INSTALLED_APP)" -type d -exec chmod 755 {} +; \
find "$(INSTALLED_APP)" -type f -exec chmod 644 {} +; \
chmod 755 "$(INSTALLED_APP)/Contents/MacOS/$(APP_NAME)"; \
xattr -dr com.apple.quarantine "$(INSTALLED_APP)" 2>/dev/null || true; \
echo "installed: $(INSTALLED_APP)"; \
fi
launch:
open "$(INSTALLED_APP)"
release:
./scripts/package_release.sh
doctor:
@command -v swiftc
@command -v codesign
@test -d "$(DEVELOPER_DIR)"
@command -v plutil
@command -v open
@command -v magick
@command -v lsof
@command -v diskutil
@test -f "$(DEFAULT_CONFIG)" && echo "config: $(DEFAULT_CONFIG)"
@test -f "$(APP_ICON_SVG)" && echo "icon: $(APP_ICON_SVG)"
@test -f "$(ICON_BUILDER)"
@echo "app-name: $(APP_NAME)"
@echo "version: $(MARKETING_VERSION) ($(BUILD_VERSION))"
@echo "bundle-id: $(APP_BUNDLE_ID)"
@echo "install-dir: $(INSTALL_DIR)"
@echo "developer-dir: $(DEVELOPER_DIR)"
@if [ "$(CODE_SIGN_IDENTITY)" = "-" ]; then echo "codesign: ad-hoc (-)"; else echo "codesign: $(CODE_SIGN_IDENTITY)"; fi
clean:
rm -rf build