###############################################################################################################################################################################################################################################################################
####
####
#### samj 20130905
####
#### Ce fichier est  utiliser avec :
####     C:\petit-msys-mingw-gimp28 - Tlchargement de l'environnement de compilation pour Windows 64 bits :     http://www.aljacom.com/~gmic/petit-msys-mingw-gimp28.7z
####     http://sourceforge.net/projects/gmic/files/beta/gmic_1.5.7.0_beta.tar.gz/download
#### Faire une double dcompression de   gmic_1.5.7.0_beta.tar.gz   dans  C:\petit-msys-mingw-gimp28
#### Remplacer le fichier existant  C:\petit-msys-mingw-gimp28\gmic-1.5.7.0\src\Makefile    par ce fichier.
#### Ouvrir le terminal MSYS en cliquant sur   C:\petit-msys-mingw-gimp28\start_MSYS.bat
#### Dans le terminal MSYS taper au clavier les lignes suivantes (appuyer sur la touche "Entre"  la fin de chaque ligne).
####          cd /env/gmic-1.5.7.0/src
####          make gimp
####
#### Attendre que la compilation se termine (taper   exit   dans le terminal MSYS)
####
####
#### Remarques :
####          make           cration de GMIC et du plugin pour Gimp (temps de compilation trs trs long)
####          make gimp      cration du plugin pour Gimp (temps de compilation long)
####          make windows   cration de GMIC (temps de compilation trs long)
####          Si vous utilisez GMIC, installer 	gmic.exe   dans  C:\petit-msys-mingw-gimp28\base\c\bin   et copier  C:\petit-msys-mingw-gimp28\base\c\Preferences\plug-ins\_gmic\curl.exe   dans  C:\petit-msys-mingw-gimp28\base\c\bin
####          Diffusion des compilations : Utiliser les DLL situes dans C:\petit-msys-mingw-gimp28\base\c\bin  . Ne pas oublier   curl.exe   et son sous-rpertoire  _gmic
####
####
####
###############################################################################################################################################################################################################################################################################


###############################################################################################################################################################################################################################################################################
####
####
#### samj 20130905
####
#### English translation
####
#### This "Makefile" file is for use with :
####     C:\petit-msys-mingw-gimp28 - Download the compilation environment for 64-bit Windows from :     http://www.aljacom.com/~gmic/petit-msys-mingw-gimp28.7z
####     http://sourceforge.net/projects/gmic/files/beta/gmic_1.5.7.0_beta.tar.gz/download
#### Do a double decompressing archive "gmic_1.5.7.0_beta.tar.gz" in the directory "C:\petit-msys-mingw-gimp28"
#### Replace the existing file "C:\petit-msys-mingw-gimp28\gmic-1.5.7.0\src\Makefile" by this file.
#### Open the MSYS terminal by clicking   C:\petit-msys-mingw-gimp28\start_MSYS.bat
#### In the MSYS terminal typing the following lines. Press the "Enter" key at the end of each line.
####          cd /env/gmic-1.5.7.0/src
####          make gimp
####
#### Wait until the compilation ends (Type   exit    in the MSYS terminal)
####
####
#### Notes :
####          make           creation of GMIC and plugin for Gimp (very very long time compilation)
####          make gimp      creation plugin for Gimp (long time compilation)
####          make windows   creation of GMIC (compilation time very long)
####          If you use GMIC, install 	gmic.exe   in  C:\petit-msys-mingw-gimp28\base\c\bin   and copy  C:\petit-msys-mingw-gimp28\base\c\Preferences\plug-ins\_gmic\curl.exe   in  C:\petit-msys-mingw-gimp28\base\c\bin
####          Distribution compilations : Use DLL located in   C:\petit-msys-mingw-gimp28\base\c\bin   . Do not forget "curl.exe" and its subdirectory "_gmic".
####
####
####
###############################################################################################################################################################################################################################################################################


#
#  File        : Makefile
#                ( Makefile for GNU 'make' utility )
#
#  Description : Makefile for compiling :
#
#                 . the G'MIC command line tool (type 'make windows').
#                 . the G'MIC plug-in for GIMP (type 'make gimp').
#
#                ( http://gmic.sourceforge.net )
#
#  Copyright   : David Tschumperle
#                ( http://tschumperle.users.greyc.fr/ )
#
#  License     : CeCILL v2.0
#                ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
#
#  This software is governed by the CeCILL  license under French law and
#  abiding by the rules of distribution of free software.  You can  use,
#  modify and/ or redistribute the software under the terms of the CeCILL
#  license as circulated by CEA, CNRS and INRIA at the following URL
#  "http://www.cecill.info".
#
#  As a counterpart to the access to the source code and  rights to copy,
#  modify and redistribute granted by the license, users are provided only
#  with a limited warranty  and the software's author,  the holder of the
#  economic rights,  and the successive licensors  have only  limited
#  liability.
#
#  In this respect, the user's attention is drawn to the risks associated
#  with loading,  using,  modifying and/or developing or reproducing the
#  software by the user in light of its specific status of free software,
#  that may mean  that it is complicated to manipulate,  and  that  also
#  therefore means  that it is reserved for developers  and  experienced
#  professionals having in-depth computer knowledge. Users are therefore
#  encouraged to load and test the software's suitability as regards their
#  requirements in conditions enabling the security of their systems and/or
#  data to be ensured and,  more generally, to use and operate it in the
#  same conditions as regards security.
#
#  The fact that you are presently reading this means that you have had
#  knowledge of the CeCILL license and that you accept its terms.
#

