#CFLAGS=-fno-stack-protector -fomit-frame-pointer -fno-exceptions -fPIC -Os -O0
CFLAGS_32=-fno-stack-protector -fno-exceptions -fPIC -Os -O0
GCC_BIN_OSX=`xcrun --sdk macosx -f gcc`
GCC_BIN_IOS=`xcrun --sdk iphoneos -f gcc`
GCC_BASE_OSX=$(GCC_BIN_OSX) $(CFLAGS)
GCC_BASE_IOS=$(GCC_BIN_IOS)
GCC_OSX=$(GCC_BASE_OSX) -arch x86_64
SDK_IOS=`xcrun --sdk iphoneos --show-sdk-path`
GCC_IOS=$(GCC_BASE_IOS) $(CFLAGS) -arch arm64 -isysroot $(SDK_IOS) \
		-Iheaders -framework CoreFoundation -framework Foundation -framework IOKit \
		-I/Users/User/rsync/mettle/build/aarch64-iphone-darwin/include \
		-I/Users/User/rsync/mettle/mettle/src \
		-L/Users/User/rsync/mettle/build/aarch64-iphone-darwin/lib \
		-lmettle -lsigar -lev -lz -leio -ldnet -lcurl -lmbedx509 -lmbedtls -lmbedcrypto \
		-framework CoreVideo -framework CoreImage -framework CoreGraphics -framework CoreMedia -framework AVFoundation -framework UIKit

GCC_IOS_32=$(GCC_BASE_IOS) $(CFLAGS_32) -arch armv7 -isysroot $(SDK_IOS) \
		-Iheaders

all: clean main_ios main_ios32

flatten: flatten-macho.m
	$(GCC_OSX) -o $@ $^

main_ios: main.m exploit64.m find.m main.m nvpatch.m set.m
	$(GCC_IOS) -o $@ $^

main_ios32: main32.c
	$(GCC_IOS_32) -o $@ $^

main_ios32.bin: main_ios32
	ruby create_bin.rb main_ios32

main_vm: flatten main_ios
	./flatten main_ios main_vm

install: main_vm
	cp main_vm ../../../../data/exploits/CVE-2016-4655/exploit

install32: main_ios32.bin
	cp main_ios32.bin ../../../../data/exploits/CVE-2016-4655/exploit32

clean:
	rm -f *.o main_ios main_ios32 main_ios32.bin main_vm flatten

