# 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++ modules targetted at RAM.

INCLUED_RAMCMODULE = YES

#
# $Id$
#
# This makefile provides the following phony targets:
#
#    all     install
#
#
# This fragment uses the following macros set by the master makefile.
#
#
# COMPONENT        (the name of the component)
# TARGET     (opt) (the leafname of the component - otherwise ${COMPONENT})
# RAM_OBJS   (opt) (component's object files for romming - otherwise ${OBJS})
# RAM_LIBS   (opt) (libraries to link to generate RAM_MODULE - otherwise ${LIBS})
# RAM_MODULE (opt) (output filename for module - otherwise rm.${TARGET}
# DIRS       (opt) (magic target to ensure object directories are present)
# CLIB             (C library)
# RAM_DEPEND (opt) (any extra dependency to assert on ${RAM_MODULE}
#
#
# It relies on the following from the build system:
#
#
# INSTDIR          (installation directory for ROM_MODULE)
# PHASE            (export phase discriminator)
#
#
# It relies on the following generic tool macros from the Tools makefile
#
# CP + CPFLAGS     (copy, cp etc.)
# AS + ASFLAGS     (assembler)
# MKDIR            (cdir/mkdir -p)
# ECHO
# LD + LDFLAGS     (linker)
# LDRAMFLAGS       (more linker flags)
# MODSQZ +
#   MODSQZFLAGS    (module squeezer)
#

TARGET     ?= ${COMPONENT}
RAM_MODULE ?= rm.${TARGET}
RAM_OBJS   ?= ${OBJS}
RAM_LIBS   ?= ${LIBS}

#
# RISC OS ROM build rules:
#
all: ${RAM_MODULE}
        @${ECHO} ${COMPONENT}: ram module built

install: ${RAM_MODULE}
        ${MKDIR} ${INSTDIR}
        ${CP} ${RAM_MODULE} ${INSTDIR}.${TARGET} ${CPFLAGS}
        @${ECHO} ${COMPONENT}: ram module installed

#
# Actually make the linked RAM target 
#
${RAM_MODULE}: ${RAM_OBJS} ${RAM_LIBS} ${CLIB} ${DIRS} ${RAM_DEPEND}
        ${MKDIR} rm
        ${LD} ${LDFLAGS} ${LDRAMFLAGS} -o $@ -rmf ${RAM_OBJS} ${RAM_LIBS} ${CLIB}
        ${MODSQZ} ${MODSQZFLAGS} $@
        ${CHMOD} -R a+rx rm


EOFSTDMAKFILE=$Id$
# EOF