CApp 5.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# 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
#
# $Id$
#
# This makefile provides the following phony targets:
#
#    all  install  debug
#
#
# 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})
# DBG_TARGET   (opt) (debug application leafname - otherwise ${TARGET}-D)
# INSTDIR      (opt) (the target directory - otherwise <Install$Dir>.${TARGET})
# DIRS         (opt) (stamp object for directory creation - otherwise o._dirs)
# OBJS         (opt) (object files, no o. prefixes - otherwise ${TARGET})
# DBG_OBJS     (opt) (debug build object files, no prefixes - otherwise ${OBJS})
# LIBS         (opt) (extra libraries; CLib is always used)
# DBG_LIBS     (opt) (extra debug libraries - otherwsie ${LIBS};
#                     CLib and DEBUGLIBS always used)
# APP_OBJS     (opt) (object files for application version - otherwise derived
#                     from ${OBJS})
# APP_DBG_OBJS (opt) (object files for debug app version - otherwise derived
#                     from ${DBG_OBJS})
41 42 43 44 45 46 47
# CLEAN_DEPEND (opt) (phony target for additional clean actions)
# LINK_TYPE    (opt) (variant of linking command, eg C++ - defaults to C)
# INSTTYPE     (opt) (use "tool" or "app" to install executable vs application - defaults to "tool")
# INSTALLAPPFILES   (opt) (list of files to be installed in application directory - use InstRes specification rules)
# INSTALLAPP_DEPEND (opt) (list of dependencies to be satisfied before doing application install - ${TARGET} assumed if in INSTALLAPPFILES)
# CUSTOMINSTALLAPP  (opt) (set to "custom" to override the install rule for resource files)
# CUSTOMINSTALLTOOL (opt) (set to "custom" to override the install rule for target binary)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#
#
# 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
#
#
# It relies on the following from the DbgRules makefile
#
#
# CDFLAGS  C++DFLAGS  ASDFLAGS  LDDFLAGS
# .c.od  .c++.od  .cpp.od  .s.od
#
#

INSTALLDIR    = <Install$Dir>

TARGET       ?= ${COMPONENT}
DBG_TARGET   ?= ${TARGET}-D
INSTDIR      ?= ${INSTALLDIR}.${TARGET}
DIRS         ?= o._dirs
OBJS         ?= ${TARGET}
DBG_OBJS     ?= ${OBJS}
DBG_LIBS     ?= ${LIBS}
88 89 90 91
ifeq (C++,${LINK_TYPE})
LIBS         += ${C++LIB}
DBG_LIBS     += ${C++LIB}
endif
92 93 94 95 96 97 98 99 100 101 102 103 104
LIBS         += ${CLIB}
DBG_LIBS     += ${DEBUGLIBS} ${CLIB}
APP_OBJS     ?= $(addprefix o.,${OBJS})
APP_DBG_OBJS ?= $(addprefix od.,${DBG_OBJS})

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

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

105
clean ::  ${CLEAN_DEPEND}
106 107 108 109 110 111 112 113
        @IfThere o  Then ${ECHO} ${WIPE} o ${WFLAGS}
        @IfThere o  Then ${WIPE} o ${WFLAGS}
        @IfThere od Then ${ECHO} ${WIPE} od ${WFLAGS}
        @IfThere od Then ${WIPE} od ${WFLAGS}
        ${RM} ${TARGET}
        ${RM} ${DBG_TARGET}
        @${ECHO} ${COMPONENT}: cleaned

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
install: install_${INSTTYPE}

install_: install_tool

INSTALLAPP_DEPEND += $(filter ${TARGET},${INSTALLAPPFILES})

install_app${CUSTOMINSTALLAPP}: ${INSTALLAPP_DEPEND}
        ${MKDIR} ${INSTAPP}
        ${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${INSTAPP} ${INSTALLAPPFILES}
ifneq (,$(filter Desc,${INSTALLAPPFILES}))
        ${CPREPRO} -I. ${INSTAPP}.Desc > ${INSTAPP}.DescTmp
        ${TIDYDESC} ${INSTAPP}.Desc ${INSTAPP}.DescTmp
        ${RM} ${INSTAPP}.DescTmp
endif
        @${ECHO} ${COMPONENT}: application installation complete

install_tool${CUSTOMINSTALLTOOL}: ${TARGET}
131 132
        ${MKDIR} ${INSTDIR}
        ${CP} ${TARGET} ${INSTDIR}.${TARGET} ${CPFLAGS}
133
        @${ECHO} ${COMPONENT}: tool installation complete
134 135 136 137 138 139 140 141 142 143 144 145

debug: ${DBG_TARGET}
        @${ECHO} ${COMPONENT}: debug application built

${TARGET}: ${APP_OBJS} ${LIBS} ${DIRS}
        ${LD} ${LDFLAGS} -o ${TARGET} ${APP_OBJS} ${LIBS}
        ${SQZ} ${SQZFLAGS} $@

${DBG_TARGET}: ${APP_DBG_OBJS} ${DBG_LIBS} ${DIRS}
        ${LD} ${LDFLAGS} ${LDDFLAGS} -o ${DBG_TARGET} ${APP_DBG_OBJS} ${DBG_LIBS}

# EOF