#
#   Copyright (c) 2016-2018 Texas Instruments Incorporated - http://www.ti.com
#
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions
#   are met:
#
#   *  Redistributions 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 the distribution.
#
#   *  Neither the name of Texas Instruments Incorporated nor the names of
#      its 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 OWNER 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, 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.
#
#
#  ======== makefile ========
#

help:
	@echo "make release"
	@echo "make clobber"
	@echo "make DRA7XX_bios_elf"
	@echo "make AM572X_bios_elf"
	@echo "make AM571X_linux_elf"
	@echo "make DRA7XX_qnx_elf"
	@echo "make DRA7XX_android_elf"
	@echo "make TI814X_bios_elf"
	@echo "make C6A8149_bios_elf"
	@echo "make OMAPL138_linux_elf"
	@echo "make OMAP54XX_qnx_elf"
	@echo "make OMAP54XX_linux_elf"
	@echo "make C6472_bios_elf"
	@echo "make C6678_bios_elf"
	@echo "make TDA3XX_bios_elf"
	@echo "make TCI6638_linux_elf"
	@echo "make TCI6636_bios_elf"
	@echo "make TCI6636_linux_elf"
	@echo "make 66AK2E_bios_elf"
	@echo "make 66AK2E_linux_elf"
	@echo "make 66AK2G_bios_elf"
	@echo "make 66AK2G_linux_elf"
	@echo "make TCI6630_bios_elf"
	@echo "make TCI6630_linux_elf"
	@echo "make AM65XX_bios_elf"
	@echo "make AM65XX_linux_elf"

release:


ifeq ($(PLATFORM),$(filter $(PLATFORM),DRA7XX *))
release: DRA7XX_bios_elf
release: DRA7XX_linux_elf
release: DRA7XX_qnx_elf
release: DRA7XX_android_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),AM572X *))
release: AM572X_bios_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),AM571X *))
release: AM571X_bios_elf
endif
#release: TI814X_bios_elf
#release: C6A8149_bios_elf
ifeq ($(PLATFORM),$(filter $(PLATFORM),OMAPL138 *))
release: OMAPL138_linux_elf
endif
#release: OMAP54XX_qnx_elf
#release: OMAP54XX_linux_elf
#release: C6472_bios_elf
ifeq ($(PLATFORM),$(filter $(PLATFORM),C6678 *))
release: C6678_bios_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),TDA3XX *))
release: TDA3XX_bios_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),TCI6638 *))
release: TCI6638_linux_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),TCI6636 *))
release: TCI6636_bios_elf
release: TCI6636_linux_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),66AK2E *))
release: 66AK2E_bios_elf
release: 66AK2E_linux_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),66AK2G *))
release: 66AK2G_bios_elf
release: 66AK2G_linux_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),TCI6630 *))
release: TCI6630_bios_elf
release: TCI6630_linux_elf
endif
ifeq ($(PLATFORM),$(filter $(PLATFORM),AM65XX *))
release: AM65XX_bios_elf
release: AM65XX_linux_elf
endif

%_ex01_hello:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex01_hello .zip
%_ex02_messageq:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex02_messageq .zip
%_ex11_ping:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex11_ping .zip
%_ex12_mmrpc:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex12_mmrpc .zip
%_ex13_notifypeer:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex13_notifypeer .zip
%_ex41_forwardmsg:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex41_forwardmsg .zip
%_ex44_compute:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex44_compute .zip
%_ex45_host:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex45_host .zip
%_ex46_graph:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex46_graph .zip
%_ex67_buffer:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex67_buffer .zip
%_ex68_power:
	@$(MAKE) PLATFORM_DIR_NAME=$(P) HOSTOS=$(O) NAME=ex68_power .zip


