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)
	$(MAKE) -C po

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 data/style.css \
		$(DESTDIR)$(PREFIX)/share/toile/style.css
	install -Dm644 data/homepage.html \
		$(DESTDIR)$(PREFIX)/share/toile/homepage.html
	for l in `cat po/LINGUAS`; do \
		install -Dm644 data/homepage.$$l.html \
			$(DESTDIR)$(PREFIX)/share/toile/homepage.$$l.html; \
	done
	$(MAKE) -C po install DESTDIR=$(DESTDIR) PREFIX=$(PREFIX)

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)$(PREFIX)/share/toile/style.css
	rm -f $(DESTDIR)$(PREFIX)/share/toile/homepage*.html
	for l in `cat po/LINGUAS`; do \
		rm -f $(DESTDIR)$(PREFIX)/share/locale/$$l/LC_MESSAGES/toile.mo; \
	done

run: all
	./$(TARGET)

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

.PHONY: all install uninstall run clean
