topsrc = @top_srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
CC = @CC@
CFLAGS = @CFLAGS@
MAKE = @MAKE@
INSTALL = @INSTALL@
LN = @LN_S@
have_gtk = @have_gtk@

ifeq ($(CC),)
  CC = gcc
endif

ifeq ($(have_gtk),2.0)
  GUIDIR = gui2
else
  ifeq ($(have_gtk),1.2)
    GUIDIR = gui
  endif
endif

INSTALL_PROGRAM = ${INSTALL} -m 755
INSTALL_DATA = ${INSTALL} -m 644

export

tooldir = $(topsrc)/tools

SUBDIRS = lib cli $(GUIDIR) plugin po
ALLSUBDIRS = lib cli gui gui2 plugin po share tests

.PHONY : subdirs $(SUBDIRS) clean installdirs install install-strip \
install-man tags dist distclean check

subdirs: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $@

clean:
	for d in $(ALLSUBDIRS) ; do $(MAKE) -C $$d clean; done

installdirs:
	$(tooldir)/mkinstalldirs $(libdir) $(includedir) $(bindir)

install: $(SUBDIRS) installdirs install-man
	for d in $(SUBDIRS) ; do $(MAKE) -C $$d install; done
	$(MAKE) -C share install

install-strip: $(SUBDIRS) installdirs install-man	
	for d in $(SUBDIRS) ; do $(MAKE) -C $$d install-strip; done
	$(MAKE) -C share install-strip

install-man:
	$(tooldir)/install_man $(tooldir) $(prefix) $(topsrc)/gretl.1 
	$(tooldir)/install_man $(tooldir) $(prefix) $(topsrc)/gretl-config.1

tags:
	etags $(topsrc)/lib/src/*.[ch] $(topsrc)/cli/*.[ch] \
	$(topsrc)/$(GUIDIR)/*.[ch] $(topsrc)/plugin/*.[ch]

dist: 
	$(tooldir)/makedist

distclean: clean
	make -C win32 clean
	rm -f config.log config.cache config.status config.h gretl.pc
	rm -f gretl_sh gretl-config libtool Makefile
	for d in $(ALLSUBDIRS) ; do $(MAKE) -C $$d distclean; done

check:
	make -C tests check

# dependency for parallel builds
cli: lib
$(GUIDIR): lib
plugin: lib
tests: lib






