prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
libdir = @libdir@
mandir = @mandir@
includedir = @includedir@
sharedir = $(prefix)/share/fontforge
pixmapsdir = $(sharedir)/pixmaps
docdir = $(prefix)/share/doc/fontforge
pythondir = $(sharedir)/python

srcdir = @srcdir@
top_builddir = .

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

all: fontforge

libs: libgunicode @GDRAW_LIB@

fontforge: libgunicode libgutils @GDRAW_LIB@ pos
	( cd fontforge ; $(MAKE) )

libgunicode:
	( cd Unicode ; $(MAKE) )

libgutils: libgunicode
	( cd gutils ; $(MAKE) )

libgdraw: libgutils libgunicode
	( cd gdraw ; $(MAKE) )

pos:
	( cd po ; $(MAKE) )

clean:
	( cd fontforge ; $(MAKE) clean )
	( cd Unicode ; $(MAKE) clean )
	( cd gutils ; $(MAKE) clean )
	( cd gdraw ; $(MAKE) clean )

distclean cleaner:
	( cd fontforge ; $(MAKE) distclean )
	( cd Unicode ; $(MAKE) distclean )
	( cd gutils ; $(MAKE) distclean )
	( cd gdraw ; $(MAKE) distclean )
	-rm Makefile config.cache config.log config.status libtool fontforge.pc systemspecific inc/config.h

install_libs: libs

install_docs:
	mkdir -p $(DESTDIR)$(docdir)
	mkdir -p $(DESTDIR)$(docdir)/flags $(DESTDIR)$(docdir)/ja
#explicit use of sh to make sure we don't invoke csh with different "if" syntax
	-sh -c "if test -d $(srcdir)/htdocs/ja >/dev/null ; then mkdir -p $(DESTDIR)$(docdir)/ja ; fi"
	-$(INSTALL_DATA) $(srcdir)/htdocs/*.{html,png,gif,pdf} $(DESTDIR)$(docdir)
	-$(INSTALL_DATA) $(srcdir)/htdocs/flags/* $(DESTDIR)$(docdir)/flags
	-$(INSTALL_DATA) $(srcdir)/htdocs/ja/* $(DESTDIR)$(docdir)/ja

install_po:
	( cd po ; $(MAKE) install )

install_pycontrib:
	mkdir -p $(DESTDIR)$(pythondir)
	( cd pycontrib ; $(INSTALL_DATA) *.py $(DESTDIR)$(pythondir) )

install: $(sharedir) all install_libs install_po install_pycontrib
# You may need to be root to do the install
	mkdir -p $(DESTDIR)$(bindir)
	mkdir -p $(DESTDIR)$(mandir)/man1
	mkdir -p $(DESTDIR)$(sharedir)
	mkdir -p $(DESTDIR)$(pixmapsdir)
	cp fontforge/fontforge $(DESTDIR)$(bindir)
	cp fontforge/sfddiff $(DESTDIR)$(bindir)
	cp fontforge/fontimage $(DESTDIR)$(bindir)
	cp fontforge/fontlint $(DESTDIR)$(bindir)
#	$(INSTALL_DATA) fontforge/pfaedit-*.ui $(sharedir)
#The next line will fail for most installs. If you have downloaded the cidmaps
# this will install them. If you haven't it won't. You only need the cidmaps
# if you are editing CID keyed files (and even then you can live without them
	-$(INSTALL_DATA) $(srcdir)/cidmap/*.cidmap $(DESTDIR)$(sharedir) >/dev/null 2>&1
	-$(INSTALL_DATA) $(srcdir)/fontforge/pixmaps/*.png $(DESTDIR)$(pixmapsdir)
	$(INSTALL_DATA) $(srcdir)/fontforge/fontforge.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/fontforge/sfddiff.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/fontforge/fontimage.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/fontforge/fontlint.1 $(DESTDIR)$(mandir)/man1
	mkdir -p $(DESTDIR)$(libdir)/pkgconfig
	$(INSTALL_DATA) fontforge.pc $(DESTDIR)$(libdir)/pkgconfig
#explicit use of sh to make sure we don't invoke csh with different "if" syntax
	sh -c "if test -d $(srcdir)/htdocs >/dev/null ; then $(MAKE) install_docs ; fi"
	sh -c "if test -d fontforge/FontForge.app >/dev/null ; then rm -rf /Applications/FontForge.app ; mv fontforge/FontForge.app /Applications ; ln -s /usr/local/bin/fontforge /Applications/FontForge.app/Contents/MacOS/FontForge ; fi"
	sh < systemspecific

uninstall:
	-rm $(DESTDIR)$(bindir)/fontforge
	-rm $(DESTDIR)$(bindir)/sfddiff
	-rm $(DESTDIR)$(bindir)/fontimage
	-rm $(DESTDIR)$(bindir)/fontlint
	-rm $(DESTDIR)$(sharedir)/pfaedit-*.ui
	-rm $(DESTDIR)$(localedir)/*/LC_MESSAGES/FontForge.mo
	-rm $(DESTDIR)$(mandir)/man1/fontforge.1
	-rm $(DESTDIR)$(mandir)/man1/fontimage.1
	-rm $(DESTDIR)$(mandir)/man1/sfddiff.1
	-rm $(DESTDIR)$(mandir)/man1/fontlint.1
	-rm $(DESTDIR)$(sharedir)/*.cidmap
	-rm -rf $(DESTDIR)$(docdir)/*
	-rm $(DESTDIR)$(libdir)/pkgconfig/fontforge.pc
	-rm $(DESTDIR)$(pythondir)/*

$(DESTDIR)$(sharedir):
	mkdir -p $(DESTDIR)$(sharedir)
