############################################################################
#
# Copyright (c) 2008-2016 Telchemy, Incorporated. All Rights Reserved.
#
# Telchemy Confidential and Proprietary
#
# The following software source code ("Software") is strictly confidential
# and is proprietary to Telchemy, Incorporated ("Telchemy").  It may only
# be read, used, copied, adapted, modified or otherwise utilized by parties
# (individuals, corporations, or organizations) that have entered into a
# license agreement or confidentiality agreement with Telchemy, and are thus
# subject to the terms of that license agreement or confidentiality agreement
# and any other applicable agreement between the party and Telchemy.  If
# there is any doubt as to whether a party is entitled to access, read, use,
# copy, adapt, modify or otherwise utilize the Software, or whether a party
# is entitled to disclose the Software to any other party, you should contact
# Telchemy.  If you, as a party, have not entered into a license agreement or
# confidentiality agreement with Telchemy granting access to this Software,
# all media, copies and printed listings containing the Software should be
# forthwith returned to Telchemy.
#
# Telchemy reserves the right to take legal action against any party that
# violates Telchemy's rights to the Software, including without limitation a
# party's breach of the above conditions.
#
# If you have questions about any of the above conditions, or wish to report
# violations, please contact:  support@telchemy.com
#
############################################################################

#
# VQmon Sample Host Application Makefile (GNU make)
#
# Copyright (c) 2008-2016 Telchemy, Incorporated
#

#-------------------------------------------------------------------------
# Target OS/Architecture-Specific Build Options
#-------------------------------------------------------------------------
-include ../../config/vqbldcfg.inc

CFLAGS          = $(CFLAGS_OPTS) $(CFLAGS_DEFS) $(CFLAGS_INCS)

#-------------------------------------------------------------------------
# Directories
#-------------------------------------------------------------------------
OBJDIR          = ./obj
VQMON_INCDIR  = ../../include
VQMON_CONFDIR = ../../config
VQMON_LIBDIR  = ../../lib
VPATH           = $(OBJDIR)

#-------------------------------------------------------------------------
# Build Target Definitions
#-------------------------------------------------------------------------
TARGETNAME     := voipsim
TARGETDESC      = "VQmon VoIP Sample Application"
TARGETSRC       = voipsim.c
TARGETDEPS      =
TARGETOBJ       = $(TARGETSRC:.c=.o)

VQMONLIB 	= $(VQMON_LIBDIR)/libvqmon.a

ifeq ($(TARGET_OS),osx-darwin)
CFLAGS_OPTS    += -framework CoreFoundation -framework IOKit
endif

#-------------------------------------------------------------------------
# Compiler Options
#-------------------------------------------------------------------------
CFLAGS_INCS    += -I. -I$(VQMON_INCDIR) -I$(VQMON_CONFDIR)
ifdef DEBUG
CFLAGS_OPTS    += $(CFLAGS_DBG)
else
CFLAGS_OPTS    += $(CFLAGS_REL)
endif

#-------------------------------------------------------------------------
# Debug vs. Release Versions
#-------------------------------------------------------------------------
ifdef DEBUG
BUILDMSG 	= "- DEBUG Build"
VQMONBLD 	= debug
else
BUILDMSG 	= "- RELEASE Build"
VQMONBLD 	= release
endif

#-------------------------------------------------------------------------
# Target Build Dependencies
#-------------------------------------------------------------------------

.c.o :
	@echo "$<"
	@$(CC) $(CFLAGS) -o $(OBJDIR)/$(@F) -c $<

$(TARGETNAME): preproc $(TARGETDEPS) $(VQMONLIB) $(TARGETOBJ)
	@echo "./$@"
	@$(CC) $(CFLAGS_OPTS) -o $(TARGETNAME) \
	    $(foreach file,$(TARGETOBJ),$(OBJDIR)/$(notdir $(file))) \
	    $(VQMONLIB)
	@echo

$(VQMONLIB):
	@if [ -e "$(VQMON_LIBDIR)/../Makefile" ]; then \
	    $(MAKE) $(MAKEOPTS) -C $(VQMON_LIBDIR)/.. $(MAKEDEFS) \
	    $(VQMON_BUILDOPTS) $(VQMONBLD); fi

preproc:
	@echo ""
	@echo "Building the $(TARGETDESC) $(BUILDMSG)"
	@echo "-------------------------------------------------------------------------"
	@if [ ! -d "$(OBJDIR)" ]; then mkdir $(OBJDIR); fi

clean_build_intermediate_artifacts:
	@echo ""
	@echo "Cleaning the $(TARGETDESC) build tree"
	@echo "-------------------------------------------------------------------------"
	@rm -Rf $(OBJDIR)/*.o $(TARGETNAME)
	@echo "Clean build complete."
	@echo ""
