-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (148 loc) · 4.34 KB
/
Makefile
File metadata and controls
184 lines (148 loc) · 4.34 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
172
173
174
175
176
177
178
179
180
181
182
183
#
# Created 190116 lynnl
# Makefile of Quick Look plugin
#
include Makefile.inc
#
# Check mandatory vars
#
ifndef PLUGIN_NAME
$(error PLUGIN_NAME not defined)
endif
ifndef PLUGIN_VERSION
$(error PLUGIN_VERSION not defined)
endif
# [assume] zero indicates no build number
PLUGIN_BUILD?= 0
ifndef BUNDLE_DOMAIN
$(error BUNDLE_DOMAIN not defined)
endif
ifndef PLUGIN_SUPPORTED_UTI
$(error PLUGIN_SUPPORTED_UTI not defined)
endif
# defaults
PLUGIN_BID?= $(BUNDLE_DOMAIN).quicklook.$(PLUGIN_NAME)
PLUGIN_BUNDLE?= $(PLUGIN_NAME).qlgenerator
PLUGIN_MACHO?= $(PLUGIN_NAME)
ARCHFLAGS?= -arch x86_64 -arch i386
PREFIX?= ${HOME}/Library/QuickLook
#
# Set default macOS SDK
# You may use
# sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
# to switch to Xcode from Command Line Tools if cannot find any SDK
#
SDKROOT?= $(shell xcrun --sdk macosx --show-sdk-path)
SDKFLAGS:= -isysroot $(SDKROOT)
CC:= $(shell xcrun -find -sdk $(SDKROOT) cc)
#CXX:= $(shell xcrun -find -sdk $(SDKROOT) c++)
CODESIGN:= $(shell xcrun -find -sdk $(SDKROOT) codesign)
#
# Standard defines and includes for kernel extensions
#
# The __ql_makefile__ macro used to compatible with XCode
# Since XCode use intermediate objects which causes symbol duplicated
#
CPPFLAGS+= -D__ql_makefile__
#
# Convenience defines
# PLUGIN_BID macro will be used in KMOD_EXPLICIT_DECL
#
CPPFLAGS+= -DPLUGIN_NAME_S=\"$(PLUGIN_NAME)\" \
-DPLUGIN_VERSION_S=\"$(PLUGIN_VERSION)\" \
-DPLUGIN_BUILD_S=\"$(PLUGIN_BUILD)\" \
-DPLUGIN_BID_S=\"$(PLUGIN_BID)\"
PLUGIN_ID:= $(shell uuidgen)
TIME_STAMP:= $(shell date +'%Y/%m/%d\ %H:%M:%S%z')
CPPFLAGS+= -D__TS__=\"$(TIME_STAMP)\" \
-DPLUGIN_ID=\"$(PLUGIN_ID)\"
#
# C compiler flags
#
ifdef MACOSX_VERSION_MIN
CFLAGS+= -mmacosx-version-min=$(MACOSX_VERSION_MIN)
else
CFLAGS+= -mmacosx-version-min=10.5
endif
CFLAGS+= $(SDKFLAGS) \
$(ARCHFLAGS) \
-std=c99 \
-fmodules \
-fno-common
# warnings
CFLAGS+= -Wall
#CFLAGS+= -Wextra
#CFLAGS+= -Werror
# linker flags
ifdef MACOSX_VERSION_MIN
LDFLAGS+= -mmacosx-version-min=$(MACOSX_VERSION_MIN)
else
LDFLAGS+= -mmacosx-version-min=10.5
endif
LDFLAGS+= $(SDKFLAGS) \
$(ARCHFLAGS) \
-Xlinker -object_path_lto \
-Xlinker -export_dynamic \
-bundle
# source, object files
SRCS:= $(wildcard src/*.m)
SRCS+= $(wildcard src/*.c)
OBJS:= $(SRCS:.m=.o)
OBJS:= $(OBJS:.c=.o)
# targets
all: debug
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -x c -c -o $@ $<
%.o: %.m
$(CC) $(CPPFLAGS) $(CFLAGS) -x objective-c -c -o $@ $<
$(PLUGIN_MACHO): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
otool -h $@
otool -l $@ | grep uuid
Info.plist: Info.plist.in
sed \
-e 's/__PLUGIN_NAME__/$(PLUGIN_NAME)/g' \
-e 's/__PLUGIN_VERSION__/$(PLUGIN_VERSION)/g' \
-e 's/__PLUGIN_BUILD__/$(PLUGIN_BUILD)/g' \
-e 's/__PLUGIN_BID__/$(PLUGIN_BID)/g' \
-e 's/__OS_BUILD__/$(shell /usr/bin/sw_vers -buildVersion)/g' \
-e 's/__CLANG_VERSION__/$(shell $(CC) -v 2>&1 | grep version)/g' \
-e 's/__DEV_LANG__/$(shell echo $$LANG | cut -d'.' -f1)/g' \
-e 's/__UUID__/$(PLUGIN_ID)/g' \
$^ > $@
$(PLUGIN_BUNDLE): $(PLUGIN_MACHO) Info.plist
mkdir -p $@/Contents/MacOS
mv $< $@/Contents/MacOS/$(PLUGIN_NAME)
for UTI in $(PLUGIN_SUPPORTED_UTI); do \
/usr/libexec/PlistBuddy -c "Add :CFBundleDocumentTypes:0:LSItemContentTypes:0 string $$UTI" Info.plist; \
done
mv Info.plist $@/Contents/Info.plist
ifdef COPYRIGHT
/usr/libexec/PlistBuddy -c 'Add :NSHumanReadableCopyright string "$(COPYRIGHT)"' $@/Contents/Info.plist
endif
ifdef SIGNCERT
$(CODESIGN) --force --timestamp=none --sign $(SIGNCERT) $@
/usr/libexec/PlistBuddy -c 'Add :CFBundleSignature string ????' $@/Contents/Info.plist
endif
touch $@
dsymutil $(ARCHFLAGS) -o $(PLUGIN_BUNDLE).dSYM $@/Contents/MacOS/$(PLUGIN_NAME)
release: CFLAGS += -Os
release: $(PLUGIN_BUNDLE)
# see: https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
# Those two flags must present at the same time o.w. debug symbol cannot be generated
debug: CPPFLAGS += -g -DDEBUG
debug: CFLAGS += -O0
debug: $(PLUGIN_BUNDLE)
install: release uninstall
mkdir -p "$(PREFIX)"
cp -r $(PLUGIN_BUNDLE) "$(PREFIX)/$(PLUGIN_BUNDLE)"
qlmanage -r cache
qlmanage -r
qlmanage -m | grep -w $(PLUGIN_NAME)
uninstall:
rm -rf "$(PREFIX)/$(PLUGIN_BUNDLE)"
qlmanage -r cache
qlmanage -r
clean:
rm -rf $(PLUGIN_BUNDLE) $(PLUGIN_BUNDLE).dSYM Info.plist $(OBJS) $(PLUGIN_MACHO)
.PHONY: all debug release intall uninstall clean