CFLAGS=
PNAME=prog
CHECKPRUN=java -jar checkproject.jar
DRCHECKPRUN=java -Dcheckmem=yes -jar checkproject.jar
FETCH=curl -O "https://inf-swe-jenkins.technikum-wien.at/job/SYS-BMR-PAD-checkproject/lastSuccessfulBuild/artifact/deploy/{checkproject.jar,checkproject.sh,properties.txt}" --progress-bar
FETCHMEM=curl -L -O https://bintray.com/artifact/download/bruening/DrMemory/DrMemory-MacOS-1.8.1-0.tar.gz --progress-bar
LINE=\n-----------------------------------------------\n

all: clean
	gcc $(CFLAGS) *.c -o $(PNAME)

clean:
	rm -rf *o $(PNAME) $(PNAME).*

run: all
	clear
	./prog

debug: all
	lldb ./$(PNAME)

gdebug: all
	lldb -s gui ./(PNAME)

check: getcheck all
	$(CHECKPRUN)

drcheck: getcheck getdrmem all
	$(DRCHECKPRUN)

getcheck:
	@test -s ./checkproject.jar || (echo "\033[31m$(LINE)checkproject seems to be missing!\nFetching NOW!\033[0m";$(FETCH);echo "\033[31mmodding properties.txt\033[0m";sed -i '' -e 's/# exec=/exec=prog/' properties.txt;sed -i '' -e 's/checkmem=no/#checkmem=yes/' properties.txt;sed -i '' -e 's/# drMemoryPath=/drMemoryPath=..\/..\/drmemory/' properties.txt;echo "\033[34mDONE$(LINE)\033[0m")

getdrmem:
	@test -d ../../drmemory || (echo "\033[31m$(LINE)DRMemory seems to be missing!\nFetching NOW!\033[0m";$(FETCHMEM);echo "\033[31m$ Extracting package\033[0m";tar -zxf DrMemory-MacOS-1.8.1-0.tar.gz ;echo "\033[34m$(LINE)Deleting image!\033[0m";echo "\033[34m$(LINE)Moving extracted Folder!\033[0m";mv DrMemory-MacOS-1.8.1-0 drmemory;mv drmemory ../../;echo "\033[34mDONE$(LINE)\033[0m")
