prefix = /opt

TARGET = whatchord

CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2

SRC_DIR = ./Sources

SDL3_CFLAGS := $(shell pkg-config --cflags sdl3 sdl3-ttf)
SDL3_LIBS   := $(shell pkg-config --libs sdl3 sdl3-ttf)

RTMIDI_CFLAGS := $(shell pkg-config --cflags rtmidi)
RTMIDI_LIBS   := $(shell pkg-config --libs rtmidi)

CXXFLAGS += $(SDL3_CFLAGS) $(RTMIDI_CFLAGS) -I$(SRC_DIR)
LDFLAGS  = $(SDL3_LIBS) $(RTMIDI_LIBS) -lpthread

SRCS = $(wildcard $(SRC_DIR)/*.C)

OBJS = $(SRCS:.C=.o)

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CXX) $(OBJS) -o $(TARGET) $(LDFLAGS)

$(SRC_DIR)/%.o: $(SRC_DIR)/%.C
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -f $(OBJS) $(TARGET)

rebuild: clean all

install:
	mkdir -pm 0755 $(DESTDIR)$(prefix)/pietraszczyk/whatchord
	mkdir -pm 0755 $(DESTDIR)$(prefix)/pietraszczyk/whatchord/ttf
	mkdir -pm 0755 $(DESTDIR)/usr/share/applications
	install -m 0755 whatchord $(DESTDIR)$(prefix)/pietraszczyk/whatchord
	install -m 0644 ttf/LiberationMono-Regular.ttf $(DESTDIR)$(prefix)/pietraszczyk/whatchord/ttf
	install -m 0644 Pixmaps/icon.png $(DESTDIR)$(prefix)/pietraszczyk/whatchord/icon.png
	install -m 0644 whatchord.desktop $(DESTDIR)/usr/share/applications
.PHONY: install


uninstall:
	rm -r $(prefix)//pietraszczyk/whatchord
	rm /usr/share/applications/whatchord.desktop
	update-desktop-database /usr//share/applications
.PHONY: uninstall


.PHONY: all clean rebuild
