##########################################################################
#                                                                        #
#  This file is part of Aorai plug-in of Frama-C.                        #
#                                                                        #
#  Copyright (C) 2007-2015                                               #
#    CEA (Commissariat à l'énergie atomique et aux énergies              #
#         alternatives)                                                  #
#    INRIA (Institut National de Recherche en Informatique et en         #
#           Automatique)                                                 #
#    INSA  (Institut National des Sciences Appliquees)                   #
#                                                                        #
#  you can redistribute it and/or modify it under the terms of the GNU   #
#  Lesser General Public License as published by the Free Software       #
#  Foundation, version 2.1.                                              #
#                                                                        #
#  It is distributed in the hope that it will be useful,                 #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#  GNU Lesser General Public License for more details.                   #
#                                                                        #
#  See the GNU Lesser General Public License version 2.1                 #
#  for more details (enclosed in the file licenses/LGPLv2.1).            #
#                                                                        #
##########################################################################

# Makefile for compiling Aorai independently of Frama-C.
#
# To be used independently of Frama-C, a version of Frama-C compatible with
# Aorai has to be properly installed as long as the Aorai-specific stuff.

# Do not use ?= to initialize both below variables
# (fixed efficiency issue, see GNU Make manual, Section 8.11)
ifndef FRAMAC_SHARE
FRAMAC_SHARE  :=$(shell frama-c -journal-disable -print-path)
endif
ifndef FRAMAC_LIBDIR
FRAMAC_LIBDIR :=$(shell frama-c -journal-disable -print-libpath)
endif
PLUGIN_DIR ?=.

PLUGIN_ENABLE:=@ENABLE_AORAI@
PLUGIN_DYNAMIC:=@DYNAMIC_AORAI@
PLUGIN_NAME:=Aorai
PLUGIN_GENERATED:= $(addprefix ${PLUGIN_DIR}/, \
		promelalexer_withexps.ml promelaparser_withexps.ml \
		promelaparser_withexps.mli \
		promelalexer.ml promelaparser.ml promelaparser.mli \
		ltllexer.ml ltlparser.ml ltlparser.mli \
		yalexer.ml yaparser.ml yaparser.mli)
PLUGIN_CMO:= bool3 \
	aorai_option \
	path_analysis \
	promelaoutput \
	logic_simplification \
	data_for_aorai \
	aorai_utils \
	ltl_output \
	utils_parser \
	ltlparser \
	ltllexer \
	yaparser \
	yalexer \
	promelaparser \
	promelalexer \
	promelaparser_withexps \
	promelalexer_withexps \
	aorai_dataflow \
	aorai_visitors \
	aorai_register
PLUGIN_CMI:= ltlast promelaast

PLUGIN_DISTRIBUTED:=$(PLUGIN_ENABLE)
PLUGIN_DISTRIB_EXTERNAL:= Makefile.in configure.ac configure
PLUGIN_HAS_EXT_DOC:=no # [JS 2010/07/28] was 'yes'
                       # but prevent 'make src-distrib to work

# if ltltoba is not present, do not attempt to run any test.
ifneq (@HAS_LTLTOBA@,yes)
PLUGIN_NO_TEST:=yes
PLUGIN_NO_DEFAULT_TEST:=yes
endif

PLUGIN_TESTS_DIRS:=aorai

include $(FRAMAC_SHARE)/Makefile.dynamic

# Regenerating the Makefile on need

ifeq ("$(FRAMAC_INTERNAL)","yes")
CONFIG_STATUS_DIR=$(FRAMAC_SRC)
else
CONFIG_STATUS_DIR=.
endif

$(Aorai_DIR)/Makefile: $(Aorai_DIR)/Makefile.in \
			$(CONFIG_STATUS_DIR)/config.status
	cd $(CONFIG_STATUS_DIR) && ./config.status --file $@

headers::
	$(SED) $(FRAMAC_SRC)/headers/INSA_INRIA_LGPL \
	       -e 's/This file is/Files in this archive are/' \
	       > $(FRAMAC_SRC)/doc/aorai/example/LICENSE

LOCAL_SRC_DIR=aorai
COMMON_FILES_TO_COPY=$(PLUGIN_DISTRIB_EXTERNAL) Makefile.in YA.README INSTALL VERSIONS.txt
FRAMAC_SRC_ROOT=../../..
LOCAL_WEB_ROOT=/home/nstouls/Projets/AMAZONES/ForgeINRIA/main/aorai/
LOCAL_WEB_DIFFUSION=$(LOCAL_WEB_ROOT)/site/src/site/resources
TODAY=`date  +"%d-%m-%Y - %T"`
TAGIN=<\!--START DATE-->
TAGOUT=<\!--END DATE-->
INDEX=$(LOCAL_WEB_DIFFUSION)/index.html

pre-release:
	mkdir -p $(LOCAL_SRC_DIR)/doc

	@echo '## Generating bin and doc'
	@make -C $(FRAMAC_SRC_ROOT) depend --quiet
	@make -C $(FRAMAC_SRC_ROOT) --quiet
	@make -C $(FRAMAC_SRC_ROOT) $(PLUGIN_NAME)_DOC --quiet
	cp -r $(FRAMAC_SRC_ROOT)/doc/code/aorai $(LOCAL_SRC_DIR)/doc/.
	cp  $(FRAMAC_SRC_ROOT)/doc/code/frama-c.png $(LOCAL_SRC_DIR)/doc/.
	cp  $(FRAMAC_SRC_ROOT)/doc/code/style.css $(LOCAL_SRC_DIR)/doc/.

	@make -C $(FRAMAC_SRC_ROOT)/doc/aorai/  --quiet
	@make -C $(FRAMAC_SRC_ROOT)/doc/aorai/ install  --quiet
	cp  $(FRAMAC_SRC_ROOT)/doc/manuals/aorai-manual.pdf $(LOCAL_SRC_DIR)/doc/.
	cp  $(FRAMAC_SRC_ROOT)/doc/manuals/aorai-example.tgz $(LOCAL_SRC_DIR)/doc/.

	@echo '## Deployment for local release'
	@make clean --quiet
# SRC directory generation
	if [ -d autom4te.cache ] ; then rm -rf  autom4te.cache ; fi
	cp *.* $(LOCAL_SRC_DIR)

# Commun files copy
	for f in $(COMMON_FILES_TO_COPY) ; do \
		cp $$f $(LOCAL_SRC_DIR)/. ; \
	done

	@echo "## Generating archive"
	tar -czf $(LOCAL_SRC_DIR).tgz $(LOCAL_SRC_DIR)
	@echo "## Done."
	@echo "## Please make 'pre-release-deploy' to move archive to $(LOCAL_WEB_DIFFUSION)"

pre-release-deploy: $(LOCAL_SRC_DIR).tgz
	@echo "## Moving archive to $(LOCAL_WEB_DIFFUSION)"
	mv $(LOCAL_SRC_DIR).tgz $(LOCAL_WEB_DIFFUSION)
	cat $(INDEX) | sed "s/$(TAGIN).*$(TAGOUT)/$(TAGIN)$(TODAY)$(TAGOUT)/" $(INDEX) > $(INDEX)2
	mv $(INDEX)2 $(INDEX)
	@echo "## Website updated"
	cd $(LOCAL_WEB_ROOT) && ./CreateHTML.sh

clean-all:
	@make clean
	@echo '## Removing generated directories'
	@rm -rf $(LOCAL_SRC_DIR)
