prefix = @prefix@
exec_prefix = @exec_prefix@

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

srcdir = @srcdir@
top_builddir = .

LIBTOOL = @LIBTOOL@
INSTALL = @INSTALL@

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 )
	-rm -rf .libs

distclean cleaner:
	( cd fontforge ; $(MAKE) distclean )
	( cd Unicode ; $(MAKE) distclean )
	( cd gdraw ; $(MAKE) distclean )
	-rm -rf .libs
	-rm Makefile config.cache config.log config.status libtool

install_libs: libs
# You may need to be root to do the install
	mkdir -p $(libdir)
	#-rm $(libdir)/libgdraw.so* $(libdir)/libgunicode.so.*
	$(LIBTOOL) --mode=install $(INSTALL) -c libgdraw.la $(libdir)/libgdraw.la
	$(LIBTOOL) --mode=install $(INSTALL) -c libgunicode.la $(libdir)/libgunicode.la
	#cp .libs/*.so.*.* $(libdir)
	$(LIBTOOL) --mode=finish $(libdir)
	mkdir -p $(libdir)/pkgconfig
	$(LIBTOOL) --mode=install $(INSTALL) -c fontforge.pc $(libdir)/pkgconfig

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 htdocs/ja >/dev/null ; then mkdir -p $(docdir)/ja ; fi"
	-cp htdocs/*.{html,png,gif,pdf} $(docdir)
	-cp htdocs/flags/* $(docdir)/flags
	-cp 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)
	$(LIBTOOL) --mode=install $(INSTALL) -c fontforge/fontforge $(bindir)
	-$(LIBTOOL) --mode=install $(INSTALL) -c fontforge/sfddiff $(bindir)
#	-rm -f $(bindir)/pfaedit
#	(cd $(bindir) ; ln -s fontforge pfaedit)
#	cp 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
	-cp $(srcdir)/cidmap/*.cidmap $(sharedir) >/dev/null 2>&1
	cp $(srcdir)/fontforge/fontforge.1 $(mandir)/man1
	-cp $(srcdir)/fontforge/sfddiff.1 $(mandir)/man1
#explicit use of sh to make sure we don't invoke csh with different "if" syntax
	sh -c "if test -d 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 $(libdir)/libgdraw.so*
	-rm $(libdir)/libgunicode.so*
	-rm $(sharedir)/*.cidmap
	-rm -rf $(docdir)/*

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