topsrc = @top_srcdir@

tooldir = $(topsrc)/tools
docdir = $(topsrc)/doc

INSTALL = @INSTALL@
gnome_prefix = @gnome_prefix@
have_gnome = @have_gnome@

sysconfdir = $(gnome_prefix)/etc

GCONFTOOL = @GCONFTOOL@
GCONF_SCHEMA_CONFIG_SOURCE = @GCONF_SCHEMA_CONFIG_SOURCE@
GCONF_SCHEMA_FILE_DIR = @GCONF_SCHEMA_FILE_DIR@

ifeq ($(INSTALL_DATA),)
  INSTALL_DATA = $(INSTALL) -m 644
endif

ifeq ($(have_gnome),2.0)
  install_help = install-help-2
  omfdir = ../gui2/omf-install
  install_schemas = install-gconf-keys install-gconf-schema-file
  schemadir = $(GCONF_SCHEMA_FILE_DIR)
else
  install_help = install-help-1
endif

desktopdir = $(gnome_prefix)/share/applications
mimedir = $(gnome_prefix)/share/mime-info
gpixmaps = $(gnome_prefix)/share/pixmaps
ghelpdir = $(gnome_prefix)/share/gnome/help/gretl
schemadir = $(gnome_prefix)/etc/gconf/schemas

install: install-images install-misc install-help-dirs $(install_help) $(install_schemas)

install-images:
	$(tooldir)/mkinstalldirs $(gpixmaps)
	$(INSTALL_DATA) $(topsrc)/pixmaps/gretl-logo.xpm $(gpixmaps)
	$(INSTALL_DATA) $(topsrc)/gnome/gretl.png $(gpixmaps)
	$(INSTALL_DATA) $(topsrc)/gnome/gnome-*.png $(gpixmaps)

install-misc:
	$(tooldir)/mkinstalldirs $(desktopdir)
	$(INSTALL_DATA) $(topsrc)/gnome/gretl.desktop $(desktopdir)
	$(tooldir)/mkinstalldirs $(mimedir)
	$(INSTALL_DATA) $(topsrc)/gnome/gretl.mime $(mimedir)
	$(INSTALL_DATA) gretl.keys $(mimedir)

install-help-dirs:
	$(tooldir)/mkinstalldirs $(ghelpdir)
	$(tooldir)/mkinstalldirs $(ghelpdir)/C
	$(tooldir)/mkinstalldirs $(ghelpdir)/C/figures
	$(tooldir)/mkinstalldirs $(ghelpdir)/C/chapters
	$(tooldir)/mkinstalldirs $(ghelpdir)/it
	$(tooldir)/mkinstalldirs $(ghelpdir)/it/figures
	$(tooldir)/mkinstalldirs $(ghelpdir)/it/chapters


install-help-2:
	# English help files
	cat $(docdir)/manual.xml | sed s+fileref=\"figures/[^\"]*+\&.png+g \
	  > $(ghelpdir)/C/gretl.xml
	for f in $(docdir)/chapters/*.xml ; do \
	  cat $$f | sed s+fileref=\"figures/[^\"]*+\&.png+g > \
	  $(ghelpdir)/C/chapters/`basename $$f` ; done
	$(INSTALL_DATA) $(docdir)/figures/*.png $(ghelpdir)/C/figures
	# Italian help files
	cat $(docdir)/manual_it.xml | sed s+fileref=\"figures/[^\"]*+\&.png+g \
	  | sed s+chapters_it+chapters+g > $(ghelpdir)/it/gretl.xml
	for f in $(docdir)/chapters_it/*.xml ; do \
	  cat $$f | sed s+fileref=\"figures/[^\"]*+\&.png+g > \
	  $(ghelpdir)/it/chapters/`basename $$f` ; done
	$(INSTALL_DATA) $(docdir)/figures/*.png $(ghelpdir)/it/figures
	$(INSTALL_DATA) $(docdir)/figures_it/*.png $(ghelpdir)/it/figures
	make -C $(omfdir) install

install-help-1:
	-$(INSTALL_DATA) $(topsrc)/gnome/topic.dat $(ghelpdir)/C
	-$(INSTALL_DATA) $(docdir)/manual.html/*.html $(ghelpdir)/C
	-$(INSTALL_DATA) $(docdir)/manual.html/*.css $(ghelpdir)/C
	-$(INSTALL_DATA) $(docdir)/figures/*.png $(ghelpdir)/C/figures
	-$(INSTALL_DATA) $(topsrc)/gnome/topic.dat $(ghelpdir)/it
	-$(INSTALL_DATA) $(docdir)/manual_it.html/*.html $(ghelpdir)/it
	-$(INSTALL_DATA) $(docdir)/manual_it.html/*.css $(ghelpdir)/it
	-$(INSTALL_DATA) $(docdir)/figures/*.png $(ghelpdir)/it/figures
	-$(INSTALL_DATA) $(docdir)/figures_it/*.png $(ghelpdir)/it/figures

install-gconf-keys:
	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
	$(GCONFTOOL) --makefile-install-rule $(topsrc)/gnome/gretl.schemas

install-gconf-schema-file: $(topsrc)/gnome/gretl.schemas	
	$(tooldir)/mkinstalldirs $(schemadir)
	$(INSTALL_DATA) $(topsrc)/gnome/gretl.schemas $(schemadir)


