-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (151 loc) · 5.97 KB
/
Makefile
File metadata and controls
171 lines (151 loc) · 5.97 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
167
168
169
170
171
ifeq (,$(filter help completion,$(MAKECMDGOALS)))
# Dynamic compiler detection
XCODE_PATH := $(shell xcode-select -p)
XCODE_TOOLCHAIN := $(XCODE_PATH)/Toolchains/XcodeDefault.xctoolchain
CC := $(shell xcrun -find clang)
CXX := $(shell xcrun -find clang++)
# SDK paths
SDKROOT ?= $(shell xcrun --show-sdk-path)
ISYSROOT := $(shell xcrun -sdk macosx --show-sdk-path)
INCLUDE_PATH := $(shell xcrun -sdk macosx --show-sdk-platform-path)/Developer/SDKs/MacOSX.sdk/usr/include
else
# Fallbacks for non-build goals to avoid SDK discovery
CC := clang
CXX := clang++
SDKROOT :=
ISYSROOT :=
INCLUDE_PATH :=
endif
# Compiler and flags
CFLAGS = -Wall -Wextra -O2 \
-fobjc-arc \
-isysroot $(SDKROOT) \
-iframework $(SDKROOT)/System/Library/Frameworks \
-F/System/Library/PrivateFrameworks \
-IZKSwizzle
ARCHS = -arch x86_64 -arch arm64 -arch arm64e
FRAMEWORK_PATH = $(SDKROOT)/System/Library/Frameworks
PRIVATE_FRAMEWORK_PATH = $(SDKROOT)/System/Library/PrivateFrameworks
PUBLIC_FRAMEWORKS = -framework Foundation -framework AppKit -framework QuartzCore -framework Cocoa \
-framework CoreFoundation
# Project name and paths
PROJECT = apple_sharpener
DYLIB_NAME = lib$(PROJECT).dylib
CLI_NAME = sharpener
BUILD_DIR = build
SOURCE_DIR = src
INSTALL_DIR = /var/ammonia/core/tweaks
CLI_INSTALL_DIR = /usr/local/bin
# Source files
DYLIB_SOURCES = $(SOURCE_DIR)/sharpener/sharpener.m \
$(SOURCE_DIR)/sharpener/Windows/window.m \
$(SOURCE_DIR)/sharpener/Dock/dock.m \
ZKSwizzle/ZKSwizzle.m
DYLIB_OBJECTS = $(DYLIB_SOURCES:%.m=$(BUILD_DIR)/%.o)
# CLI tool source and object
CLI_SOURCE = $(SOURCE_DIR)/sharpener/clitool.m
CLI_OBJECT = $(BUILD_DIR)/sharpener/clitool.o
# Installation targets
INSTALL_PATH = $(INSTALL_DIR)/$(DYLIB_NAME)
CLI_INSTALL_PATH = $(CLI_INSTALL_DIR)/$(CLI_NAME)
BLACKLIST_SOURCE = lib$(PROJECT).dylib.blacklist
BLACKLIST_DEST = $(INSTALL_DIR)/lib$(PROJECT).dylib.blacklist
# Dylib settings
DYLIB_FLAGS = -dynamiclib \
-install_name @rpath/$(DYLIB_NAME) \
-compatibility_version 1.0.0 \
-current_version 1.0.0
# Default target
all: clean $(BUILD_DIR)/$(DYLIB_NAME) $(BUILD_DIR)/$(CLI_NAME) ## Build dylib and CLI
# Create build directory and subdirectories
$(BUILD_DIR):
@rm -rf $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)/ZKSwizzle
@mkdir -p $(BUILD_DIR)/src/sharpener
# Compile source files
$(BUILD_DIR)/%.o: %.m | $(BUILD_DIR)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(ARCHS) -c $< -o $@
# Link dylib
$(BUILD_DIR)/$(DYLIB_NAME): $(DYLIB_OBJECTS)
$(CC) $(DYLIB_FLAGS) $(ARCHS) $(DYLIB_OBJECTS) -o $@ \
-F$(FRAMEWORK_PATH) \
-F$(PRIVATE_FRAMEWORK_PATH) \
$(PUBLIC_FRAMEWORKS) \
-L$(SDKROOT)/usr/lib
# Build CLI tool (updated to avoid linking UI frameworks)
$(BUILD_DIR)/$(CLI_NAME): $(CLI_SOURCE)
@rm -f $(BUILD_DIR)/$(CLI_NAME)
$(CC) $(CFLAGS) $(ARCHS) $(CLI_SOURCE) \
-DAPPLE_SHARPENER_VERSION="\"$(shell cat VERSION)\"" \
-framework Foundation \
-framework CoreFoundation \
-o $@
# Install both dylib and CLI tool
install: $(BUILD_DIR)/$(DYLIB_NAME) $(BUILD_DIR)/$(CLI_NAME) ## Install dylib and CLI to system
@echo "Installing dylib to $(INSTALL_DIR) and CLI tool to $(CLI_INSTALL_DIR)"
# Create the target directories.
sudo mkdir -p $(INSTALL_DIR)
sudo mkdir -p $(CLI_INSTALL_DIR)
# Install the tweak's dylib where injection takes place.
sudo install -m 755 $(BUILD_DIR)/$(DYLIB_NAME) $(INSTALL_DIR)
# Install the CLI tool separately so it will not have DYLD_INSERT_LIBRARIES set.
sudo install -m 755 $(BUILD_DIR)/$(CLI_NAME) $(CLI_INSTALL_DIR)
@if [ -f $(BLACKLIST_SOURCE) ]; then \
sudo cp $(BLACKLIST_SOURCE) $(BLACKLIST_DEST); \
sudo chmod 644 $(BLACKLIST_DEST); \
echo "Installed $(DYLIB_NAME), $(CLI_NAME), and blacklist"; \
else \
echo "Warning: $(BLACKLIST_SOURCE) not found"; \
echo "Installed $(DYLIB_NAME) and $(CLI_NAME)"; \
fi
# Test target that builds, installs, and relaunches test applications
test: install ## Build, install, and restart test applications
@echo "Force quitting test applications and Dock..."
$(eval TEST_APPS := Spotify "System Settings" Chess soffice "Brave Browser" Beeper Safari Finder qBittorrent zoom.us)
@for app in $(TEST_APPS); do \
pkill -9 "$$app" 2>/dev/null || true; \
done
@echo "Killing Dock to reload with new dylib..."
@pkill -9 "Dock" 2>/dev/null || true
@echo "Relaunching test applications..."
@for app in $(TEST_APPS); do \
if [ "$$app" != "soffice" ] && [ "$$app" != "zoom.us" ]; then \
open -a "$$app" 2>/dev/null || true; \
elif [ "$$app" = "zoom.us" ]; then \
open -a "zoom.us" 2>/dev/null || true; \
fi; \
done
@echo "Test applications and Dock restarted with new dylib loaded"
# Clean build files
clean: ## Remove build directory and artifacts
@rm -rf $(BUILD_DIR)
@echo "Cleaned build directory"
# Delete installed files
delete: ## Delete installed files and relaunch Finder
@echo "Force quitting test applications and Dock..."
$(eval TEST_APPS := Spotify "System Settings" Chess soffice "Brave Browser" Beeper Safari Finder qBittorrent zoom.us)
@for app in $(TEST_APPS); do \
pkill -9 "$$app" 2>/dev/null || true; \
done
@echo "Killing Dock..."
@pkill -9 "Dock" 2>/dev/null || true
@sleep 2 && open -a "Finder" || true
@sudo rm -f $(INSTALL_PATH)
@sudo rm -f $(CLI_INSTALL_PATH)
@sudo rm -f $(BLACKLIST_DEST)
@echo "Deleted $(DYLIB_NAME), $(CLI_NAME), and blacklist from $(INSTALL_DIR)"
# Uninstall
uninstall: ## Uninstall dylib, CLI, and blacklist
@sudo rm -f $(INSTALL_PATH)
@sudo rm -f $(CLI_INSTALL_PATH)
@sudo rm -f $(BLACKLIST_DEST)
@echo "Uninstalled $(DYLIB_NAME), $(CLI_NAME), and blacklist"
installer: ## Create a .pkg installer
@echo "Packaging Apple Sharpener into a .pkg installer"
./scripts/create_installer.sh
help: ## Show this help
@echo "Available make targets:"
@grep -E '^[a-zA-Z0-9_.-]+:.*##' $(MAKEFILE_LIST) | sed 's/^\([^:]*\):.*##\s*\(.*\)/ \1|\2/' | awk -F'|' '{printf " %-20s %s\n", $$1, $$2}'
.PHONY: all clean install test delete uninstall installer help