topsrc = @top_srcdir@

prefix = @prefix@
have_gtk = @have_gtk@

gretldir = $(prefix)/share/gretl
tooldir = $(topsrc)/tools
sharesrc = $(topsrc)/share

INSTALL_DATA = cp -fp

AUTO_HELPFILES = \
	$(sharesrc)/gretl.hlp \
	$(sharesrc)/gretlcli.hlp \
	$(sharesrc)/gretl.hlp.es \
	$(sharesrc)/gretlcli.hlp.es \
	$(sharesrc)/gretl.hlp.it \
	$(sharesrc)/gretlcli.hlp.it 

AUTO_HELP_SRCS = $(topsrc)/doc/commands/gretl_commands.xml \
	$(topsrc)/doc/commands/gretl_commands_es.xml \
	$(topsrc)/doc/commands/gretl_commands_it.xml 

AUTO_HELP_STY = $(topsrc)/doc/commands/gretltxt.xsl

AUTO_HELP_STRS = $(topsrc)/doc/commands/hlpstrings.txt

ifeq ($(have_gtk),2.0)
   ES_GUI_HLP = $(sharesrc)/gretl.hlp.es.utf8
   ES_CLI_HLP = $(sharesrc)/gretlcli.hlp.es.utf8
   IT_GUI_HLP = $(sharesrc)/gretl.hlp.it.utf8
   IT_CLI_HLP = $(sharesrc)/gretlcli.hlp.it.utf8
   RECODE_FILES = $(ES_GUI_HLP) $(ES_CLI_HLP) $(IT_GUI_HLP) $(IT_CLI_HLP)
else
   ES_GUI_HLP = $(sharesrc)/gretl.hlp.es
   ES_CLI_HLP = $(sharesrc)/gretlcli.hlp.es
   IT_GUI_HLP = $(sharesrc)/gretl.hlp.it
   IT_CLI_HLP = $(sharesrc)/gretlcli.hlp.it
endif

VPATH = $(sharesrc)

.PHONY :

all: $(AUTO_HELPFILES) $(RECODE_FILES)

install: installdirs install_datafiles install_scripts install_help
	$(INSTALL_DATA) $(sharesrc)/gretl.stamp $(gretldir)/gretl.stamp
	make -C bcih install

install-strip: install

install_datafiles:
	for f in $(sharesrc)/data/*.gdt ; do \
	$(INSTALL_DATA) $$f $(gretldir)/data ; done
	$(INSTALL_DATA) $(sharesrc)/data/descriptions $(gretldir)/data 
	$(INSTALL_DATA) $(sharesrc)/data/gretldata.dtd $(gretldir)/data 
	for f in $(sharesrc)/data/greene/* ; do \
	$(INSTALL_DATA) $$f $(gretldir)/data/greene ; done
	for f in $(sharesrc)/data/misc/* ; do \
	$(INSTALL_DATA) $$f $(gretldir)/data/misc ; done
	for f in $(topsrc)/tests/*.dat ; do \
	$(INSTALL_DATA) $$f $(gretldir)/data/nist ; done

install_scripts:
	for f in $(sharesrc)/scripts/* ; do \
	$(INSTALL_DATA) $$f $(gretldir)/scripts ; done
	for f in $(sharesrc)/scripts/misc/* ; do \
	$(INSTALL_DATA) $$f $(gretldir)/scripts/misc ; done

install_man: gretl.1
	$(tooldir)/mkinstalldirs $(prefix)/share/man/man1
	$(INSTALL_DATA) $(topsrc)/gretl.1 $(prefix)/share/man/man1

install_help: $(AUTO_HELPFILES) $(RECODE_FILES)
	$(tooldir)/mkinstalldirs $(gretldir)
	$(INSTALL_DATA) $(sharesrc)/gretl.hlp $(gretldir)/gretl.hlp
	$(INSTALL_DATA) $(sharesrc)/gretlcli.hlp $(gretldir)/gretlcli.hlp
	$(INSTALL_DATA) $(ES_GUI_HLP) $(gretldir)/gretl.hlp.es
	$(INSTALL_DATA) $(ES_CLI_HLP) $(gretldir)/gretlcli.hlp.es
	$(INSTALL_DATA) $(IT_GUI_HLP) $(gretldir)/gretl.hlp.it
	$(INSTALL_DATA) $(IT_CLI_HLP) $(gretldir)/gretlcli.hlp.it

installdirs:
	$(tooldir)/mkinstalldirs $(gretldir) $(gretldir)/data 
	$(tooldir)/mkinstalldirs $(gretldir)/data/greene
	$(tooldir)/mkinstalldirs $(gretldir)/data/misc
	$(tooldir)/mkinstalldirs $(gretldir)/data/nist
	$(tooldir)/mkinstalldirs $(gretldir)/scripts
	$(tooldir)/mkinstalldirs $(gretldir)/scripts/misc 
	$(tooldir)/mkinstalldirs $(gretldir)/db

$(AUTO_HELPFILES): $(AUTO_HELP_SRCS) $(AUTO_HELP_STY) $(AUTO_HELP_STRS)
	make -C ../doc/commands hlp

$(RECODE_FILES): $(sharesrc)/gretl.hlp.es $(sharesrc)/gretlcli.hlp.es \
	$(sharesrc)/gretl.hlp.it $(sharesrc)/gretlcli.hlp.it
	for f in $^ ; do recode l1..utf-8 < $$f > $$f.utf8 ; done

clean:
	make -C bcih clean

textclean: 
	rm -f *.txt *.utf8

distclean: clean
	rm -f Makefile
	make -C bcih distclean
