API ?= 35
NDK_ROOT ?= $(HOME)/android-ndk-cache/android-ndk-r29
CC := $(NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android$(API)-clang
OUT := build/exploit

CFLAGS := -O2 -g0 -Wall -Wextra -D_GNU_SOURCE -D__ARM \
	-ffunction-sections -fdata-sections -Isrc
LDFLAGS := -static -pthread -Wl,--gc-sections -Wl,--strip-all
SOURCES := \
	src/main.c src/util.c src/patch.c src/page.c src/pipe.c \
	src/late_refs.c src/su.c src/payloads.S
HEADERS := src/common.h src/target.h src/kernelsnitch/*.h

.DEFAULT_GOAL := exploit
.PHONY: all exploit clean

all: exploit
exploit: $(OUT)

build:
	mkdir -p $@

$(OUT): $(SOURCES) $(HEADERS) | build
	$(CC) $(CFLAGS) $(SOURCES) -o $@ $(LDFLAGS)
	sha256sum $@
clean:
	rm -rf build
