ifeq ($(ANDROID_NDK_ROOT),)
$(error Error : Set the env variable 'ANDROID_NDK_ROOT' with the path of the Android NDK (version 20))
endif

CC := $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang
AR := $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
OBJCOPY := $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-objcopy
LD := $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld.bfd

#==================Target Samsung S7 (8890)==================
all: samsung_s7 samsung_s7_reloc samsung_s7_reloc_0x2019e5c

CFLAGS_SAMSUNGS7 = -Os -Idevices/samsung_s7/
samsung_s7:
	[ -d bin/samsung_s7 ] || mkdir -p bin/samsung_s7/
	$(CC) arm64_stub.S -c -o bin/samsung_s7/entry.o $(CFLAGS_SAMSUNGS7)
	$(CC) debugger.c -c -o bin/samsung_s7/debugger.o $(CFLAGS_SAMSUNGS7)
	$(LD) -T devices/samsung_s7/linkscript.ld bin/samsung_s7/entry.o bin/samsung_s7/debugger.o -o bin/samsung_s7/debugger.elf --just-symbols=devices/samsung_s7/symbols.txt
	$(OBJCOPY) -O binary bin/samsung_s7/debugger.elf bin/samsung_s7/debugger.bin

CFLAGS_SAMSUNGS7_RELOC = -Os -DRELOC_DEBUGGER=1 -Idevices/samsung_s7/ 
samsung_s7_reloc:
	[ -d bin/samsung_s7 ] || mkdir -p bin/samsung_s7/
	$(CC) arm64_stub.S -c -o bin/samsung_s7/reloc_entry.o $(CFLAGS_SAMSUNGS7_RELOC)
	$(CC) debugger.c -c -o bin/samsung_s7/reloc_debugger.o $(CFLAGS_SAMSUNGS7_RELOC)
	$(LD) -T devices/samsung_s7/reloc_linkscript.ld bin/samsung_s7/reloc_entry.o bin/samsung_s7/reloc_debugger.o -o bin/samsung_s7/reloc_debugger.elf --just-symbols=devices/samsung_s7/reloc_symbols.txt
	$(OBJCOPY) -O binary bin/samsung_s7/reloc_debugger.elf bin/samsung_s7/reloc_debugger.bin

CFLAGS_SAMSUNGS7_RELOC_0x2019e5c = -Os -DRELOC_DEBUGGER_2=1 -Idevices/samsung_s7/ 
samsung_s7_reloc_0x2019e5c:
	[ -d bin/samsung_s7 ] || mkdir -p bin/samsung_s7/
	$(CC) arm64_stub.S -c -o bin/samsung_s7/reloc_entry_0x2019e5c.o $(CFLAGS_SAMSUNGS7_RELOC_0x2019e5c)
	$(CC) debugger.c -c -o bin/samsung_s7/reloc_debugger_0x2019e5c.o $(CFLAGS_SAMSUNGS7_RELOC_0x2019e5c)
	$(LD) -T devices/samsung_s7/reloc_linkscript_0x2019e5c.ld bin/samsung_s7/reloc_entry_0x2019e5c.o bin/samsung_s7/reloc_debugger_0x2019e5c.o -o bin/samsung_s7/reloc_debugger_0x2019e5c.elf --just-symbols=devices/samsung_s7/reloc_symbols_0x2019e5c.txt
	$(OBJCOPY) -O binary bin/samsung_s7/reloc_debugger_0x2019e5c.elf bin/samsung_s7/reloc_debugger_0x2019e5c.bin