CC = gcc
PKG_CFLAGS = $(shell pkg-config --cflags gtk+-3.0 webkit2gtk-4.1)
PKG_LIBS = $(shell pkg-config --libs gtk+-3.0 webkit2gtk-4.1)

# === PERFORMANCE-OPTIMIZED BUILD FLAGS ===
# -O3: Maximum optimization level
# -march=native: Optimize for current CPU architecture
# -mtune=native: Tune for current CPU
# -flto: Link-time optimization for cross-file inlining
# -ffast-math: Faster floating point (safe for browser UI)
# -fomit-frame-pointer: Free up a register
# -pipe: Faster compilation

CFLAGS = $(PKG_CFLAGS) -O3 -march=native -mtune=native -flto \
         -ffast-math -fomit-frame-pointer -pipe \
         -Wall -Wextra -Wno-unused-parameter

LDFLAGS = $(PKG_LIBS) -flto -Wl,-O1 -Wl,--as-needed

TARGET = veil
SRC = src/veil.c

all: $(TARGET)

$(TARGET): $(SRC)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

# Debug build (slower but easier to debug)
debug: CFLAGS = $(PKG_CFLAGS) -O0 -g -Wall -Wextra
debug: LDFLAGS = $(PKG_LIBS)
debug: $(TARGET)

# Release build with stripped binary
release: $(TARGET)
	strip --strip-all $(TARGET)

clean:
	rm -f $(TARGET)

install: $(TARGET)
	install -Dm755 $(TARGET) /usr/local/bin/$(TARGET)

.PHONY: all clean install debug release
