prefix = @prefix@
exec_prefix = @exec_prefix@

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

srcdir = @srcdir@
top_builddir = .

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

all: fontforge

libs: libgunicode libgdraw

fontforge: libgunicode libgdraw pos
	( cd fontforge ; $(MAKE) )

libgunicode:
	( cd Unicode ; $(MAKE) )

libgdraw:
	( cd gdraw ; $(MAKE) )

pos:
	-ln -s $(srcdir)/po/*.po po
	( cd po ; $(MAKE) )

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

distclean cleaner:
	( cd fontforge ; $(MAKE) distclean )
	( cd Unicode ; $(MAKE) distclean )
	( cd gdraw ; $(MAKE) distclean )
	( cd plugins ; $(MAKE) clean )
	-rm Makefile config.cache config.log config.status libtool fontforge.pc systemspecific

install_libs: libs

install_docs:
	mkdir -p $(docdir)
	mkdir -p $(docdir)/flags $(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 $(docdir)/ja ; fi"
	-$(INSTALL_DATA) $(srcdir)/htdocs/*.{html,png,gif,pdf} $(docdir)
	-$(INSTALL_DATA) $(srcdir)/htdocs/flags/* $(docdir)/flags
	-$(INSTALL_DATA) $(srcdir)/htdocs/ja/* $(docdir)/ja

install_po:
	( cd po ; make install )

install: $(sharedir) all install_libs install_po
# You may need to be root to do the install
	mkdir -p $(bindir)
	mkdir -p $(mandir)/man1
	mkdir -p $(sharedir)
	cp fontforge/fontforge $(bindir)
	cp fontforge/sfddiff $(bindir)
	cp fontforge/fontimage $(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 $(sharedir) >/dev/null 2>&1
	$(INSTALL_DATA) $(srcdir)/fontforge/fontforge.1 $(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/fontforge/sfddiff.1 $(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/fontforge/fontimage.1 $(mandir)/man1
	mkdir -p $(libdir)/pkgconfig
	$(INSTALL_DATA) fontforge.pc $(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 < systemspecific

uninstall:
	-rm $(bindir)/fontforge
	-rm $(bindir)/sfddiff
	-rm $(sharedir)/pfaedit-*.ui
	-rm $(localedir)/*/LC_MESSAGES/FontForge.mo
	-rm $(mandir)/man1/fontforge.1
	-rm $(mandir)/man1/sfddiff.1
	-rm $(sharedir)/*.cidmap
	-rm -rf $(docdir)/*

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