.PHONY: all install clean distclean

INSTALL=install
BINDIR=/usr/local/bin
T_FJMODULE=1
T_FJMODULE_REMOTE=http://omni-compiler.org/T_FJModule/20170523
T_FJMODULE_LOCAL=T_FJModule

SUBDIRS=C-FrontEnd/src F-FrontEnd/src XcodeML-Common libxmpf/include C-BackEnd F-BackEnd Driver/bin

FALSE=1
TRUE=0
NEED_MAKE_MOD2XMOD=1
ifeq ($(NEED_MAKE_MOD2XMOD), $(TRUE))
    SUBDIRS+=F-FrontEnd/gnu_module
endif

IS_ATOOL=1
ifeq ($(IS_ATOOL), $(TRUE))
    SUBDIRS+=Driver/atool
endif

all:
	@for subdir in $(SUBDIRS) ; do \
	  $(MAKE) -C $$subdir ; \
	  if test $$? -ne 0; then exit 1; fi ; \
	done

install:
	@for subdir in $(SUBDIRS) ; do \
	  $(MAKE) -C $$subdir install ; \
	  if test $$? -ne 0; then exit 1; fi ; \
	done; \
	if test $(T_FJMODULE) -eq $(TRUE); then \
	  wget $(T_FJMODULE_REMOTE) -O $(DESTDIR)$(BINDIR)/$(T_FJMODULE_LOCAL) || \
	  echo "Please download $(T_FJMODULE_REMOTE) and copy it at $(DESTDIR)$(BINDIR)/$(T_FJMODULE_LOCAL)"; \
	  chmod +x $(DESTDIR)$(BINDIR)/$(T_FJMODULE_LOCAL); \
	fi

clean:
	@for subdir in $(SUBDIRS) ; do \
	  $(MAKE) -C $$subdir clean ; \
	  if test $$? -ne 0; then exit 1; fi; \
	done

distclean: clean
	rm -rf autom4te.cache config.log config.status
