#
#  Copyright (C) 2017 A Little Slice of MangOH and Renfell Engineering Pty Ltd - All Rights Reserved
#  
#  Use of this work is subject to license and solely for use with hardware
#  supplied by Renfell Engineering Pty Ltd.
#  
#  Proprietary and confidential.
#  This file or any part thereof may not be used, distributed, copied, or 
#  modified for use for any purpose other than that for which it was 
#  originally provided without first receiving written permission of the
#  copyright holder.
#  
#  This source code is provided 'as is' without warranty of any kind, either
#  expressed or implied by consumer legislation or otherwise, including but 
#  not limited to the implied warranties of merchantability and/or fitness 
#  for a particular purpose.
#  
#  The end user acknowledges that this software is a "work in progress", and
#  as such should not be relied upon in a commercial environment or other
#  situations where economic loss or harm to persons may arise due to a
#  failure to perform to the end users specific requirements.
#  
#  By use of this software you agree to the use of the above terms.
#  
# 

# Uncomment if debug wanted
#DEBUG:=true

# Application name (name of adef file)
APPLICATION:=complexBlinky

# application includes (for mkapp) - where to find things like API files
#APPLICATION_INCLUDES:= -i reMangOH

# application sources (for mkapp) - where to find non-standard sources
APPLICATION_SOURCES:=

# airvantage application name - must be unique to airvantage
AIRVANTAGE_NAME:=$(APPLICATION)

# mangOH Device IP
DEVICEIP:=192.168.2.2

# Define LEGATO_ROOT
# uncomment following line to use custom LEGATO_ROOT
#LEGATO_ROOT:=/home/developer/legato-16.07.0

# Define target type
TARGET:=wp85

# set some parameters if DEBUG mode
ifdef DEBUG
MKAPPFLAGS:=-C -g -X -g -L -g
APPDBG:=.debug
else
MKAPPFLAGS:=
APPDBG:=
endif

# Target artifact.*
TARGET_ARTIFACT:=$(APPLICATION)$(APPDBG).$(TARGET).update

# WORKING Directory for MKCOMMAND
WORKING_DIR:=_BUILD_.$(TARGET).$(APPLICATION)$(APPDBG)

# Clean commands
CLEAN:=rm -f
CLEANDIR:=rm -rf


# MK command
MKCOMMAND:=mkapp -t $(TARGET) -w $(WORKING_DIR) \
	-i "$(LEGATO_ROOT)/interfaces/wifi" \
	-i "$(LEGATO_ROOT)/interfaces/positioning" \
	-i "$(LEGATO_ROOT)/interfaces/secureStorage" \
	-i "$(LEGATO_ROOT)/interfaces/modemServices" \
	-i "$(LEGATO_ROOT)/interfaces/logDaemon" \
	-i "$(LEGATO_ROOT)/interfaces/supervisor" \
	-i "$(LEGATO_ROOT)/interfaces/airVantage" \
	-i "$(LEGATO_ROOT)/interfaces/atServices" \
	-i "$(LEGATO_ROOT)/interfaces" \
	$(APPLICATION_INCLUDES) \
	-s "." \
	-s "$(LEGATO_ROOT)/components" \
	$(APPLICATION_SOURCES) \
	$(MKAPPFLAGS) \
	$(APPLICATION).adef

.PHONY: all target clean airvantage install start status stop

all: clean target airvantage

target: 
	$(MKCOMMAND)

clean:
	$(CLEANDIR) $(WORKING_DIR)
	$(CLEAN) *.update *.$(TARGET) $(AIRVANTAGE_NAME).zip manifest.* mktool* *.so *.ninja* .ninja*

airvantage: target
	av-pack -f $(TARGET_ARTIFACT) $(AIRVANTAGE_NAME)

install: target
	@echo "installing $(TARGET_ARTIFACT) to $(DEVICEIP)" ; \
	app install $(TARGET_ARTIFACT) $(DEVICEIP) 
	
start:
	app start $(APPLICATION) $(DEVICEIP)

stop:
	app stop $(APPLICATION) $(DEVICEIP)

status:
	app status $(APPLICATION) $(DEVICEIP)

sshclean:
	ssh-keygen -f "$(HOME)/.ssh/known_hosts" -R 192.168.2.2

