
# -*- Makefile -*-
# Mimicking the behavior of a top-level autotool generated Makefile.

 pythonSiteLocator = "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1)"

             tools = bootstrap vlsisapd hurricane crlcore coloquinte etesian knik \
                     katabatic kite equinox solstice cumulus stratus1 unicorn documentation
            prefix = /usr
        rootPrefix = $(subst /usr,,$(prefix))
           DESTDIR =
     BUILD_DESTDIR = $(shell pwd)/install.dir
    PYTHON_SITEDIR = $(shell python -c $(pythonSiteLocator))
     IMPORTEDS_TOP = $(prefix)
      CORIOLIS_TOP = $(prefix)

       environment = IMPORTEDS_TOP=$(IMPORTEDS_TOP); export IMPORTEDS_TOP; \
                      CORIOLIS_TOP=$(CORIOLIS_TOP);  export  CORIOLIS_TOP

.PHONY: build install FORCE


all: build

clean:
	rm -rf build.dir install.dir \
	   crlcore/doc/doxygen/html \
	   hurricane/doc/hurricane/html \
	   hurricane/doc/hurricane/latex \
	   hurricane/doc/viewer/html \
	   hurricane/doc/viewer/latex

build: FORCE
	$(environment); \
	case "`uname -m`" in                                     \
	  "x86_64") cmakeArgs="-D LIB_SUFFIX:STRING=64";;        \
	  *)        cmakeArgs="";;                               \
	esac;                                                    \
	case "$${X_SCLS}" in                                     \
	  *"devtoolset"*)                                        \
         version="`echo $${X_SCLS} | sed 's,devtoolset-,,'`";                \
	     cmakeArgs="$${cmakeArgs} -D Boost_NO_SYSTEM_PATHS:STRING=TRUE";     \
	     BOOST_INCLUDEDIR="/opt/rh/devtoolset-$${version}/root/usr/include"; \
	     BOOST_LIBRARYDIR="/opt/rh/devtoolset-$${version}/root/usr/lib";     \
	     export BOOST_INCLUDEDIR BOOST_LIBRARYDIR;                           \
	     echo "** Using $${X_SCLS}.";                                        \
	     ;;                                                                  \
	esac;                                                    \
	for tool in $(tools); do                                 \
	  echo "** Building tool $${tool}";                      \
	  mkdir -p build.dir/$$tool;                             \
	  cd build.dir/$$tool;                                   \
	  cmake -D CMAKE_BUILD_TYPE:STRING=RELEASE               \
	        -D BUILD_SHARED_LIBS:STRING=ON                   \
	        -D BUILD_DOC:STRING=OFF                          \
	        -D CMAKE_INSTALL_PREFIX:STRING=$(CORIOLIS_TOP)   \
	        -D DESTDIR:STRING=$(BUILD_DESTDIR)               \
	        $${cmakeArgs}                                    \
	        ../../coriolis/$$tool                            \
	        || exit 1;                                       \
	  make DESTDIR=$(BUILD_DESTDIR) $(SMP_MFLAGS) install    \
	        || exit 1;                                       \
	  cd ../..;                                              \
	done

install: FORCE
	$(environment); \
	case "`uname -m`" in                                      \
	  "x86_64") commonCMakeArgs="-D LIB_SUFFIX:STRING=64";;   \
	  *)        commonCMakeArgs="";;                          \
	esac;                                                     \
	for tool in $(tools); do                                  \
	  echo "** Installing tool $${tool}";                     \
	  cd build.dir/$$tool;                                    \
	  makeArgs="";                                            \
	  cmakeArgs="$$commonCMakeArgs -D BUILD_DOC:STRING=OFF";  \
	  if [    "$$tool" = "hurricane"                          \
	       -o "$$tool" = "crlcore"                            \
	       -o "$$tool" = "unicorn"   ]; then                  \
	    cmakeArgs="$$commonCMakeArgs -D BUILD_DOC:STRING=ON"; \
	  fi;                                                     \
	  cmake -D CMAKE_BUILD_TYPE:STRING=RELEASE                \
	        -D BUILD_SHARED_LIBS:STRING=ON                    \
	        -D CMAKE_INSTALL_PREFIX:STRING=${CORIOLIS_TOP}    \
	        -D DESTDIR:STRING=$(DESTDIR)                      \
	        $${cmakeArgs}                                     \
	        ../../coriolis/$$tool                             \
	        || exit 1;                                        \
	  make DESTDIR=$(DESTDIR) -j1 $${makeArgs} install        \
	        || exit 1;                                        \
	  cd ../..;                                               \
	done;                                                     \
	rm -rfv $(DESTDIR)$(rootPrefix)/etc/coriolis2/coriolis2.sh \
	        $(DESTDIR)$(prefix)/bin/ccb                        \
	        $(DESTDIR)$(prefix)/bin/cx2y                       \
	        $(DESTDIR)$(prefix)/bin/*.bin                      \
	        $(DESTDIR)$(rootPrefix)$(PYTHON_SITEDIR)/builder   \
	        $(DESTDIR)$(prefix)/share/cmake/Modules/GetGitRevisionDescription.cmake.in

FORCE:
