include config.mk

TARGET  = toile
SRCDIR  = src
SRCS    = $(SRCDIR)/toile.c \
          $(SRCDIR)/window.c \
          $(SRCDIR)/tabs.c \
          $(SRCDIR)/uri.c \
          $(SRCDIR)/shortcuts.c \
          $(SRCDIR)/prefs.c \
          $(SRCDIR)/bookmarks.c \
          $(SRCDIR)/history.c \
          $(SRCDIR)/scheme.c \
          $(SRCDIR)/downloads.c
# Soie blocks content itself (its block.so): Toile's blocklist is WebKit's
ifeq ($(ENGINE),soie)
SRCS   += $(SRCDIR)/webview-soie.c
else
SRCS   += $(SRCDIR)/webview.c \
          $(SRCDIR)/adblock.c
endif
OBJS    = $(SRCS:.c=.o)
DEPS    = $(OBJS:.o=.d)

all: config.h $(TARGET)

config.h:
	cp config.def.h config.h

$(TARGET): $(OBJS)
	$(CC) -o $@ $^ $(LDFLAGS)

$(SRCDIR)/%.o: $(SRCDIR)/%.c config.h
	$(CC) $(CFLAGS) -MMD -MP -Isrc -I. -c -o $@ $<

-include $(DEPS)

install: all
	install -Dm755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
	install -Dm644 data/toile.desktop \
		$(DESTDIR)$(PREFIX)/share/applications/toile.desktop
	install -Dm644 data/toile.svg \
		$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/toile.svg
	install -Dm644 doc/toile.1 \
		$(DESTDIR)$(MANPREFIX)/man1/toile.1
	install -Dm644 data/style.css \
		$(DESTDIR)$(PREFIX)/share/toile/style.css
	install -Dm644 data/homepage.html \
		$(DESTDIR)$(PREFIX)/share/toile/homepage.html

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/$(TARGET)
	rm -f $(DESTDIR)$(PREFIX)/share/applications/toile.desktop
	rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/toile.svg
	rm -f $(DESTDIR)$(MANPREFIX)/man1/toile.1
	rm -f $(DESTDIR)$(PREFIX)/share/toile/style.css

run: all
	./$(TARGET)

clean:
	rm -f $(SRCDIR)/*.o $(SRCDIR)/*.d $(TARGET) config.h

.PHONY: all install uninstall run clean
