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

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

TOTAL_PATH_ADD =

ifndef SPATIALAUDIO
SPATIALAUDIO=1
endif

ifndef SPATIAL_EMBED_STUDY_ON
SPATIAL_EMBED_STUDY_ON=1
endif


ifndef PARTIALLY_COMPLEX
PARTIALLY_COMPLEX = 0
endif

ifndef HRTF_DYNAMIC_UPDATE
HRTF_DYNAMIC_UPDATE=1
endif

ifneq "$(PARTIALLY_COMPLEX)" "0"
TOTAL_PATH_ADD += lpmps
endif


#EXTERNLIBS += -lmp4spatialdec
#REFSOFT_LIBRARY_PATH = ../lib/mp4spatialdec/Linux_gcc_O0d

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

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

TOTAL_PATH_ADD += sbr

ifndef LOW_POWER_SBR
LOW_POWER_SBR=0
endif

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

ifndef PARAMETRICSTEREO
PARAMETRICSTEREO=1
endif

ifneq "$(PARAMETRICSTEREO)" "0"
TOTAL_PATH_ADD += ps
endif

ifndef USE_AFSP
USE_AFSP = 1
endif

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

ifneq  "$(MAKELEVEL)" "0"

override ADDONDIR = $(TOTAL_PATH_ADD)
#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
ifneq "$(ISOMP4)" "0"
ADDONOBJDIR = _mp4
override DEFFLAGS += -DMPEG4V1
else
#endif          /* strip-to-mpeg2 needs this comment */
ADDONOBJDIR = _aac
#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
endif
#endif          /* strip-to-mpeg2 needs this comment */

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

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


MPS_CONF_OBJS = audiofile_io.o \
                conf_bitdec.o \
                decoderConfTool.o \
                diff_pcm.o \
                downmix_parser.o \
                mps_decoder.o \
                qmf_inverseFilter.o \
                sbrmps_decoder.o

override DEFFLAGS += -DCT_SBR
ifeq "$(LOW_POWER_SBR)" "1"
override DEFFLAGS += -DLOW_POWER_SBR
endif

ifeq "$(SPATIAL_EMBED_STUDY_ON)" "1"
override DEFFLAGS += -DSPATIAL_EMBED_STUDY_ON
endif

ifeq "$(PARTIALLY_COMPLEX)" "1"
override DEFFLAGS += -DPARTIALLY_COMPLEX
endif

ifeq "$(HRTF_DYNAMIC_UPDATE)" "1"
override DEFFLAGS += -DHRTF_DYNAMIC_UPDATE
endif

ifeq "$(PARAMETRICSTEREO)" "1"
override DEFFLAGS += -DPARAMETRICSTEREO
endif

ifeq "$(SPATIALAUDIO)" "1"
COMLIBS += -lmp4spatialdec
override DEFFLAGS += -DSPATIALAUDIO
override INCL += -I../mp4spatialdec/src
override INCL += -I../mp4spatialdec/include
endif

#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
ifeq "$(ISOMP4)" "1"
COMLIBS_isoaac = -lisoaac_mp4
else
#endif
COMLIBS_isoaac = -lisoaac
#ifdef MPEG4V1  /* strip-to-mpeg2 needs this comment */
endif
#endif

SRCDIRS = src

OPTIONS = $(MFLAGS) SRCDIRS="$(SRCDIRS)" USE_AFSP=$(USE_AFSP) COMLIBS="$(COMLIBS)" EXTERNLIBS="$(EXTERNLIBS)" DEFFLAGS="$(DEFFLAGS)" LIBS="$(LIBS)" INCL="$(INCL)" INCLDEP=1

.PHONY: all allafsp mps_conftool mps_conftool_lp clean

ifeq "$(LOW_POWER_SBR)" "1"  # explicit LP
all: mps_conftool
else
all: mps_conftool mps_conftool_lp
endif

mps_conftool:
	@$(MAKE) TORTURE_TEST=0 SPATIAL_EMBED_STUDY_ON=1 $(OPTIONS) TARGET=$@ COMLIBS="$(COMLIBS_isoaac) $(COMLIBS)" OBJS="$(MPS_CONF_OBJS)" binary

mps_conftool_lp:
	@$(MAKE) LOW_POWER_SBR=1 PARTIALLY_COMPLEX=1 TORTURE_TEST=0 SPATIAL_EMBED_STUDY_ON=1 $(OPTIONS) TARGET=$@ COMLIBS="$(COMLIBS_isoaac) $(COMLIBS)" OBJS="$(MPS_CONF_OBJS)" binary
# unfortunaltely, the recursive approach (next line) seems to stuble over MAKELEVEL issues
#	@$(MAKE) LOW_POWER_SBR=1 PARTIALLY_COMPLEX=1 mps_conftool

ifeq "$(MAKELEVEL)" "0"

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

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

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

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