-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (86 loc) · 3.65 KB
/
Makefile
File metadata and controls
111 lines (86 loc) · 3.65 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
SWIFT ?= swift
SWIFTLINT ?= swiftlint
SWIFTFORMAT ?= swiftformat
CODESIGN ?= codesign
APP_NAME := Mote
BUNDLE_ID := com.samzong.mote
BUILD_DIR := .build
APP_BUNDLE := /Applications/$(APP_NAME).app
APP_ICON := Resources/AppIcon.icns
ARCH ?= arm64
DMG_DIR := $(BUILD_DIR)/dmg
DMG_STAGING := $(DMG_DIR)/staging
DMG_PATH := $(BUILD_DIR)/$(APP_NAME)-$(ARCH).dmg
CODE_SIGN_IDENTITY ?= -
CODE_SIGN_REQUIREMENT := =designated => identifier "$(BUNDLE_ID)"
CODE_SIGN := $(CODESIGN) --force --sign $(CODE_SIGN_IDENTITY) --requirements '$(CODE_SIGN_REQUIREMENT)'
BOLD := \033[1m
CYAN := \033[36m
GREEN := \033[32m
RESET := \033[0m
.DEFAULT_GOAL := help
# -- Development --------------------------------------------------------------
.PHONY: build app run test lint format check
build: ## Build debug artifacts
$(SWIFT) build -c debug
app: ## Build the debug app product
$(SWIFT) build -c debug --product $(APP_NAME)
run: app ## Run the debug app product
$(BUILD_DIR)/debug/$(APP_NAME)
test: ## Run tests
$(SWIFT) test
lint: ## Run SwiftLint
$(SWIFTLINT) lint --quiet
format: ## Format sources and tests
$(SWIFTFORMAT) Sources Tests
check: ## Run build, lint, and tests
@printf '\n$(BOLD)[1/3] Building$(RESET)\n'
@$(MAKE) --no-print-directory build
@printf '\n$(BOLD)[2/3] Running lint$(RESET)\n'
@$(MAKE) --no-print-directory lint
@printf '\n$(BOLD)[3/3] Running tests$(RESET)\n'
@$(MAKE) --no-print-directory test
@printf '\n$(GREEN)[ok] All checks passed$(RESET)\n\n'
# -- Packaging ----------------------------------------------------------------
.PHONY: dmg install uninstall
dmg: ## Build an ad-hoc signed DMG
$(SWIFT) build -c release --arch $(ARCH) --product $(APP_NAME)
rm -rf $(DMG_STAGING)
mkdir -p $(DMG_STAGING)/$(APP_NAME).app/Contents/MacOS
mkdir -p $(DMG_STAGING)/$(APP_NAME).app/Contents/Resources
cp $$($(SWIFT) build -c release --arch $(ARCH) --product $(APP_NAME) --show-bin-path)/$(APP_NAME) $(DMG_STAGING)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME)
cp Resources/Info.plist $(DMG_STAGING)/$(APP_NAME).app/Contents/Info.plist
cp $(APP_ICON) $(DMG_STAGING)/$(APP_NAME).app/Contents/Resources/AppIcon.icns
$(CODE_SIGN) $(DMG_STAGING)/$(APP_NAME).app
ln -s /Applications $(DMG_STAGING)/Applications
rm -f $(DMG_PATH)
hdiutil create -volname "$(APP_NAME)" \
-srcfolder $(DMG_STAGING) \
-ov -format UDZO \
$(DMG_PATH)
rm -rf $(DMG_DIR)
@printf "DMG created: %s\n" "$(DMG_PATH)"
install: ## Install an ad-hoc signed app bundle to /Applications
$(SWIFT) build -c release --arch $(ARCH) --product $(APP_NAME)
mkdir -p $(APP_BUNDLE)/Contents/MacOS
mkdir -p $(APP_BUNDLE)/Contents/Resources
cp $$($(SWIFT) build -c release --arch $(ARCH) --product $(APP_NAME) --show-bin-path)/$(APP_NAME) $(APP_BUNDLE)/Contents/MacOS/$(APP_NAME)
cp Resources/Info.plist $(APP_BUNDLE)/Contents/Info.plist
cp $(APP_ICON) $(APP_BUNDLE)/Contents/Resources/AppIcon.icns
$(CODE_SIGN) $(APP_BUNDLE)
@printf "Installed to %s\n" "$(APP_BUNDLE)"
uninstall: ## Remove the installed app bundle
rm -rf $(APP_BUNDLE)
@printf "Removed %s\n" "$(APP_BUNDLE)"
# -- Maintenance --------------------------------------------------------------
.PHONY: clean
clean: ## Remove SwiftPM build artifacts
$(SWIFT) package clean
rm -rf $(BUILD_DIR)
# -- Help ---------------------------------------------------------------------
.PHONY: help
help: ## Show available targets
@awk 'BEGIN {FS = ":.*## "; printf "\n$(BOLD)mote$(RESET) - macOS text rewrite app\n"} \
/^# -- / {n = $$0; gsub(/(^# -- | -+$$)/, "", n); printf "\n$(BOLD)%s$(RESET)\n", n} \
/^[a-zA-Z_-]+:.*## / {printf " $(CYAN)make %-10s$(RESET) %s\n", $$1, $$2} \
END {printf "\n"}' $(MAKEFILE_LIST)