!IF "$(CFG)" == "Win64"
BUILDBITS= 64
EXTRAFLAGS=/D _M_X64
!ELSE
BUILDBITS= 32
!ENDIF

PERL   = perl 
CP     = $(PERL) -MExtUtils::Command -e cp --
RM_F   = $(PERL) -MExtUtils::Command -e rm_f --
MKPATH = $(PERL) -MExtUtils::Command -e mkpath --

### GLOBAL PART ###

VER_MAJOR = 3
VER_MINOR = 16.0
DISTDIR   = Dist
STATICLIB = freeimage.lib

###INCLUDEFLAGS = -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibTIFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/IlmImf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/LibRawLite -ISource/LibRawLite/dcraw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src -ISource/LibWebP -ISource/LibJXR -ISource/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib 
###CFLAGS = $(INCLUDEFLAGS) /O2 /Ob2 /Oi /Ot /Oy /D "WIN32" /D "_DEBUG" /D "OPJ_STATIC" /D "FREEIMAGE_LIB" /D "_CRT_SECURE_NO_DEPRECATE" /D "LIBRAW_NODLL" /D "_MBCS" /GF /FD /EHsc /MT /W3 /wd4290 /nologo $(EXTRAFLAGS)

CFLAGS = /O2 /Ob2 /Oi /Ot /Oy /I "Source" /I "Source\ZLib" /I "Source\DeprecationManager" /I "Source\OpenEXR" /I "Source\OpenEXR\Half" /I "Source\OpenEXR\Iex" /I "Source\OpenEXR\IlmImf" /I "Source\OpenEXR\Imath" /I "Source\OpenEXR\IlmThread" /I "Source\LibJXR\jxrgluelib" /I "Source\LibJXR\image\sys" /I "Source\LibRawLite" /D "WIN32" /D "_DEBUG" /D "OPJ_STATIC" /D "FREEIMAGE_LIB" /D "_CRT_SECURE_NO_DEPRECATE" /D "LIBRAW_NODLL" /D "_MBCS" /D "DISABLE_PERF_MEASUREMENT" /GF /FD /EHsc /MT /W3 /wd4290 /nologo $(EXTRAFLAGS)

CPPFLAGS = $(CFLAGS)