DRA7XX_bios_elf: P=DRA7XX_bios_elf
DRA7XX_bios_elf: O=bios
DRA7XX_bios_elf: DRA7XX_bios_elf_ex01_hello
DRA7XX_bios_elf: DRA7XX_bios_elf_ex02_messageq
DRA7XX_bios_elf: DRA7XX_bios_elf_ex11_ping
DRA7XX_bios_elf: DRA7XX_bios_elf_ex13_notifypeer

DRA7XX_linux_elf: P=DRA7XX_linux_elf
DRA7XX_linux_elf: O=linux
DRA7XX_linux_elf: DRA7XX_linux_elf_ex02_messageq
DRA7XX_linux_elf: DRA7XX_linux_elf_ex12_mmrpc
DRA7XX_linux_elf: DRA7XX_linux_elf_ex41_forwardmsg
DRA7XX_linux_elf: DRA7XX_linux_elf_ex68_power

DRA7XX_qnx_elf: P=DRA7XX_qnx_elf
DRA7XX_qnx_elf: O=qnx
DRA7XX_qnx_elf: DRA7XX_qnx_elf_ex02_messageq
DRA7XX_qnx_elf: DRA7XX_qnx_elf_ex41_forwardmsg
DRA7XX_qnx_elf: DRA7XX_qnx_elf_ex12_mmrpc
DRA7XX_qnx_elf: DRA7XX_qnx_elf_ex67_buffer

DRA7XX_android_elf: P=DRA7XX_android_elf
DRA7XX_android_elf: O=android
DRA7XX_android_elf: DRA7XX_android_elf_ex02_messageq

AM572X_bios_elf: P=AM572X_bios_elf
AM572X_bios_elf: O=bios
AM572X_bios_elf: AM572X_bios_elf_ex02_messageq
AM572X_bios_elf: AM572X_bios_elf_ex11_ping

AM571X_bios_elf: P=AM571X_bios_elf
AM571X_bios_elf: O=bios
AM571X_bios_elf: AM571X_bios_elf_ex02_messageq
AM571X_bios_elf: AM571X_bios_elf_ex11_ping

TI814X_bios_elf: P=TI814X_bios_elf
TI814X_bios_elf: O=bios
TI814X_bios_elf: TI814X_bios_elf_ex11_ping

C6A8149_bios_elf: P=C6A8149_bios_elf
C6A8149_bios_elf: O=bios
C6A8149_bios_elf: C6A8149_bios_elf_ex11_ping

C6472_bios_elf: P=C6472_bios_elf
C6472_bios_elf: O=bios
C6472_bios_elf: C6472_bios_elf_ex11_ping

C6678_bios_elf: P=C6678_bios_elf
C6678_bios_elf: O=bios
C6678_bios_elf: 6678_bios_elf_ex11_ping

OMAPL138_linux_elf: P=OMAPL138_linux_elf
OMAPL138_linux_elf: O=linux
OMAPL138_linux_elf: OMAPL138_linux_elf_ex11_ping
OMAPL138_linux_elf: OMAPL138_linux_elf_ex02_messageq

OMAP54XX_qnx_elf: P=OMAP54XX_qnx_elf
OMAP54XX_qnx_elf: O=qnx
OMAP54XX_qnx_elf: OMAP54XX_qnx_elf_ex12_mmrpc
OMAP54XX_qnx_elf: OMAP54XX_qnx_elf_ex02_messageq

OMAP54XX_linux_elf: P=OMAP54XX_linux_elf
OMAP54XX_linux_elf: O=linux
OMAP54XX_linux_elf: OMAP54XX_linux_elf_ex12_mmrpc
OMAP54XX_linux_elf: OMAP54XX_linux_elf_ex02_messageq

TDA3XX_bios_elf: P=TDA3XX_bios_elf
TDA3XX_bios_elf: O=bios
TDA3XX_bios_elf: TDA3XX_bios_elf_ex11_ping

TCI6638_linux_elf: P=TCI6638_linux_elf
TCI6638_linux_elf: O=linux
TCI6638_linux_elf: TCI6638_linux_elf_ex44_compute
TCI6638_linux_elf: TCI6638_linux_elf_ex45_host
TCI6638_linux_elf: TCI6638_linux_elf_ex46_graph
TCI6638_linux_elf_ex46_graph: TCI6638_linux_elf_ex45_host

