# ====================================================================================================================
#
# The copyright in this software is being made available under the license included below.
#
# Copyright (c) 2010, France Telecom S.A., NTT Corp, NTT DOCOMO, Inc., DOCOMO Communications Laboratories USA, Inc.,
# Panasonic Corp., Technicolor S.A. All rights reserved.
#
# By receiving and/or using this software, you agree to be bound by the following license. Subject to the terms of
# this agreement, this license is a non-exclusive license to distribute and use the software, in source and binary
# forms, with or without modification, permitted only for the purpose of developing standards within the Joint
# Collaborative Team on Video Coding and for testing and promoting such standards. The license is subject to the
# following conditions:
#
#   * Distributions of source code must retain the above copyright notice, this list of conditions and the following
#     disclaimer.
#   * Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the
#     following disclaimer in the documentation and/or other materials provided with such distribution.
#   * Neither the name of France Telecom S.A., NTT Corp, NTT DOCOMO, Inc.,
#     DOCOMO Communications Laboratories USA, Inc., Panasonic Corp., Technicolor S.A nor the names of their
#     contributors may be used to endorse or promote products derived from this software without specific prior
#     written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, EQUIPMENT OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# THIS SOFTWARE MAY BE SUBJECT TO OTHER THIRD PARTY AND CONTRIBUTOR RIGHTS, INCLUDING PATENT RIGHTS, AND NO SUCH
# RIGHTS ARE GRANTED UNDER THIS LICENSE. ALL USERS AGREE TO INDEMNIFY AND HOLD HARMLESS THE ABOVE MENTIONED PARTIES
# TO THE COPYRIGHT AGAINST ANY AND ALL CLAIMS OR DEMANDS, INCLUDING WITHOUT LIMITATION INTELLECTUAL PROPERTY RIGHTS
# OF THIRD PARTIES, WHICH MIGHT ARISE UNDER THE USE OR DISTRIBUTION OF THIS SOFTWARE.
#
# ====================================================================================================================
# Makefile



INCDIR = inc
SRCDIR = src

### include debug information: 1=yes, 0=no
#DBG= 0
### Add special optimizations based on Architecture : 1=Enable, 0=disable
OPT= 1
### Choose Compliler : 1=Intel, 0=GCC
#ICC= 0
#ifdef JMSNR
SNR = -DJM_PSNR
#else
#SNR =
#endif

ifdef ICC
COMPILER= 'CDCM: Using Intel Compiler...'
CC = icc
else
COMPILER= 'CDCM: Using G++ Compiler...'
CC = g++
#CC = llvm-g++
endif

ifdef ICC
# Flags for icc
SUFFIX=
CFLAGS = -fast -static -I$(INCDIR) -xN -DUSEMMX $(SNR)
#CFLAGS = -O2 -static -I$(INCDIR) -xN -DUSEMMX -prof_dir pf -prof_genx 
#CFLAGS = -fast -I$(INCDIR) -xN -DUSEMMX -prof_dir pf -prof_use
DEBUG= 'Debug mode disabled'

else
# Architecture-specific flags (g++)
AFLAGS = -msse2 -momit-leaf-frame-pointer
#AFLAGS =

# Flags for gcc
#CFLAGS = $(AFLAGS) -pthread -Wall -W -I$(INCDIR) $(SNR) -DTRACE_STATS
CFLAGS = $(AFLAGS) -pthread -ffloat-store -Wall -W -I$(INCDIR) $(SNR) -DTRACE_STATS
#CFLAGS = $(AFLAGS) -Wall -W -I$(INCDIR) $(SNR) -DTRACE_STATS -DAIF -DAIF_HALF -DAIF_PRED -DAIF_FULL
#CFLAGS = $(AFLAGS) -Wall -W -pg -I$(INCDIR)
#CFLAGS = $(AFLAGS) -Wall -W -O3 -pg -g3 -ggdb -I$(INCDIR)
#CFLAGS = $(AFLAGS) -g3 -I$(INCDIR)

ifdef DBG
DEBUG= 'Debug mode enabled'
SUFFIX= .dbg
CFLAGS+= -g -g3 -ggdb
else
DEBUG= 'Debug mode disabled'
SUFFIX=
CFLAGS+= -O3
#CFLAGS+= -O4
# Uncomment following line to disable assert() checks in code
#CFLAGS+= -DNDEBUG

ifdef OPT
#CFLAGS += -mtune=core2 -march=core2
#CFLAGS+= -funroll-all-loops -fomit-frame-pointer -finline-functions -fno-strength-reduce -fthread-jumps -fexpensive-optimizations
CFLAGS+= -mtune=nocona -march=nocona -funroll-all-loops -fomit-frame-pointer -finline-functions -fno-strength-reduce -fthread-jumps -fexpensive-optimizations
endif   #ifdef OPT

