#-*-makefile-*-
# Usage: gmake [<general options>] [USE_AFSP=0] [ISOMP4=0] [RESET_TEST=1] [TORTURE_TEST=1] [PNS_NONDETERMINISTIC_RANDOM=1] [LOW_POWER_SBR=1] [PARAMETRICSTEREO=1]

include ../general/makefile.cfg
-include ../general/makefile.cfg-local
-include makefile.cfg
-include makefile.cfg-local

TOTAL_PATH_ADD =

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
ifndef ISOMP4
ISOMP4 = 1
endif

ifneq "$(ISOMP4)" "0"
TOTAL_PATH_ADD += isomp4
endif

ifndef LOW_POWER_SBR
LOW_POWER_SBR=0
endif

ifndef PARAMETRICSTEREO
PARAMETRICSTEREO=0
endif

ifneq "$(LOW_POWER_SBR)" "0"
TOTAL_PATH_ADD += lp
endif

TOTAL_PATH_ADD += sbr

ifneq "$(PARAMETRICSTEREO)" "0"
TOTAL_PATH_ADD += ps
endif
#endif          /* strip-to-mpeg2 needs this comment */

ifndef USE_AFSP
USE_AFSP = 1
endif

ifneq "$(USE_AFSP)" "0"
TOTAL_PATH_ADD += AFsp
endif

ifneq  "$(MAKELEVEL)" "0"

override ADDONDIR = $(TOTAL_PATH_ADD)
ifneq "$(findstring libisoaac.a,$(TARGET))" ""
ADDONOBJDIR = _aac
else
ADDONOBJDIR = _mp4
override DEFFLAGS += -DMPEG4V1

override MODULELIBS += -lisoaac_mp4

#endif          /* strip-to-mpeg2 needs this comment */
endif

endif # ifneq  "$(MAKELEVEL)" "0"

# -include ../general/makefile.all spread in file
include ../general/makefile.platform
include ../general/makefile.rules

ifeq "$(MAKELEVEL)" "0"

# Common
OBJS = bitinput.o config.o coupling.o diagnose.o drc.o \
       huffdec1.o huffdec2.o huffdec3.o huffinit.o hufftables.o \
       intensity.o intrins.o monopred.o stereo.o tns.o

ifeq "$(USE_AFSP)" "0"
OBJS += aiff_support.o
endif

# + DOLBY imdct
OBJS += adifdecConfTool.o block.o dolby_adapt.o transfo.o

# + SONY gain control
OBJS += gc_unpac.o gc_compensate.o gc_common.o \
        gc_pqf_common.o gc_ipqf.o gc.o gc_mdct_common.o gc_imdct.o


#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
OBJS += ct_envcalc.o ct_envdec.o ct_envextr.o ct_freqsca.o ct_hfgen.o \
        ct_sbrbitb.o ct_sbrcrc.o ct_sbrdec.o ct_sbrdecoder.o ct_polyphase.o
ifeq "$(PARAMETRICSTEREO)" "1"
OBJS += ct_psdec.o   # Parametric Stereo
endif

SBR_CONF_OBJS = ct_sbrConfToolDownSampler.o \
                ct_sbrdecoderConfTool.o \
                decoderConfTool.o \
                audiofile_io.o
#endif          /* strip-to-mpeg2 needs this comment */


OBJS_LIB       = $(OBJS)
AAC_OBJS_ALL   = $(OBJS_LIB)

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
# additional files for MPEG4 only
# + LTP + PNS
MP4_OBJS_LIB   = nok_lt_prediction.o pns.o
MP4_OBJS_ALL   = $(OBJS_LIB) $(MP4_OBJS_LIB) $(OBJS_MP4AUDEC)
#endif          /* strip-to-mpeg2 needs this comment */

# -DBIGDECODER
#  Enabling this option builds an AAC Decoder that can handle up
#  to 48 channels of audio. This is required for stream L8, S15, S16.

override DEFFLAGS = -DNEW_ADTS -DWRITE_NEW_ADTS -DDRC -DBIGDECODER

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
override DEFFLAGS += -DCT_SBR
ifeq "$(LOW_POWER_SBR)" "1"
override DEFFLAGS += -DLOW_POWER_SBR
endif
ifeq "$(PARAMETRICSTEREO)" "1"
override DEFFLAGS += -DPARAMETRICSTEREO
endif
#endif          /* strip-to-mpeg2 needs this comment */

ALL_BIN   = sbr_conftool
AAC_LIBS  = libisoaac.a

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
ifeq "$(ISOMP4)" "1"
MP4_LIBS  = libisoaac_mp4.a
endif
#endif          /* strip-to-mpeg2 needs this comment */

SRCDIRS = src ../mp4mcDec/src
override SRCDIRS += src
OPTIONS = $(MFLAGS) SRCDIRS="$(SRCDIRS)" USE_AFSP=$(USE_AFSP) COMLIBS="$(COMLIBS)" DEFFLAGS="$(DEFFLAGS)" LIBS="$(LIBS)" INCL="$(INCL)" INCLDEP=1

.PHONY: all allafsp $(ALL_BIN) $(MP4_LIBS) $(AAC_LIBS) clean cleanafsp

all: $(ALL_BIN)

allafsp:
	$(MAKE) USE_AFSP=0 all
	$(MAKE) USE_AFSP=1 all

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
ifeq "$(ISOMP4)" "1"

sbr_conftool: $(MP4_LIBS)
	@$(MAKE) $(OPTIONS) TARGET=$@ OBJS="$(SBR_CONF_OBJS)" binary

libisoaac_mp4.a:
	@$(MAKE) $(OPTIONS) TARGET=$@ OBJS="$(OBJS_LIB) $(MP4_OBJS_LIB)" library

endif
#endif          /* strip-to-mpeg2 needs this comment */

libisoaac.a:
	@$(MAKE) $(OPTIONS) TARGET=$@ OBJS="$(OBJS_LIB)" library

clean:
	@$(MAKE) TARGET="libisoaac.a"       OBJS="$(AAC_OBJS_ALL)"  clean_mode
#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
	@$(MAKE) TARGET="libisoaac_mp4.a"   OBJS="$(MP4_OBJS_ALL)"  clean_mode
#endif          /* strip-to-mpeg2 needs this comment */
	@$(MAKE) TARGET="sbr_conftool"      OBJS="$(SBR_CONF_OBJS)" clean_mode

cleanafsp:
	@$(MAKE) USE_AFSP=0 TARGET="libisoaac.a"                 OBJS="$(AAC_OBJS_ALL)"  clean_mode
#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
	@$(MAKE) USE_AFSP=0 TARGET="libisoaac_mp4.a"             OBJS="$(MP4_OBJS_ALL)"  clean_mode
	@$(MAKE) USE_AFSP=1 TARGET="libisoaac_mp4.a"             OBJS="$(MP4_OBJS_ALL)"  clean_mode
#endif          /* strip-to-mpeg2 needs this comment */
	@$(MAKE) USE_AFSP=1 TARGET="libisoaac.a"                 OBJS="$(AAC_OBJS_ALL)"  clean_mode

else # ifeq "$(MAKELEVEL)" "0"

clean_mode:
	@$(MAKE) USE_AFSP=$(USE_AFSP) TARGET="$(TARGET)" OBJS="$(OBJS)" clean

endif # ifeq "$(MAKELEVEL)" "0"