#----------------------------------
# Set correct variables and paths.
#----------------------------------


CC = /mingw/bin/i686-w64-mingw32-c++.exe
USR = /mingw
EXE = .exe
IS_GCC = yes



#------------------------------------------------
# Set compilation flags for build customization.
#------------------------------------------------

# Flags to enable 'beta' version.
IS_BETA_CFLAGS = -Dcimg_use_vt100 -Dgmic_is_beta=1

# Flags that are mandatory to compile 'gmic'.
MANDATORY_CFLAGS += -Dgmic_build -I$(USR)/include -I/mingw/i686-w64-mingw32/include -pipe -O3 -mms-bitfields -s -march=i686
MANDATORY_LDFLAGS += -L$(USR)/lib -L/mingw/i686-w64-mingw32/lib -lpthread
ifeq ($(IS_GCC),yes)
MANDATORY_CFLAGS += -Wall -W
MANDATORY_LDFLAGS += -lm
endif
MANDATORY_CFLAGS+=$(IS_BETA_CFLAGS)

# Flags to enable debugging.
DEBUG_CFLAGS = -Dcimg_use_vt100 -Dcimg_verbosity=3 -g

# Flags to enable optimizations.
ifeq ($(IS_GCC),yes)
OPT_CFLAGS = -O3 -mtune=generic # -fno-tree-pre # -ffast-math
endif
ifeq ($(CC),icc)
OPT_CFLAGS = -O3 -ipo -no-prec-div -override-limits
endif

# Flags to enable parallel processing.
PARALLEL_CFLAGS = -Dgmic_is_parallel



# Flags to enable image display, using GDI32.
# This requires the presence of the GDI32 include and library files.
GDI32_CFLAGS = -Dcimg_display=2 -Dcimg_appname=\\\"gmic\\\"
GDI32_LDFLAGS = -lgdi32

# Flags to enable native support for PNG image files, using the PNG library.
# This requires the presence of the libpng include and library files.
# (package 'libpng12-dev' on Debian).
PNG_CFLAGS = -Dcimg_use_png
PNG_LDFLAGS = -lpng15 -lz

# Flags to enable native support for JPEG image files, using the JPEG library.
# This requires the presence of the libjpeg include and library files.
# (package 'libjpeg62-dev' on Debian).
JPEG_CFLAGS = -Dcimg_use_jpeg
JPEG_LDFLAGS = -ljpeg

# Flags to enable native support for TIFF image files, using the TIFF library.
# This requires the presence of the libtiff include and library files.
# (package 'libtiff4-dev' on Debian).
TIFF_CFLAGS = -Dcimg_use_tiff
TIFF_LDFLAGS = -ltiff


# Flags to enable native support for compressed .cimgz files, using the Zlib library.
# This requires the presence of the Zlib include and library files.
# (package 'zlib1g-dev' on Debian).
ZLIB_CFLAGS = -Dcimg_use_zlib
ZLIB_LDFLAGS = -lz



# Flags to enable the use of the FFTW3 library.
# This requires the presence of the FFTW3 include and library files.
# (package 'libfftw3-dev' on Debian).
FFTW_CFLAGS = -Dcimg_use_fftw3
FFTW_LDFLAGS = -lfftw3




#----------------------------------------------------------------
# Predefined sets of flags for different default configurations.
#----------------------------------------------------------------


# Windows : Standard build.
STD_WINDOWS_CFLAGS= $(MANDATORY_CFLAGS) $(PARALLEL_CFLAGS) $(GDI32_CFLAGS) $(ZLIB_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) $(TIFF_CFLAGS) $(FFTW_CFLAGS)
STD_WINDOWS_LDFLAGS = $(MANDATORY_LDFLAGS) $(PARALLEL_LDFLAGS) $(GDI32_LDFLAGS) $(ZLIB_LDFLAGS) $(PNG_LDFLAGS) $(JPEG_LDFLAGS) $(TIFF_LDFLAGS) $(FFTW_LDFLAGS)



