#!/bin/bash
# A bloody simple, hand-rolled configure script

echo "Checking for pkg-config..."
if ! command -v pkg-config &> /dev/null; then
    echo "Error: pkg-config is not installed. Fucking install it first."
    exit 1
fi

echo "Checking for gtkmm-3.0..."
if ! pkg-config --exists gtkmm-3.0; then
    echo "Error: gtkmm-3.0 not found. Install libgtkmm-3.0-dev."
    exit 1
fi

echo "Checking for libarchive..."
if ! pkg-config --exists libarchive; then
    echo "Error: libarchive not found. Install libarchive-dev."
    exit 1
fi

# Grab the flags
GTKMM_CFLAGS=$(pkg-config --cflags gtkmm-3.0)
GTKMM_LIBS=$(pkg-config --libs gtkmm-3.0)
ARCHIVE_CFLAGS=$(pkg-config --cflags libarchive)
ARCHIVE_LIBS=$(pkg-config --libs libarchive)

echo "Writing Makefile..."

cat <<EOF > Makefile
# Auto-generated Makefile
CXX = g++
CXXFLAGS = -std=c++17 -Wall $GTKMM_CFLAGS $ARCHIVE_CFLAGS
LDFLAGS = $GTKMM_LIBS $ARCHIVE_LIBS

SOURCES = main.cpp MainWindow.cpp
OBJECTS = \$(SOURCES:.cpp=.o)
EXECUTABLE = gnome-vault

all: \$(EXECUTABLE)

\$(EXECUTABLE): \$(OBJECTS)
	\$(CXX) \$(OBJECTS) -o \$@ \$(LDFLAGS)

%.o: %.cpp
	\$(CXX) \$(CXXFLAGS) -c \$< -o \$@

clean:
	rm -f \$(OBJECTS) \$(EXECUTABLE)
EOF

echo "Fucking done. You can now run 'make'."