TCI6636_bios_elf: P=TCI6636_bios_elf
TCI6636_bios_elf: O=bios
TCI6636_bios_elf: TCI6636_bios_elf_ex11_ping
TCI6636_bios_elf: TCI6636_bios_elf_ex02_messageq

TCI6636_linux_elf: P=TCI6636_linux_elf
TCI6636_linux_elf: O=linux
TCI6636_linux_elf: TCI6636_linux_elf_ex02_messageq

66AK2E_bios_elf: P=66AK2E_bios_elf
66AK2E_bios_elf: O=bios
66AK2E_bios_elf: 66AK2E_bios_elf_ex11_ping
66AK2E_bios_elf: 66AK2E_bios_elf_ex02_messageq

66AK2E_linux_elf: P=66AK2E_linux_elf
66AK2E_linux_elf: O=linux
66AK2E_linux_elf: 66AK2E_linux_elf_ex02_messageq

66AK2G_bios_elf: P=66AK2G_bios_elf
66AK2G_bios_elf: O=bios
66AK2G_bios_elf: 66AK2G_bios_elf_ex11_ping
66AK2G_bios_elf: 66AK2G_bios_elf_ex02_messageq

66AK2G_linux_elf: P=66AK2G_linux_elf
66AK2G_linux_elf: O=linux
66AK2G_linux_elf: 66AK2G_bios_linux_ex02_messageq

TCI6630_bios_elf: P=TCI6630_bios_elf
TCI6630_bios_elf: O=bios
TCI6630_bios_elf: TCI6630_bios_elf_ex11_ping
TCI6630_bios_elf: TCI6630_bios_elf_ex02_messageq

TCI6630_linux_elf: P=TCI6630_linux_elf
TCI6630_linux_elf: O=linux
TCI6630_linux_elf: TCI6630_linux_elf_ex02_messageq

AM65XX_bios_elf: P=AM65XX_bios_elf
AM65XX_bios_elf: O=bios
AM65XX_bios_elf: AM65XX_bios_elf_ex11_ping
AM65XX_bios_elf: AM65XX_bios_elf_ex02_messageq

AM65XX_linux_elf: P=AM65XX_linux_elf
AM65XX_linux_elf: O=linux
AM65XX_linux_elf: AM65XX_linux_elf_ex02_messageq

.zip:
	@echo "#"
	@echo "# Making $@ ..."
	$(XDC_INSTALL_DIR)/xs --xdcpath="$(IPCTOOLS)/packages;." \
            ti.ipc.utils.genbundle $(PLATFORM_DIR_NAME)_$(HOSTOS)_$(NAME)_out $(NAME) \
            $(NAME) \
            platform=$(PLATFORM_DIR_NAME) \
            hostos=$(HOSTOS)
	mkdir -p ../$(PLATFORM_DIR_NAME)
	cd $(PLATFORM_DIR_NAME)_$(HOSTOS)_$(NAME)_out/; \
            zip -r ../../$(PLATFORM_DIR_NAME)/$(NAME).zip $(NAME)
	@rm -rf $(PLATFORM_DIR_NAME)_$(HOSTOS)_$(NAME)_out

clobber:
	@echo "#"
	@echo "# Making $@ ..."
	rm -rf ../OMAP*
	rm -rf ../TI81*
	rm -rf ../C6A81*
	rm -rf ../VAYU*
	rm -rf ../DRA7XX*
	rm -rf ../AM572X*
	rm -rf ../AM571X*
	rm -rf ../C6472*
	rm -rf ../C6678*
	rm -rf ../TDA3XX*
	rm -rf ../TCI6638*
	rm -rf ../TCI6636*
	rm -rf ../66AK2E*
	rm -rf ../66AK2G*
	rm -rf ../TCI6630*
	rm -rf ../AM65XX*
