# Compiler and Toolchain Options
VALAC = valac
VALAFLAGS = -g -C

CC = gcc
CCFLAGS = -g -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-incompatible-pointer-types $(shell pkg-config --cflags glib-2.0 gio-2.0)
# FIX: Added -lXinerama directly into the dynamic system linking libraries list
LIBS = -lImlib2 -lX11 -lXinerama $(shell pkg-config --libs glib-2.0 gio-2.0)

VALA_PKG = --pkg glib-2.0 --pkg gio-2.0

TARGET = myslideshow

all: $(TARGET)

$(TARGET): myslideshow.vala x11_helper.c
	@echo "=== Step 1: Transpiling Vala source to C ==="
	$(VALAC) $(VALAFLAGS) $(VALA_PKG) myslideshow.vala
	@echo "=== Step 2: Compiling objects separately ==="
	$(CC) $(CCFLAGS) -c myslideshow.c -o myslideshow.o
	$(CC) $(CCFLAGS) -c x11_helper.c -o x11_helper.o
	@echo "=== Step 3: Linking unified application binary ==="
	$(CC) myslideshow.o x11_helper.o $(LIBS) -o $(TARGET)

clean:
	@echo "=== Cleaning compilation artifacts ==="
	rm -f $(TARGET)
	rm -f myslideshow.c
	rm -f myslideshow.vala.c
	rm -f *.o

.PHONY: all clean