# warning options for GCC
# source files for compiling
SOURCE = src/tinyfiledialogs/*.c src/gfx/*.c src/*.c
# executable file name
TARGETNAME = ptclone_pal_editor
# executable file path
TARGET = release/other/$(TARGETNAME)
# temporary files (for deleting)
CLEAN = src/tinyfiledialogs/*.o src/gfx/*.o src/*.o
# install path
INSTALL = /usr/local/bin/
# name of the user running the make
USER = $(shell whoami)

.PHONY: clean cleanall uninstall

$(TARGET): $(SOURCE)
	@echo "Compiling, please wait..."
	gcc  $(SOURCE) -Wno-unused-result -lSDL2 -march=native -mtune=native -O3 -o $(TARGET)
	@echo "Done! The executable is in the folder named 'release/other'."

run: $(TARGET)
	$(TARGET)

clean:
	@echo "Deleting temporary files..."
	rm $(CLEAN) 2> /dev/null || true

cleanall: clean
	@echo "Deleting executable..."
	rm $(TARGET) 2> /dev/null || true

install: $(TARGET)
	@if [ "$(USER)" = "root" ]; then \
		echo "Copying '$(TARGETNAME)' to $(INSTALL)"; \
		install -m 775 $(TARGET) "$(INSTALL)/$(TARGETNAME)"; \
	else echo "Please run 'make install' as root"; fi

uninstall:
	@if [ "$(USER)" = "root" ]; then \
		echo "Deleting '$(TARGETNAME)' from $(INSTALL)"; \
		rm "$(INSTALL)/$(TARGETNAME)"; \
	else echo "Please run 'make uninstall' as root"; fi
