include config.mk
DESTDIR?=

GHIDRA_NATIVE_COMMIT=0.5.0

all: ghidra-processors.txt
	$(MAKE) -C src
	$(MAKE) -C ghidra

c:
	make -C src -j4

purge: clean
	$(MAKE) uninstall
	$(MAKE) user-uninstall

ghidra-processors.txt: ghidra-processors.txt.default
	cp -f ghidra-processors.txt.default ghidra-processors.txt

asan: ghidra-processors.txt
	CFLAGS=-g CXXFLAGS=-g $(MAKE) -C src asan

asan-run:
	DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib r2 -s 9664 /Users/pancake/Downloads/usr-4/bin/bc

help:
	@echo
	@echo "./configure          # first you need to run configure"
	@echo "make                 # build r2ghidra plugins"
	@echo "make install         # install plugin and sleighs into prefix"
	@echo "make uninstall       # uninstall r2ghidra from prefix (see user-uninstall)"
	@echo "make user-install    # install in your home"
	@echo "make user-uninstall  # uninstall r2ghidra from prefix (see user-uninstall)"
	@echo

clean:
	$(MAKE) -C src clean
	$(MAKE) -C ghidra clean
	rm -f ghidra-processors.txt
	rm -f config.mk

install uninstall user-install user-uninstall:
	$(MAKE) -C src $@
	$(MAKE) -C ghidra $@

mrproper: clean
	rm -rf subprojects/ghidra-native
	rm -rf subprojects/pugixml
	rm -rf subprojects/zlib

r2ghidra_sleigh.zip dist: ghidra-processors.txt
	rm -rf tmp && mkdir -p tmp
	$(MAKE) -C ghidra user-install DH=$(shell pwd)/tmp/r2ghidra_sleigh-$(VERSION)
	cd tmp && zip -r ../r2ghidra_sleigh-$(VERSION).zip *
	rm -rf tmp


.PHONY: mrproper clean install uninstall all dist
