# Copyright 2008 Castle Technology Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile fragment for C and C++ applications to run on the build host

INCLUDED_HOSTAPP = YES

#
# This makefile provides the following phony targets:
#
#    all  clean
#
#
# This fragment uses the following macros set by the master makefile.
#
#
# COMPONENT                 (the name of the component)
# TARGET              (opt) (the leafname of the application - otherwise ${COMPONENT})
# DIRS                (opt) (stamp object for directory creation - otherwise o._dirs)
# OBJS                (opt) (object files, no o. prefixes - otherwise ${TARGET})
# APP_OBJS            (opt) (release build object files, no prefixes - otherwise ${OBJS})
# LIBS                (opt) (extra libraries; ${CLIB} is always used)
# APP_LIBS            (opt) (extra release libraries - otherwise ${LIBS}; ${CLIB} is always used)
# LINK_TYPE           (opt) (variant of linking command, eg C++ - defaults to C)
# CUSTOMLINK          (opt) (set to "custom" to override the link rule)
#
#
# It relies on the following generic tool macros from the StdTools makefile
#
#
#C + CFLAGS       (C compiler; CDFLAGS also used in debug builds; -g implicit)
# CP + CPFLAGS     (copy, cp etc.)
# WIPE + WFLAGS    (recursive delete)
# RM               (non-recursive delete)
# AS + ASFLAGS     (assembler)
# LD + LDFLAGS     (linker; LDDFLAGS also used in debug builds; -d implicit)
# SQZ + SQZFLAGS   (binary compressor)
# MKDIR            (cdir/mkdir -p)
# ECHO
# TOUCH            (create/touch)
#
#
# It relies on the following from the StdRules makefile
#
#
# .c.o  .c++.o  .cpp.o  .s.o
#
#

INSTALLDIR    = <Install$Dir>

CLIB      = <Build$HostLibs>.CLib.o.stubs
C++LIB    = <Build$HostLibs>.C++Lib.o.c++lib

TARGET       ?= ${COMPONENT}
DIRS         ?= o._dirs
OBJS         ?= ${TARGET}
APP_OBJS     ?= ${OBJS}
APP_LIBS     ?= ${LIBS}
ifeq (C++,${LINK_TYPE})
APP_LIBS     += ${C++LIB}
endif
APP_LIBS     += ${CLIB}

APP_OBJS_     = $(addprefix o.,${APP_OBJS})

ifeq ("${INCLUDED_HOSTTOOLS}","")
include HostTools
endif

ifeq ("${INCLUDED_STDRULES}","")
include StdRules
endif

all: ${TARGET}
        @${ECHO} ${COMPONENT}: host application built

${DIRS} ::
        ${MKDIR} o
        ${TOUCH} $@

clean ::
        @IfThere o  Then ${ECHO} ${WIPE} o ${WFLAGS}
        @IfThere o  Then ${WIPE} o ${WFLAGS}
        ${RM} ${TARGET}
        @${ECHO} ${COMPONENT}: cleaned

${TARGET}${CUSTOMLINK}: ${APP_OBJS_} ${APP_LIBS} ${DIRS}
        ${LD} ${LDFLAGS} -o ${TARGET} ${APP_OBJS_} ${APP_LIBS}
        ${SQZ} ${SQZFLAGS} $@

# EOF
