prefix         = @prefix@
datarootdir    = @datarootdir@
datadir        = $(DESTDIR)@datadir@
mandir         = $(DESTDIR)@mandir@
OPTIONAL_PROGS = @OPTIONAL_PROGS@

# Generated files
GEN1 = man1/dumpkeys.1 man1/loadkeys.1
GEN8 = man8/setfont.8 man8/loadunimap.8 man8/mapscrn.8

MAN1DIRS = man1
MAN5DIRS = man5
MAN8DIRS = man8

ifdef OPTIONAL_PROGS
MAN1DIRS += man1misc
MAN8DIRS += man8misc
endif

all: $(GEN1) $(GEN8)

%: %.in
	sed -e "s|\@datadir\@|$(datadir)|g" <$< >$@

install:
	install -d -m 755 $(mandir)/man1 $(mandir)/man5 $(mandir)/man8; \
	for d in $(MAN1DIRS); do \
		install -m 644 $$d/*.[0-9] $(mandir)/man1/; \
	done; \
	for d in $(MAN5DIRS); do \
		install -m 644 $$d/*.[0-9] $(mandir)/man5/; \
	done; \
	for d in $(MAN8DIRS); do \
		install -m 644 $$d/*.[0-9] $(mandir)/man8/; \
	done

clean:
	rm -f $(GEN1) $(GEN8)

distclean: clean
	rm -f Makefile

# Note: man?misc contains the man pages for non-installed
# programs from ../src. Most of these are tiny test programs,
# not very useful for anybody.
# But if you decide to install some of those, then here are the man pages.
