# Makefile.in for REMIND
#

SHELL= /bin/sh
BETA = 1
srcdir=@srcdir@
prefix=@prefix@
exec_prefix=@exec_prefix@
mandir=@mandir@
bindir=@bindir@
datadir=@datadir@
datarootdir=@datarootdir@
VPATH=$(srcdir)
VERSION=@VERSION@

INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

PROGS=		remind rem2ps
SCRIPTS=	$(srcdir)/../scripts/tkremind

MANS=		$(srcdir)/../man/rem2ps.1 $(srcdir)/../man/remind.1 \
		$(srcdir)/../man/tkremind.1

.SUFFIXES:
.SUFFIXES: .c .o

REMINDSRCS=	calendar.c dedupe.c dynbuf.c dorem.c dosubst.c expr.c	\
		files.c funcs.c globals.c hashtab.c hashtab_stats.c	\
		hbcal.c ifelse.c init.c main.c markup.c md5.c moon.c    \
		omit.c queue.c sort.c token.c trans.c trigger.c         \
		userfns.c utils.c var.c

XLATSRC= xlat.c

REMINDHDRS=config.h custom.h dynbuf.h err.h globals.h hashtab.h	\
	   md5.h protos.h rem2ps.h types.h version.h
REMINDOBJS= $(REMINDSRCS:.c=.o) $(XLATSRC:.c=.o)

all: remind rem2ps

test-basic: all
	@sh ../tests/test-rem

test-rem2html: all
	@sh ../tests/test-rem2html

test-rem2pdf: all
	@sh ../tests/test-rem2pdf

test-tz: all
	@sh ../tests/test-timezone-support

# rem2pdf - THESE ARE SKIPPED
# because Cairo output varies across machines
# and Cairo versions... *SIGH*
test: test-basic test-rem2html test-tz

.c.o:
	@CC@ -c @CPPFLAGS@ @CFLAGS@ @DEFS@ $(CEXTRA) -DSYSDIR=$(datarootdir)/remind -I. -I$(srcdir) $<

# Extract all tr() strings into a file.  NOTE: SOURCE CODE MUST NOT HAVE
# MORE THAN ONE tr() PER LINE!!!
xlat.c: $(REMINDSRCS)
	@echo "#include <stddef.h>" > xlat.c
	@echo "char const *translatables[] = {" >> xlat.c
	@cat $(REMINDSRCS) | grep 'tr(".*")' | sed -e 's/.*tr."/"/' -e 's/").*/"/' | LANG=C LC_ALL=C sort | uniq | grep -E -v '^"(ago|am|and|at|from now|is|hour|minute|now|on|pm|today|tomorrow|was)"$$' | sed -e 's/^/    /' -e 's/$$/,/' >> xlat.c
	@echo "    NULL" >> xlat.c
	@echo "};" >> xlat.c

$(REMINDOBJS): $(REMINDHDRS)

rem2ps: rem2ps.o dynbuf.o json.o
	@CC@ @CFLAGS@ @LDFLAGS@ $(LDEXTRA) -o rem2ps rem2ps.o dynbuf.o json.o -lm

remind: $(REMINDOBJS)
	@CC@ @CFLAGS@ @LDFLAGS@ $(LDEXTRA) -o remind $(REMINDOBJS) @LIBS@

install: all
	-mkdir -p $(DESTDIR)$(bindir) || true
	for prog in $(PROGS) $(SCRIPTS) ; do \
		$(INSTALL_PROGRAM) $$prog $(DESTDIR)$(bindir) || exit 1; \
	done
	rm -f $(DESTDIR)$(bindir)/rem > /dev/null 2>&1 || true
	ln -s remind $(DESTDIR)$(bindir)/rem
	-mkdir -p $(DESTDIR)$(mandir)/man1 || true
	for man in $(MANS) ; do  \
		$(INSTALL_DATA) $$man $(DESTDIR)$(mandir)/man1 || exit 1; \
	done
	-rm -f $(DESTDIR)$(mandir)/man1/rem.1 || true
	ln -s remind.1 $(DESTDIR)$(mandir)/man1/rem.1
	-mkdir -p $(DESTDIR)$(datarootdir)/remind || true
        # Avoid problems with symlinks under holidays/
	-rm -rf $(DESTDIR)$(datarootdir)/remind/holidays > /dev/null 2>&1 || true
	cp -R ../include/* $(DESTDIR)$(datarootdir)/remind
	chmod -R a+rX $(DESTDIR)$(datarootdir)/remind
	-mkdir -p $(DESTDIR)$(prefix)/share/pixmaps
	-mkdir -p $(DESTDIR)$(prefix)/share/applications
	$(INSTALL_DATA) $(srcdir)/../resources/tkremind.png $(DESTDIR)$(prefix)/share/pixmaps
	$(INSTALL_PROGRAM) $(srcdir)/../resources/tkremind.desktop $(DESTDIR)$(prefix)/share/applications
	-if test "$(DESTDIR)" = ""; then \
	    update-desktop-database < /dev/null > /dev/null 2>&1 ; \
	    xdg-icon-resource install --novendor --size 64 $(DESTDIR)$(prefix)/share/pixmaps/tkremind.png < /dev/null > /dev/null 2>&1 || true; \
	    xdg-desktop-menu install --novendor $(DESTDIR)$(prefix)/share/applications/tkremind.desktop < /dev/null > /dev/null 2>&1 || true; \
	fi

install-stripped: install
	strip $(DESTDIR)$(bindir)/remind || true
	strip $(DESTDIR)$(bindir)/rem2ps || true

clean:
	rm -f *.o *~ core *.bak $(PROGS) $(XLATSRC)

clobber:
	rm -f *.o *~ remind rem2ps test.out core *.bak

depend:
	gccmakedep @DEFS@ $(REMINDSRCS) rem2ps.c json.c

# The next targets are not very useful to you.  I use them to build
# distributions, etc.

cppcheck:
	mkdir -p ../_cppcheck
	cppcheck -j`nproc` -v --force --enable=all --suppress=missingIncludeSystem --suppress=ConfigurationNotChecked --suppress=unmatchedSuppression --suppress=variableScope --inline-suppr --check-level=exhaustive --cppcheck-build-dir=../_cppcheck .
	-rm -rf ../_cppcheck

# Build a tar file based on all files checked into git.
distro:
	cd .. && git archive --worktree-attributes --format=tar --prefix=remind-$(VERSION)/ HEAD > src/remind-$(VERSION).tar
	gzip -f -v -9 remind-$(VERSION).tar
	gpg --detach-sign -u dianne@skoll.ca remind-$(VERSION).tar.gz

beta-tgz:
	cd .. && git archive --worktree-attributes --format=tar --prefix=remind-$(VERSION)-BETA-$(BETA)/ HEAD > src/remind-$(VERSION)-BETA-$(BETA).tar
	gzip -f -v -9 remind-$(VERSION)-BETA-$(BETA).tar
	gpg --detach-sign -u dianne@skoll.ca remind-$(VERSION)-BETA-$(BETA).tar.gz

distro-beta: beta-tgz

#---------------- Stuff after this added by "make depend" -----------------