OBJS = Source/FreeImage/BitmapAccess.obj Source/FreeImage/ColorLookup.obj Source/FreeImage/FreeImage.obj Source/FreeImage/FreeImageC.obj Source/FreeImage/FreeImageIO.obj Source/FreeImage/GetType.obj Source/FreeImage/MemoryIO.obj Source/FreeImage/PixelAccess.obj Source/FreeImage/J2KHelper.obj Source/FreeImage/MNGHelper.obj Source/FreeImage/Plugin.obj Source/FreeImage/PluginJXR.obj Source/FreeImage/PluginBMP.obj Source/FreeImage/PluginCUT.obj Source/FreeImage/PluginDDS.obj Source/FreeImage/PluginEXR.obj Source/FreeImage/PluginG3.obj Source/FreeImage/PluginGIF.obj Source/FreeImage/PluginHDR.obj Source/FreeImage/PluginICO.obj Source/FreeImage/PluginIFF.obj Source/FreeImage/PluginJ2K.obj Source/FreeImage/PluginJNG.obj Source/FreeImage/PluginJP2.obj Source/FreeImage/PluginJPEG.obj  Source/FreeImage/PluginKOALA.obj Source/FreeImage/PluginMNG.obj Source/FreeImage/PluginPCD.obj Source/FreeImage/PluginPCX.obj Source/FreeImage/PluginPFM.obj Source/FreeImage/PluginPICT.obj Source/FreeImage/PluginPNG.obj Source/FreeImage/PluginPNM.obj Source/FreeImage/PluginPSD.obj Source/FreeImage/PluginRAS.obj Source/FreeImage/PluginRAW.obj Source/FreeImage/PluginSGI.obj Source/FreeImage/PluginTARGA.obj Source/FreeImage/PluginTIFF.obj Source/FreeImage/PluginWBMP.obj Source/FreeImage/PluginWebP.obj Source/FreeImage/PluginXBM.obj Source/FreeImage/PluginXPM.obj Source/FreeImage/PSDParser.obj Source/FreeImage/TIFFLogLuv.obj Source/FreeImage/Conversion.obj Source/FreeImage/Conversion16_555.obj Source/FreeImage/Conversion16_565.obj Source/FreeImage/Conversion24.obj Source/FreeImage/Conversion32.obj Source/FreeImage/Conversion4.obj Source/FreeImage/Conversion8.obj Source/FreeImage/ConversionFloat.obj Source/FreeImage/ConversionRGB16.obj Source/FreeImage/ConversionRGBF.obj Source/FreeImage/ConversionType.obj Source/FreeImage/ConversionUINT16.obj Source/FreeImage/Halftoning.obj Source/FreeImage/tmoColorConvert.obj Source/FreeImage/tmoDrago03.obj Source/FreeImage/tmoFattal02.obj Source/FreeImage/tmoReinhard05.obj Source/FreeImage/ToneMapping.obj Source/FreeImage/NNQuantizer.obj Source/FreeImage/WuQuantizer.obj Source/DeprecationManager/Deprecated.obj Source/DeprecationManager/DeprecationMgr.obj Source/FreeImage/CacheFile.obj Source/FreeImage/MultiPage.obj Source/FreeImage/ZLibInterface.obj Source/Metadata/Exif.obj Source/Metadata/FIRational.obj Source/Metadata/FreeImageTag.obj Source/Metadata/IPTC.obj Source/Metadata/TagConversion.obj Source/Metadata/TagLib.obj Source/Metadata/XTIFF.obj Source/FreeImageToolkit/Background.obj Source/FreeImageToolkit/BSplineRotate.obj Source/FreeImageToolkit/Channels.obj Source/FreeImageToolkit/ClassicRotate.obj Source/FreeImageToolkit/Colors.obj Source/FreeImageToolkit/CopyPaste.obj Source/FreeImageToolkit/Display.obj Source/FreeImageToolkit/Flip.obj Source/FreeImageToolkit/JPEGTransform.obj Source/FreeImageToolkit/MultigridPoissonSolver.obj Source/FreeImageToolkit/Rescale.obj Source/FreeImageToolkit/Resize.obj Source/LibJPEG/jaricom.obj Source/LibJPEG/jcapimin.obj Source/LibJPEG/jcapistd.obj Source/LibJPEG/jcarith.obj Source/LibJPEG/jccoefct.obj Source/LibJPEG/jccolor.obj Source/LibJPEG/jcdctmgr.obj Source/LibJPEG/jchuff.obj Source/LibJPEG/jcinit.obj Source/LibJPEG/jcmainct.obj Source/LibJPEG/jcmarker.obj Source/LibJPEG/jcmaster.obj Source/LibJPEG/jcomapi.obj Source/LibJPEG/jcparam.obj Source/LibJPEG/jcprepct.obj Source/LibJPEG/jcsample.obj Source/LibJPEG/jctrans.obj Source/LibJPEG/jdapimin.obj Source/LibJPEG/jdapistd.obj Source/LibJPEG/jdarith.obj Source/LibJPEG/jdatadst.obj Source/LibJPEG/jdatasrc.obj Source/LibJPEG/jdcoefct.obj Source/LibJPEG/jdcolor.obj Source/LibJPEG/jddctmgr.obj Source/LibJPEG/jdhuff.obj Source/LibJPEG/jdinput.obj Source/LibJPEG/jdmainct.obj Source/LibJPEG/jdmarker.obj Source/LibJPEG/jdmaster.obj Source/LibJPEG/jdmerge.obj Source/LibJPEG/jdpostct.obj Source/LibJPEG/jdsample.obj Source/LibJPEG/jdtrans.obj Source/LibJPEG/jerror.obj Source/LibJPEG/jfdctflt.obj Source/LibJPEG/jfdctfst.obj Source/LibJPEG/jfdctint.obj Source/LibJPEG/jidctflt.obj Source/LibJPEG/jidctfst.obj Source/LibJPEG/jidctint.obj Source/LibJPEG/jmemmgr.obj Source/LibJPEG/jmemnobs.obj Source/LibJPEG/jquant1.obj Source/LibJPEG/jquant2.obj Source/LibJPEG/jutils.obj Source/LibJPEG/transupp.obj Source/LibPNG/png.obj Source/LibPNG/pngerror.obj Source/LibPNG/pngget.obj Source/LibPNG/pngmem.obj Source/LibPNG/pngpread.obj Source/LibPNG/pngread.obj Source/LibPNG/pngrio.obj Source/LibPNG/pngrtran.obj Source/LibPNG/pngrutil.obj Source/LibPNG/pngset.obj Source/LibPNG/pngtrans.obj Source/LibPNG/pngwio.obj Source/LibPNG/pngwrite.obj Source/LibPNG/pngwtran.obj Source/LibPNG/pngwutil.obj Source/LibTIFF4/tif_aux.obj Source/LibTIFF4/tif_close.obj Source/LibTIFF4/tif_codec.obj Source/LibTIFF4/tif_color.obj Source/LibTIFF4/tif_compress.obj Source/LibTIFF4/tif_dir.obj Source/LibTIFF4/tif_dirinfo.obj Source/LibTIFF4/tif_dirread.obj Source/LibTIFF4/tif_dirwrite.obj Source/LibTIFF4/tif_dumpmode.obj Source/LibTIFF4/tif_error.obj Source/LibTIFF4/tif_extension.obj Source/LibTIFF4/tif_fax3.obj Source/LibTIFF4/tif_fax3sm.obj Source/LibTIFF4/tif_flush.obj Source/LibTIFF4/tif_getimage.obj Source/LibTIFF4/tif_jpeg.obj Source/LibTIFF4/tif_luv.obj Source/LibTIFF4/tif_lzma.obj Source/LibTIFF4/tif_lzw.obj Source/LibTIFF4/tif_next.obj Source/LibTIFF4/tif_ojpeg.obj Source/LibTIFF4/tif_open.obj Source/LibTIFF4/tif_packbits.obj Source/LibTIFF4/tif_pixarlog.obj Source/LibTIFF4/tif_predict.obj Source/LibTIFF4/tif_print.obj Source/LibTIFF4/tif_read.obj Source/LibTIFF4/tif_strip.obj Source/LibTIFF4/tif_swab.obj Source/LibTIFF4/tif_thunder.obj Source/LibTIFF4/tif_tile.obj Source/LibTIFF4/tif_version.obj Source/LibTIFF4/tif_warning.obj Source/LibTIFF4/tif_write.obj Source/LibTIFF4/tif_zip.obj Source/ZLib/adler32.obj Source/ZLib/compress.obj Source/ZLib/crc32.obj Source/ZLib/deflate.obj Source/ZLib/gzclose.obj Source/ZLib/gzlib.obj Source/ZLib/gzread.obj Source/ZLib/gzwrite.obj Source/ZLib/infback.obj Source/ZLib/inffast.obj Source/ZLib/inflate.obj Source/ZLib/inftrees.obj Source/ZLib/trees.obj Source/ZLib/uncompr.obj Source/ZLib/zutil.obj Source/LibOpenJPEG/bio.obj Source/LibOpenJPEG/cio.obj Source/LibOpenJPEG/dwt.obj Source/LibOpenJPEG/event.obj Source/LibOpenJPEG/function_list.obj Source/LibOpenJPEG/image.obj Source/LibOpenJPEG/invert.obj Source/LibOpenJPEG/j2k.obj Source/LibOpenJPEG/jp2.obj Source/LibOpenJPEG/mct.obj Source/LibOpenJPEG/mqc.obj Source/LibOpenJPEG/openjpeg.obj Source/LibOpenJPEG/opj_clock.obj Source/LibOpenJPEG/pi.obj Source/LibOpenJPEG/raw.obj Source/LibOpenJPEG/t1.obj Source/LibOpenJPEG/t2.obj Source/LibOpenJPEG/tcd.obj Source/LibOpenJPEG/tgt.obj Source/OpenEXR/IlmImf/ImfAttribute.obj Source/OpenEXR/IlmImf/ImfB44Compressor.obj Source/OpenEXR/IlmImf/ImfCompressor.obj Source/OpenEXR/IlmImf/ImfEnvmap.obj Source/OpenEXR/IlmImf/ImfBoxAttribute.obj Source/OpenEXR/IlmImf/ImfChannelList.obj Source/OpenEXR/IlmImf/ImfChannelListAttribute.obj Source/OpenEXR/IlmImf/ImfChromaticities.obj Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.obj Source/OpenEXR/IlmImf/ImfCompressionAttribute.obj Source/OpenEXR/IlmImf/ImfConvert.obj Source/OpenEXR/IlmImf/ImfCRgbaFile.obj Source/OpenEXR/IlmImf/ImfDoubleAttribute.obj Source/OpenEXR/IlmImf/ImfEnvmapAttribute.obj Source/OpenEXR/IlmImf/ImfFloatAttribute.obj Source/OpenEXR/IlmImf/ImfFrameBuffer.obj Source/OpenEXR/IlmImf/ImfFramesPerSecond.obj Source/OpenEXR/IlmImf/ImfHeader.obj Source/OpenEXR/IlmImf/ImfHuf.obj Source/OpenEXR/IlmImf/ImfInputFile.obj Source/OpenEXR/IlmImf/ImfIntAttribute.obj Source/OpenEXR/IlmImf/ImfIO.obj Source/OpenEXR/IlmImf/ImfKeyCode.obj Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.obj Source/OpenEXR/IlmImf/ImfLineOrderAttribute.obj Source/OpenEXR/IlmImf/ImfLut.obj Source/OpenEXR/IlmImf/ImfMatrixAttribute.obj Source/OpenEXR/IlmImf/ImfMisc.obj Source/OpenEXR/IlmImf/ImfOpaqueAttribute.obj Source/OpenEXR/IlmImf/ImfOutputFile.obj Source/OpenEXR/IlmImf/ImfPizCompressor.obj Source/OpenEXR/IlmImf/ImfPreviewImage.obj Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.obj Source/OpenEXR/IlmImf/ImfPxr24Compressor.obj Source/OpenEXR/IlmImf/ImfRational.obj Source/OpenEXR/IlmImf/ImfRationalAttribute.obj Source/OpenEXR/IlmImf/ImfRgbaFile.obj Source/OpenEXR/IlmImf/ImfRgbaYca.obj Source/OpenEXR/IlmImf/ImfRleCompressor.obj Source/OpenEXR/IlmImf/ImfScanLineInputFile.obj Source/OpenEXR/IlmImf/ImfStandardAttributes.obj Source/OpenEXR/IlmImf/ImfStdIO.obj Source/OpenEXR/IlmImf/ImfStringAttribute.obj Source/OpenEXR/IlmImf/ImfStringVectorAttribute.obj Source/OpenEXR/IlmImf/ImfTestFile.obj Source/OpenEXR/IlmImf/ImfThreading.obj Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.obj Source/OpenEXR/IlmImf/ImfTiledInputFile.obj Source/OpenEXR/IlmImf/ImfTiledMisc.obj Source/OpenEXR/IlmImf/ImfTiledOutputFile.obj Source/OpenEXR/IlmImf/ImfTiledRgbaFile.obj Source/OpenEXR/IlmImf/ImfTileOffsets.obj Source/OpenEXR/IlmImf/ImfTimeCode.obj Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.obj Source/OpenEXR/IlmImf/ImfVecAttribute.obj Source/OpenEXR/IlmImf/ImfVersion.obj Source/OpenEXR/IlmImf/ImfWav.obj Source/OpenEXR/IlmImf/ImfZipCompressor.obj Source/OpenEXR/Imath/ImathBox.obj Source/OpenEXR/Imath/ImathColorAlgo.obj Source/OpenEXR/Imath/ImathFun.obj Source/OpenEXR/Imath/ImathMatrixAlgo.obj Source/OpenEXR/Imath/ImathRandom.obj Source/OpenEXR/Imath/ImathShear.obj Source/OpenEXR/Imath/ImathVec.obj Source/OpenEXR/Iex/IexBaseExc.obj Source/OpenEXR/Iex/IexThrowErrnoExc.obj Source/OpenEXR/Half/half.obj Source/OpenEXR/IlmThread/IlmThread.obj Source/OpenEXR/IlmThread/IlmThreadMutex.obj Source/OpenEXR/IlmThread/IlmThreadPool.obj Source/OpenEXR/IlmThread/IlmThreadSemaphore.obj Source/LibRawLite/internal/dcraw_common.obj Source/LibRawLite/internal/dcraw_fileio.obj Source/LibRawLite/internal/demosaic_packs.obj Source/LibRawLite/src/libraw_c_api.obj Source/LibRawLite/src/libraw_cxx.obj Source/LibRawLite/src/libraw_datastream.obj Source/LibWebP/src/dec/dec_alpha.obj Source/LibWebP/src/dec/dec_buffer.obj Source/LibWebP/src/dec/dec_frame.obj Source/LibWebP/src/dec/dec_idec.obj Source/LibWebP/src/dec/dec_io.obj Source/LibWebP/src/dec/dec_layer.obj Source/LibWebP/src/dec/dec_quant.obj Source/LibWebP/src/dec/dec_tree.obj Source/LibWebP/src/dec/dec_vp8.obj Source/LibWebP/src/dec/dec_vp8l.obj Source/LibWebP/src/dec/dec_webp.obj Source/LibWebP/src/dsp/cpu.obj Source/LibWebP/src/dsp/dec.obj Source/LibWebP/src/dsp/dec_clip_tables.obj Source/LibWebP/src/dsp/dec_neon.obj Source/LibWebP/src/dsp/dec_sse2.obj Source/LibWebP/src/dsp/enc.obj Source/LibWebP/src/dsp/enc_neon.obj Source/LibWebP/src/dsp/enc_sse2.obj Source/LibWebP/src/dsp/lossless.obj Source/LibWebP/src/dsp/upsampling.obj Source/LibWebP/src/dsp/upsampling_neon.obj Source/LibWebP/src/dsp/upsampling_sse2.obj Source/LibWebP/src/dsp/yuv.obj Source/LibWebP/src/enc/enc_alpha.obj Source/LibWebP/src/enc/enc_analysis.obj Source/LibWebP/src/enc/enc_backward_references.obj Source/LibWebP/src/enc/enc_config.obj Source/LibWebP/src/enc/enc_cost.obj Source/LibWebP/src/enc/enc_filter.obj Source/LibWebP/src/enc/enc_frame.obj Source/LibWebP/src/enc/enc_histogram.obj Source/LibWebP/src/enc/enc_iterator.obj Source/LibWebP/src/enc/enc_layer.obj Source/LibWebP/src/enc/enc_picture.obj Source/LibWebP/src/enc/enc_quant.obj Source/LibWebP/src/enc/enc_syntax.obj Source/LibWebP/src/enc/enc_tree.obj Source/LibWebP/src/enc/enc_vp8l.obj Source/LibWebP/src/enc/enc_webpenc.obj Source/LibWebP/src/enc/token.obj Source/LibWebP/src/utils/alpha_processing.obj Source/LibWebP/src/utils/bit_reader.obj Source/LibWebP/src/utils/bit_writer.obj Source/LibWebP/src/utils/color_cache.obj Source/LibWebP/src/utils/filters.obj Source/LibWebP/src/utils/huffman.obj Source/LibWebP/src/utils/huffman_encode.obj Source/LibWebP/src/utils/quant_levels.obj Source/LibWebP/src/utils/quant_levels_dec.obj Source/LibWebP/src/utils/random.obj Source/LibWebP/src/utils/rescaler.obj Source/LibWebP/src/utils/thread.obj Source/LibWebP/src/utils/utils.obj Source/LibWebP/src/mux/muxedit.obj Source/LibWebP/src/mux/muxinternal.obj Source/LibWebP/src/mux/muxread.obj Source/LibJXR/image/decode/decode.obj Source/LibJXR/image/decode/JXRTranscode.obj Source/LibJXR/image/decode/postprocess.obj Source/LibJXR/image/decode/segdec.obj Source/LibJXR/image/decode/strdec.obj Source/LibJXR/image/decode/strdec_x86.obj Source/LibJXR/image/decode/strInvTransform.obj Source/LibJXR/image/decode/strPredQuantDec.obj Source/LibJXR/image/encode/encode.obj Source/LibJXR/image/encode/segenc.obj Source/LibJXR/image/encode/strenc.obj Source/LibJXR/image/encode/strenc_x86.obj Source/LibJXR/image/encode/strFwdTransform.obj Source/LibJXR/image/encode/strPredQuantEnc.obj Source/LibJXR/image/sys/adapthuff.obj Source/LibJXR/image/sys/image.obj Source/LibJXR/image/sys/strcodec.obj Source/LibJXR/image/sys/strPredQuant.obj Source/LibJXR/image/sys/strTransform.obj Source/LibJXR/jxrgluelib/JXRGlue.obj Source/LibJXR/jxrgluelib/JXRGlueJxr.obj Source/LibJXR/jxrgluelib/JXRGluePFC.obj Source/LibJXR/jxrgluelib/JXRMeta.obj 

### main targets ###

all: $(STATICLIB)
	$(MKPATH) "$(DISTDIR)"
	$(CP) $(STATICLIB) "$(DISTDIR)"
	$(CP) Source/FreeImage.h "$(DISTDIR)"

$(STATICLIB): $(OBJS)
	lib /OUT:$@ $**

.c.obj:
	$(CC) $(CFLAGS) /c $< /Fo$@

.cpp.obj:
	$(CC) $(CFLAGS) /c $< /Fo$@

clean:
	$(RM_F) $(OBJS) $(STATICLIB) $(DISTDIR)/*
