##############################################################
# (C) 2015 BAE SYSTEMS
#
# ECOA Dining Philosophers Sample - Master makefile
#
# $Id: Makefile,v 2.6 2017/11/06 15:33:40 ksappleb Exp $
#
# Part of the BAE Systems, Rochester, ECOA Samples collection
#
# Created by K S Appleby, BAE Systems, Airport Works, Rochester, Kent
#
# This software is developed for and on behalf of BAE Systems (Operations)
# Limited, Dassault Aviation, Bull SAS, Thales Systemes Aeroportes,
# GE Aviation Systems Limited,
# General Dynamics United Kingdom Limited and Leonardo MW Ltd,
# and the copyright is owned by BAE Systems (Operations) Limited,
# Dassault Aviation, Bull SAS, Thales Systemes Aeroportes, 
# Limited, GE Aviation Systems Limited, General Dynamics United Kingdom
# Limited and Leonardo MW Ltd
#
# This software is developed by BAE Systems (Operations)
# Limited, Electronic Systems, and is the Intellectual
# Property of BAE Systems (Operations) Limited, Electronic Systems.
#
# The information set out in this document is provided solely
# on an 'as is' basis and the co-developers of this software make
# no warranties expressed or implied, including no warranties
# as to completeness, accuracy or fitness for purpose, with respect
# to any of the information.
##############################################################

include ../Common/CGDefs

###############################################################################

ifndef BLDTARGET
  BLDTARGET=linux
endif

###############################################################################

# Common flag values
CPPFLAGS+=-g -Wall
CC=gcc $(CPPFLAGS)
LD=gcc
LDLIBS+=

# Platform specific values
ifeq ($(BLDTARGET),wingcc)
  LDMAP=-Wl,-Map,$(basename $$@).map
endif
ifeq ($(BLDTARGET),wingcc32)
  CC=i686-pc-cygwin-gcc $(CPPFLAGS)
  LD=$(CC)
  LDMAP=-Wl,-Map,$(basename $$@).map
endif
ifeq ($(BLDTARGET),linux)
  LDLIBS+=-lrt -lpthread
  LDMAP=-Wl,-M>$(basename $$@).map
endif
ifeq ($(BLDTARGET),raspi)
  LDLIBS+=-lrt -lpthread
  LDMAP=-Wl,-M>$(basename $$@).map
endif
ifeq ($(BLDTARGET),mingw32)
  CPPFLAGS=-g -Wall -I../../../../../mingw32sup -Dmode_t="unsigned short" -D_MODE_T_ -D_USE_32BIT_TIME_T  
  CC=i686-pc-mingw32-gcc $(CPPFLAGS)
  LD=$(CC)
  LDMAP=-Wl,-Map,$(basename $$@).map
endif
ifeq ($(BLDTARGET),VXW)
  include ../Makedefs/Makedefs.vxw
  ADDED_CFLAGS+=-D_Bool=dmy
  LDMAP=-Wl,-M>$(basename $$@).map
endif

###############################################################################

all : components
#   Build the PD (executable)...
	make -C Steps/output/host/cpu/Restaurant -$(MAKEFLAGS) CC='$(CC)' LD='$(LD) $(LDFLAGS)' LDLIBS='$(LDLIBS)'
ifeq ($(BLDTARGET),VXW)
	cp Steps/output/host/cpu/Restaurant/Restaurant $(BOOTHOST)/ECOA/samples/
endif

components :
#	Build the ECOA ASC
	make -C Steps/4-ComponentImplementations -$(MAKEFLAGS) CC='$(CC)'

###############################################################################

cgASC :
	$(APIGEN) ./Steps
# Build ASCs
	make -$(MAKEFLAGS) components

cg : ./Steps/5-Integration/hostbased.logical-system.xml ./Steps/5-Integration/maiIDs.xml
	$(PFGEN) ./Steps
	make -$(MAKEFLAGS) all
	
./Steps/5-Integration/maiIDs.xml : ./Steps/5-Integration/Restaurant.deployment.xml ./Steps/5-Integration/Restaurant.impl.composite
	$(UIDGEN) ./Steps

./Steps/5-Integration/hostbased.logical-system.xml : ./Steps/5-Integration/LogicalSystems/gp2host.logical-system.xml ./Steps/5-Integration/LogicalSystems/pchost.logical-system.xml
ifeq ($(BLDTARGET),VXW)
	cp ./Steps/5-Integration/LogicalSystems/gp2host.logical-system.xml ./Steps/5-Integration/hostbased.logical-system.xml
else
	cp ./Steps/5-Integration/LogicalSystems/pchost.logical-system.xml ./Steps/5-Integration/hostbased.logical-system.xml
endif

###############################################################################

clean:
	make -C Steps/4-ComponentImplementations clean
	make -C Steps/output/host/cpu/Restaurant clean
		