.PHONY: all clean test test-unattended

GTK=3
GTK_CFLAGS=$(shell pkg-config --cflags gtk+-$(GTK).0)
GTK_LIBS=$(shell pkg-config --libs gtk+-$(GTK).0)

DEBUG=-O0 -g
CFLAGS=$(GTK_CFLAGS) $(DEBUG)
LIBS=$(GTK_LIBS)

# Disable GTypeDebugFlags and GTimeVal deprecations, might be overkill.
CFLAGS+=-DGTK_DISABLE_DEPRECATED

# Define this symbol to insert a line ending at the end of fenced codeblocks
# imitating the cmark implementation of CM 0.30.  By default mdview does
# not mimic cmark because it leaves it to the document author to make such
# decision. To assist testing against the CM specification, run-time option
# --cm-block-end is available to imitate cmark when this symbol is defined.
CFLAGS+=-UCOMMONMARK_FENCED_CODEBLOCK_LINE_ENDING

# DEBUGGING Define DEBPRTELM={0,1,2} to trace protected elements.
CFLAGS+=-UDEBPRTELM

# DEBUGGING Define DEBEMPH to trace markdown (strong) emphasis.
CFLAGS+=-UDEBEMPH

SRC = \
	egg-markdown.c \
	help-viewer.c \
	markdown-text-view.c

INCL = \
	egg-markdown.h \
	egg-markdown-color.h \
	egg-markdown-style.h \
	help-viewer.h \
	markdown-text-view.h

all: mdview

mdview: $(SRC) $(INCL)
	$(CC) $(SRC) -o mdview $(CFLAGS) $(LIBS)

clean:
	rm -f mdview

test: all test-unattended
	./mdview examples

test-unattended: all
	@test/run_unattended_tests.sh

### build distribution package
package: clean
	-rm -rf /tmp/mdview-fossil
	-mkdir -p /tmp/mdview-fossil
	-cp  -a * /tmp/mdview-fossil
	-fossil info > /tmp/mdview-fossil/fossil-version
	-echo Version $(shell date +%F) > /tmp/mdview-fossil/VERSION
	-rm -f /tmp/mdview-fossil/auth*
	-tar -C /tmp -cjvf ../mdview-$(shell date +%F).tar.bz2 mdview-fossil
	-rm -rf /tmp/mdview-fossil

### run C preprocessor
%.i: %.c
	$(CC) -E $< -o $@ $(CFLAGS) $(LIBS)

