-
Notifications
You must be signed in to change notification settings - Fork 154
/
Makefile
215 lines (173 loc) · 4.95 KB
/
Makefile
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
ARCHS=armv7 arm64
CFLAGS+=-I.
CFLAGS+=-Wall
include config.mk
CFLAGS+=-DFSMON_VERSION=\"$(VERSION)\"
SOURCES=main.c util.c
SOURCES+=backend/*.c
TARGET_TRIPLE := $(shell $(CC) -dumpmachine 2>/dev/null)
ifneq ($(findstring -darwin,$(TARGET_TRIPLE)),)
TARGET_OS_TYPE=Darwin
else ifneq ($(findstring -linux,$(TARGET_TRIPLE)),)
TARGET_OS_TYPE=Linux
else ifneq ($(findstring -android,$(TARGET_TRIPLE)),)
TARGET_OS_TYPE=Linux
else
TARGET_OS_TYPE=$(shell uname)
endif
ifeq ($(TARGET_OS_TYPE),Linux)
# LINUX: GNU / ANDROID
# __
# -=(o '.
# \.-.\
# /| \\
# '| ||
# _\_):,_
FANOTIFY_CFLAGS+=-DHAVE_FANOTIFY=1
FANOTIFY_CFLAGS+=-DHAVE_SYS_FANOTIFY=1
all: fsmon
fsmon:
$(CC) -o fsmon $(CFLAGS) $(FANOTIFY_CFLAGS) $(LDFLAGS) $(SOURCES)
DESTDIR?=
PREFIX?=/usr
clean:
rm -f fsmon
else
# APPLE: OSX / IOS / IWATCH
# _
# _\)/_
# / \
# \ /
# \_._/
DESTDIR?=
PREFIX?=/usr/local
# iOS
IOS_ARCHS=$(addprefix -arch ,$(ARCHS))
IOS_CFLAGS+=$(IOS_ARCHS)
IOS_CFLAGS+=-isysroot ${IOS_SYSROOT}
IOS_CFLAGS+=-fembed-bitcode
IOS_CFLAGS+=-flto
IOS_CFLAGS+=-target arm64-apple-ios10.0
IOS_CFLAGS+=-miphoneos-version-min=10.0
IOS_CFLAGS+=-O3 -Wall
ifeq ($(shell uname -m | grep -E "iPhone|iPad|iPod" > /dev/null ; echo $${?}),0)
IOS_ON_DEVICE_COMPILE=1
IOS_SYSROOT=/
IOS_CC=/usr/bin/clang
IOS_STRIP=/usr/bin/strip
LDID=/usr/bin/ldid
else
IOS_ON_DEVICE_COMPILE=0
IOS_SYSROOT=$(shell xcrun --sdk iphoneos --show-sdk-path)
IOS_CC=$(shell xcrun --sdk iphoneos --find clang) $(IOS_CFLAGS)
IOS_STRIP=xcrun --sdk iphoneos strip
LDID=ldid2
endif
# iWatch
WCH_CFLAGS=-arch armv7k
WCH_SYSROOT=$(shell xcrun --sdk watchos --show-sdk-path)
WCH_CFLAGS+=-isysroot ${WCH_SYSROOT}
IOS_CFLAGS+=-fembed-bitcode
WCH_CC=$(shell xcrun --sdk iphoneos --find clang) $(WCH_CFLAGS)
CC?=gcc
CFLAGS+=-g -ggdb
OBJS=fsmon.o main.o
all: macos
oldios:
$(IOS_CC) $(CFLAGS) -DTARGET_IOS=1 -o fsmon-ios $(SOURCES) -framework CoreFoundation -framework MobileCoreServices
$(IOS_STRIP) fsmon-ios
if [ $(IOS_ON_DEVICE_COMPILE) != 1 ]; then \
xcrun --sdk iphoneos codesign -f --entitlements ./entitlements.plist -s- fsmon-ios; fi
IOS_FRAMEWORKS=-framework CoreFoundation -weak_framework MobileCoreServices -weak_framework CoreServices
ios:
$(IOS_CC) $(CFLAGS) -DTARGET_IOS=1 -o fsmon-ios $(SOURCES) $(IOS_FRAMEWORKS)
ls -l fsmon-ios
-$(IOS_STRIP) fsmon-ios
if [ $(IOS_ON_DEVICE_COMPILE) != 1 ]; then \
xcrun --sdk iphoneos codesign -f --entitlements ./entitlements.plist -s- fsmon-ios; \
fi
$(LDID) -Sentitlements.plist fsmon-ios
ios2:
$(MAKE) ios
$(MAKE) ios-patch
ios-patch:
rabin2 -x fsmon-ios
export a=fsmon-ios.fat/fsmon-ios.arm_64* ; \
export OFF=`rabin2 -H $$a | grep -C 2 /CoreSer | head -n1 | cut -d ' ' -f 1`; \
echo OFF=$$OFF ; \
r2 -qnwc "wx 18000080 @ $$OFF-4" $$a
rm -f fsmon-ios
lipo -create -arch arm64 fsmon-ios.fat/fsmon-ios.arm_64* -arch armv7 fsmon-ios.fat/fsmon-ios.arm_32* -output fsmon-ios
-xcrun --sdk iphoneos codesign -f --entitlements ./entitlements.plist -s- fsmon-ios
rm -rf fsmon-ios.fat
cydia: ios
$(MAKE) -C dist/cydia
macos:
$(CC) $(CFLAGS) -mmacosx-version-min=10.12 -DTARGET_OSX=1 -o fsmon-macos $(SOURCES) -framework CoreServices
strip fsmon-macos
macos-pkg:
./pkg.sh
wch:
$(WCH_CC) $(CFLAGS) -DTARGET_WATCHOS=1 -o fsmon-wch $(SOURCES)
fat: ios macos wch
lipo fsmon-ios -thin armv7 -output fsmon-ios-armv7
lipo fsmon-ios -thin arm64 -output fsmon-ios-arm64
lipo -create -output fsmon \
-arch arm64 fsmon-ios-arm64 \
-arch armv7 fsmon-ios-armv7 \
-arch armv7k fsmon-wch \
-arch x86_64 fsmon-macos
strip fsmon
codesign -s- fsmon
clean:
rm -f fsmon-macos fsmon-ios
rm -rf fsmon*.dSYM
rm -f fsmon-and*
.PHONY: cydia ios macos macos-pkg fat wch
endif
BINDIR=$(DESTDIR)/$(PREFIX)/bin
MANDIR=$(DESTDIR)/$(PREFIX)/share/man/man1
install:
mkdir -p $(BINDIR)
install -m 0755 fsmon $(BINDIR)/fsmon
mkdir -p $(MANDIR)
install -m 0644 fsmon.1 $(MANDIR)/fsmon.1
uninstall:
rm -f $(BINDIR)/fsmon
rm -f $(MANDIR)/fsmon.1
# ANDROID
#
# \.-----./
# / o o \
# `-------'
KITKAT_CFLAGS=-DHAVE_FANOTIFY=0 -DHAVE_SYS_FANOTIFY=0
LOLLIPOP_CFLAGS=-DHAVE_FANOTIFY=1 -DHAVE_SYS_FANOTIFY=0
NDK_ARCH?=
ANDROID_ARCHS=arm arm64 x86 x86_64
ANDROID_API?=
ifneq ($(NDK_ARCH),)
ANDROID_ARCHS=$(NDK_ARCH)
endif
ifeq ($(ANDROID_API),)
AAPIMODE=aagt21compile
else
AAPIMODE=$(shell test ${ANDROID_API} -gt 21 && echo aagt21compile || echo aalt21compile)
endif
andarm64:
sh android-shell.sh arm64 make android
and android:
for a in $(ANDROID_ARCHS) ; do \
if [ -z "${NDK}" ] ; then \
./android-shell.sh $$a \
$(MAKE) $(AAPIMODE) ANDROID_API=$(ANDROID_API) NDK_ARCH=$$a ; \
else \
$(MAKE) $(AAPIMODE) ANDROID_API=$(ANDROID_API) NDK_ARCH=$$a ; \
fi; \
done
aagt21compile:
ndk-gcc $(ANDROID_API) $(LOLLIPOP_CFLAGS) $(CFLAGS) $(LDFLAGS) -o fsmon-and$(ANDROID_API)-$(NDK_ARCH) $(SOURCES)
aalt21compile:
ndk-gcc $(ANDROID_API) $(KITKAT_CFLAGS) $(CFLAGS) $(LDFLAGS) -o fsmon-and$(ANDROID_API)-$(NDK_ARCH) $(SOURCES)
.PHONY: all fsmon clean
.PHONY: install uninstall
.PHONY: and android