--- /dev/null
+#!/bin/bash -noprofile
+
+####################################################################################
+# File : freeimage.sh
+# Created : Thu Dec 18 12:01:00 2002
+# Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
+# Project : SALOME
+# Module : Installation Wizard
+# Copyright : 2002-2014 CEA
+#
+# This script is the part of the SALOME installation procedure.
+#
+####################################################################################
+
+#
+# freeimage version
+#
+VERSION_FREEIMAGE=3.15.4
+
+check_version()
+{
+# check existance of freeimage and its version
+if [ "${FREEIMAGE_ROOT_DIR}" != "" ] && [ -f ${FREEIMAGE_ROOT_DIR}/include/FreeImage.h ] ; then
+ ver_major=`grep "#define FREEIMAGE_MAJOR_VERSION" ${FREEIMAGE_ROOT_DIR}/include/FreeImage.h | awk '{print $3}'`
+ ver_minor=`grep "#define FREEIMAGE_MINOR_VERSION" ${FREEIMAGE_ROOT_DIR}/include/FreeImage.h | awk '{print $3}'`
+ ver_maint=`grep "#define FREEIMAGE_RELEASE_SERIAL" ${FREEIMAGE_ROOT_DIR}/include/FreeImage.h | awk '{print $3}'`
+ ver="${ver_major}.${ver_minor}.${ver_maint}"
+ if [ "${ver}" = "${VERSION_FREEIMAGE}" ] ; then
+ return 0
+ fi
+fi
+return 1
+}
+
+print_env_bin()
+{
+cat > ${INSTALL_WORK}/env_${PRODUCT_TYPE}.sh <<EOF
+#${DELIM} ${PRODUCT_TYPE} ${DELIM}
+export FREEIMAGE_ROOT_DIR=\${INST_ROOT}/${SINGLE_DIR:-${PRODUCT}}
+export PATH=\${FREEIMAGE_ROOT_DIR}/bin:\${PATH}
+export LD_LIBRARY_PATH=\${FREEIMAGE_ROOT_DIR}/lib:\${LD_LIBRARY_PATH}
+##
+EOF
+(test -w ${PRODUCT_DIR} && cp ${INSTALL_WORK}/env_${PRODUCT_TYPE}.sh ${PRODUCT_DIR})
+make_env ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}"
+}
+
+print_env_src()
+{
+cat > ${INSTALL_WORK}/env_${PRODUCT_TYPE}_src.sh <<EOF
+#${DELIM} ${PRODUCT_TYPE}_src ${DELIM}
+# nothing to do
+##
+EOF
+(test -w ${PRODUCT_SRC_DIR} && cp ${INSTALL_WORK}/env_${PRODUCT_TYPE}_src.sh ${PRODUCT_SRC_DIR})
+make_env ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}"
+}
+
+try_preinstalled(){
+try_existing ${PRODUCT_DIR} ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}" ${PRODUCT_TYPE}
+try_existing ${PRODUCT_SRC_DIR} ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}" ${PRODUCT_TYPE}_src
+return $?
+}
+
+install_source()
+{
+make_env ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}" ${PRODUCT_TYPE}_src
+source ${INSTALL_WORK}/${SHRC}
+
+# unpack
+check_jb tar xfz ${SOURCE_DIR}/${PRODUCT}.tar.gz -C ${INST_ROOT}
+
+# patch sources
+
+# [-] patch for build procedure
+local patch_build_procedure=1
+# [-] patch for gcc 4.7 compatibility
+local patch_gcc47_compat=1
+
+if [ "${patch_build_procedure}" = "1" ] ; then
+ sed -i "s%DESTDIR ?= /%DESTDIR ?= /usr%g;s%INCDIR ?= \$(DESTDIR)/usr/include%INCDIR ?= \$(DESTDIR)/include%g;s%INSTALLDIR ?= \$(DESTDIR)/usr/lib%INSTALLDIR ?= \$(DESTDIR)/lib%g;s%-o root -g root %%g" ${PRODUCT_SRC_DIR}/Makefile.gnu
+ sed -i "s%DESTDIR ?= /%DESTDIR ?= /usr%g;s%INCDIR ?= \$(DESTDIR)/usr/include%INCDIR ?= \$(DESTDIR)/include%g;s%INSTALLDIR ?= \$(DESTDIR)/usr/lib%INSTALLDIR ?= \$(DESTDIR)/lib%g;s%-o root -g root %%g" ${PRODUCT_SRC_DIR}/Makefile.fip
+ sed -i "s%\(^[[:space:]]*\)\(install -m 755 \$(SHAREDLIB) \$(INSTALLDIR)\)%\1\2\n\1ln -sf \$(SHAREDLIB) \$(INSTALLDIR)/\$(VERLIBNAME)\n\1ln -sf \$(VERLIBNAME) \$(INSTALLDIR)/\$(LIBNAME)%g" ${PRODUCT_SRC_DIR}/Makefile.fip
+fi
+
+if [ "${patch_gcc47_compat}" = "1" ] ; then
+ sed -i 's%\(#include "OpenEXRConfig.h"\)%\1\n#include <string.h>%g' ${PRODUCT_SRC_DIR}/Source/OpenEXR/IlmImf/ImfAutoArray.h
+fi
+
+if [ "${SALOME_IW_COMPSIZE}" = "1" ] ; then
+ du -sk ${PRODUCT_SRC_DIR} > ${INST_ROOT}/${PRODUCT_TYPE}.src.size
+fi
+
+# to generate environment scripts
+try_preinstalled
+}
+
+install_source_and_build()
+{
+# install sources
+install_source
+
+# build sources
+test -z ${SINGLE_DIR} && makedir ${PRODUCT_DIR} || mkdir -p ${PRODUCT_DIR}
+
+cd ${PRODUCT_SRC_DIR}
+
+## building FreeImage library
+
+# workaround for CentOS 5.5: FreeImage 3.16.0 is not compiled with gcc 4.2 and older :(
+local workaround_gcc42_pb=1
+gcc_found=""
+if [ "${workaround_gcc42_pb}" = "1" ] ; then
+ gcc_found="`use_latest_gcc 040200`"
+fi
+
+# compile
+check_job ${PRODUCT_DIR}/MAKE.LOG make ${gcc_found} -f Makefile.gnu
+
+# install
+check_job ${PRODUCT_DIR}/INSTALL.LOG make ${gcc_found} -f Makefile.gnu DESTDIR=${PRODUCT_DIR} install
+
+# clean temporary files
+###make -f Makefile.gnu clean
+
+## building FreeImagePlus library
+
+# compile
+check_job ${PRODUCT_DIR}/MAKEPLUS.LOG make ${gcc_found} -f Makefile.fip
+
+# install
+check_job ${PRODUCT_DIR}/INSTALLPLUS.LOG make ${gcc_found} -f Makefile.fip DESTDIR=${PRODUCT_DIR} install
+
+# clean temporary files
+###make -f Makefile.fip clean
+
+cd ${PRODUCT_DIR}
+
+if [ "${SALOME_IW_COMPSIZE}" = "1" ] ; then
+ du -sk ${PRODUCT_SRC_DIR} > ${INST_ROOT}/${PRODUCT_TYPE}.build.size
+ du -sk ${PRODUCT_DIR} > ${INST_ROOT}/${PRODUCT_TYPE}.bin.size
+fi
+
+# remove sources and temporary files after building
+if [ ${REMOVE_SRC_TMP} = "TRUE" ] ; then
+ test -d ${PRODUCT_SRC_DIR} && rm -fr ${PRODUCT_SRC_DIR}
+fi
+
+# to generate environment scripts
+try_preinstalled
+}
+
+install_binary()
+{
+make_env ${INST_ROOT} ${INSTALL_WORK} "${PRODUCT_SEQUENCE}" "${INSTALL_PRODUCTS}" ${PRODUCT_TYPE}
+source ${INSTALL_WORK}/${SHRC}
+
+# create a product directory
+test -z ${SINGLE_DIR} && makedir ${PRODUCT_DIR} || mkdir -p ${PRODUCT_DIR}
+
+check_jb tar xfz ${SOURCE_DIR}/${PRODUCT}.tar.gz -C ${PRODUCT_DIR}
+
+# to generate environment script for sources
+try_preinstalled
+}
+
+export PROCEDURE=$1;
+export INSTALL_WORK=$2;
+export SOURCE_DIR=$3;
+export INST_ROOT=$4;
+export PRODUCT_SEQUENCE=$5;
+export PRODUCT_TYPE=$6;
+export INSTALL_PRODUCTS=$7;
+shift
+REMOVE_SRC_TMP=$8;
+test $# = 10 && shift && SINGLE_DIR=$9
+export PRODUCT="freeimage-${VERSION_FREEIMAGE}"
+export PRODUCT_DIR=${INST_ROOT}/${SINGLE_DIR:-${PRODUCT}}
+export PRODUCT_WORK=${INSTALL_WORK}/${PRODUCT}
+export PRODUCT_SRC_DIR=${INST_ROOT}/${PRODUCT}_SRC
+source ./common.sh
+${PROCEDURE}