endif #ifdef DBG

endif #ifdef ICC

COBJECTS = $(SRCDIR)/ProbEst.o $(SRCDIR)/ContextMap.o \
	$(SRCDIR)/SimpleProbEst.o $(SRCDIR)/Frame.o \
	$(SRCDIR)/SimpleProbEstTabulatedLog.o \
	$(SRCDIR)/Buffer.o $(SRCDIR)/Param.o $(SRCDIR)/MotionField.o \
	$(SRCDIR)/Block.o \
	$(SRCDIR)/EntropyModel.o \
	$(SRCDIR)/FixedProbEst.o $(SRCDIR)/IntraPrediction.o \
	$(SRCDIR)/FastDCT.o $(SRCDIR)/Quantizer.o \
	$(SRCDIR)/PredBlk.o $(SRCDIR)/MCRefBlk8.o \
	$(SRCDIR)/MLC_Stat.o \
	$(SRCDIR)/LumaFrames8pel.o $(SRCDIR)/ChromaFrames8pel.o \
	$(SRCDIR)/LumaFrames.o $(SRCDIR)/ChromaFrames.o $(SRCDIR)/WFrame.o \
	$(SRCDIR)/ZTNode.o $(SRCDIR)/ZeroTree.o \
	$(SRCDIR)/WienerFilter.o \
	$(SRCDIR)/Deblocking_Filter.o \
	$(SRCDIR)/LoopFilter.o $(SRCDIR)/UnaryProbEst.o \
	$(SRCDIR)/LoopFilterNull.o \
	$(SRCDIR)/RefFrame.o $(SRCDIR)/RefFrameManager.o \
	$(SRCDIR)/EntropyDecoder.o $(SRCDIR)/ArithDecoder.o \
	$(SRCDIR)/ArithTranscoder.o \
	$(SRCDIR)/EntropyEncoder.o $(SRCDIR)/ArithEncoder.o \
	$(SRCDIR)/AIF_adaptive_filter.o \
	$(SRCDIR)/RefProcess.o \
	$(SRCDIR)/Trace.o \
	$(SRCDIR)/DenoiseThreshold.o $(SRCDIR)/DenoiseTransform.o \
	$(SRCDIR)/DenoiseTransformDCT4.o $(SRCDIR)/DenoiseTransformDCT8.o \
	$(SRCDIR)/DenoiseTransformHadamard4.o $(SRCDIR)/DenoiseTransformHadamard8.o \
	$(SRCDIR)/LoopFilterOvercomplete3.o \
	$(SRCDIR)/QuantTables.o \
	$(SRCDIR)/Plane.o \
	$(SRCDIR)/TransformAlternate.o \
	$(SRCDIR)/EntropyCoder.o

EOBJECTS = $(COBJECTS) $(SRCDIR)/MainEncoder.o \
	$(SRCDIR)/Encoder.o $(SRCDIR)/MotionEst.o \
	$(SRCDIR)/MotionEstRefine.o $(SRCDIR)/MotionEstTrellis.o \
	$(SRCDIR)/MotionEstRegion.o \
	$(SRCDIR)/IEncoder6.o \
	$(SRCDIR)/ExplicitGop.o $(SRCDIR)/MotionEstUZSearchBiPred.o

DOBJECTS = $(COBJECTS) $(SRCDIR)/MainDecoder.o $(SRCDIR)/Decoder.o


all: messages bin/encoder bin/decoder

messages:
	@echo
	@echo $(COMPILER)
	@echo $(DEBUG)
	@echo

bin/encoder: $(EOBJECTS)
	@echo
	@echo 'Generating encoder'
	@$(CC) $(CFLAGS) $(EOBJECTS) -o bin/encoder$(SUFFIX) 
	@echo ... done

bin/decoder: $(DOBJECTS)
	@echo 
	@echo $(COMPILER)
	@echo 'Generating decoder'
	@$(CC) $(CFLAGS) $(DOBJECTS) -o bin/decoder$(SUFFIX)
	@echo .. done

.cpp.o: $?
	@echo 'CDCM: Compiling object file "$@" ...'
	@$(CC) $(CFLAGS) -c $< -o $@

clean: 
	@echo remove all objects
	@rm -f $(SRCDIR)/*.o bin/encoder bin/decoder 
	@rm -f $(SRCDIR)/*~ $(INCDIR)/*~ dat/*~ tools/*~ *~ $(SRCDIR)/*.il

tar:
	@echo
	@echo 'Preparing archive file'
	@tar cvzf codec.tar.gz $(SRCDIR)/*.cpp $(INCDIR)/*.H dat Makefile bin/encoder.cfg
	@echo

depend:
	@echo
	@echo 'making dependencies'
	@makedepend -I$(INCDIR) $(SRCDIR)/*.cpp
	@echo

# DO NOT DELETE