# GIMP plug-in : Standard build.
STD_GIMP_CFLAGS = $(MANDATORY_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(PNG_CFLAGS) $(ZLIB_CFLAGS) $(TIFF_CFLAGS) ${IS_BETA_CFLAGS} -Dcimg_display=0 -Dcimg_use_rng
STD_GIMP_LDFLAGS = $(MANDATORY_LDFLAGS) $(PARALLEL_LDFLAGS) $(FFTW_LDFLAGS) $(PNG_LDFLAGS) $(ZLIB_LDFLAGS) $(TIFF_LDFLAGS) -mwindows



#--------------------------
# Define Makefile entries.
#--------------------------

# Main entries
all:

	@echo "**"
	@echo "** Windows configuration"
	@echo "**"
	$(MAKE) windows
	$(MAKE) gimp

gimp:
	$(MAKE) "CFLAGS=$(STD_GIMP_CFLAGS) $(OPT_CFLAGS)" "LDFLAGS+=$(STD_GIMP_LDFLAGS) $(OPT_LDFLAGS)" "STRIP_EXE=1" gmic_gimp



# Entries for other configurations.


windows:
	$(MAKE) "CFLAGS=$(STD_WINDOWS_CFLAGS) $(OPT_CFLAGS)" "LDFLAGS=$(STD_WINDOWS_LDFLAGS)" "STRIP_EXE=1" gmic_gmic



# Internal rules to build compilation modules.
gmic_lib.o: gmic.cpp gmic_def.h
	$(CC) -o gmic_lib.o -c gmic.cpp -fPIC $(CFLAGS) -Dgmic_float_only
gmic_lib: gmic_lib.o
	ar rcs libgmic.a gmic_lib.o
ifneq ($(OS),Darwin)
	$(CC) -shared -Wl,-soname,libgmic.so.1 -o libgmic.so gmic_lib.o $(LDFLAGS)
	$(CC) -o gmic_use_lib gmic_use_lib.cpp -L. -lgmic $(FFTW_LDFLAGS)
else
	$(CC) -shared -o libgmic.so gmic_lib.o $(LDFLAGS)
endif

gmic_gimp.o: gmic.cpp gmic_def.h
	$(CC) -o gmic_gimp.o -c gmic.cpp $(CFLAGS) -Dgmic_gimp -Dgmic_float_only
gmic_gimp : gmic_gimp.o gmic_gimp.cpp
	$(CC) -o gmic_gimp gmic_gimp.cpp gmic_gimp.o `gimptool-2.0$(EXE) --cflags` $(CFLAGS) `gimptool-2.0$(EXE) --libs` $(LDFLAGS)
	strip gmic_gimp$(EXE)

gmic_minimal: gmic.cpp
	$(CC) -o gmic gmic.cpp $(CFLAGS) -Dgmic_float_only -Dgmic_main $(LDFLAGS)

gmic_bool.o: gmic.cpp
	$(CC) -o gmic_bool.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_bool
gmic_uchar.o: gmic.cpp
	$(CC) -o gmic_uchar.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_uchar
gmic_char.o: gmic.cpp
	$(CC) -o gmic_char.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_char
gmic_ushort.o: gmic.cpp
	$(CC) -o gmic_ushort.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_ushort
gmic_short.o: gmic.cpp
	$(CC) -o gmic_short.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_short
gmic_uint.o: gmic.cpp
	$(CC) -o gmic_uint.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_uint
gmic_int.o: gmic.cpp
	$(CC) -o gmic_int.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_int
gmic_float.o: gmic.cpp
	$(CC) -o gmic_float.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_float -Dgmic_main
gmic_double.o: gmic.cpp
	$(CC) -o gmic_double.o -c gmic.cpp $(CFLAGS) -Dgmic_split_compilation -Dgmic_double
gmic_gmic: gmic_bool.o gmic_uchar.o gmic_char.o gmic_ushort.o gmic_short.o gmic_uint.o gmic_int.o gmic_float.o gmic_double.o gmic_def.h
	$(CC) -o gmic gmic_bool.o gmic_uchar.o gmic_char.o gmic_ushort.o gmic_short.o gmic_uint.o gmic_int.o gmic_float.o gmic_double.o $(LDFLAGS)
	strip gmic$(EXE)

def:
	@echo "#ifndef gmic_gimp" > gmic_def.h
	\gmic -v - gmic_def.gmic raw:gmic_def.gmic,char -compress_gmic -type char -o -.h | sed 's/unnamed/gmic_def/' | sed 's/ \};/, 0 \};\n\nunsigned int size_data_gmic_def = sizeof(data_gmic_def);\n/g' >> gmic_def.h
	@echo "#else" >> gmic_def.h
	\gmic -v - gmic_def.gmic -update_gmic_gimp @.,0 raw:$(HOME)/.update@..gmic,char -compress_gmic_gimp -type char -o -.h | sed 's/unnamed/gmic_def/' | sed 's/ \};/, 0 \};\n\nunsigned int size_data_gmic_def = sizeof(data_gmic_def);\n/g' >> gmic_def.h
	\gmic -v - ../html/img/logoGMIC.ppm -permute cxyz -type uchar -o -.h | sed 's/unnamed/gmic_logo/' >> gmic_def.h
	@echo "unsigned int size_data_logo = sizeof(data_gmic_logo);" >> gmic_def.h
	@echo "#endif" >> gmic_def.h
	@echo >>gmic_def.h

# Install/uninstall/clean procedures.


distclean: clean

clean:
	rm -rf gmic*.o *.exe

# End of Makefile
