CApp 6.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 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
Ben Avison's avatar
Ben Avison committed
16 17 18

INCLUDED_CAPP = YES

19 20 21 22 23 24 25 26 27 28 29
#
# $Id$
#
# This makefile provides the following phony targets:
#
#    all  install  debug
#
#
# This fragment uses the following macros set by the master makefile.
#
#
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# COMPONENT                 (the name of the component)
# TARGET              (opt) (the leafname of the application - otherwise ${COMPONENT})
# DBG_TARGET          (opt) (debug application leafname - otherwise ${TARGET}-D)
# INSTAPP             (opt) (the application target directory - otherwise ${INSTDIR}.!${COMPONENT})
# 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})
# APP_OBJS            (opt) (release build object files, no prefixes - otherwise ${OBJS})
# DBG_OBJS            (opt) (debug 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)
# DBG_LIBS            (opt) (extra debug libraries - otherwise ${LIBS}; ${CLIB} and ${DEBUGLIBS} always used)
# 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")
# INSTAPP_FILES       (opt) (list of files to be installed in application directory - use InstRes specification rules)
# INSTAPP_DEPENDS     (opt) (list of dependencies to be satisfied before doing application install - ${TARGET} assumed if in INSTAPP_FILES)
# INSTAPP_VERSION     (opt) (list of Messages/!Run/Desc files to insert app version from VersionNum - include in INSTAPP_FILES as well)
# CUSTOMLINK          (opt) (set to "custom" to override the link rule)
# 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)
# CUSTOMINSTALLDBGAPP (opt) (set to "custom" to override the install rule for debug resources)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#
#
# 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)
Robert Sprowson's avatar
Robert Sprowson committed
66
# INSERTVERSION    (awk script to substitute from VersionNum)
Jeffrey Lee's avatar
Jeffrey Lee committed
67
# CHMOD            (file permission manipulation)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#
#
# 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}
Robert Sprowson's avatar
Robert Sprowson committed
89
INSTAPP      ?= ${INSTDIR}.!${COMPONENT}
90 91
DIRS         ?= o._dirs
OBJS         ?= ${TARGET}
Robert Sprowson's avatar
Robert Sprowson committed
92
APP_OBJS     ?= ${OBJS}
93
DBG_OBJS     ?= ${OBJS}
Ben Avison's avatar
Ben Avison committed
94
APP_LIBS     ?= ${LIBS}
95
DBG_LIBS     ?= ${LIBS}
96
ifeq (C++,${LINK_TYPE})
Ben Avison's avatar
Ben Avison committed
97
APP_LIBS     += ${C++LIB}
98 99
DBG_LIBS     += ${C++LIB}
endif
Ben Avison's avatar
Ben Avison committed
100
APP_LIBS     += ${CLIB}
101
DBG_LIBS     += ${DEBUGLIBS} ${CLIB}
Robert Sprowson's avatar
Robert Sprowson committed
102 103

APP_OBJS_     = $(addprefix o.,${APP_OBJS})
104
DBG_OBJS_     = $(addprefix od.,${DBG_OBJS})
105

Ben Avison's avatar
Ben Avison committed
106
ifeq ("${INCLUDED_STDTOOLS}","")
Ben Avison's avatar
Ben Avison committed
107
ifeq ("${INCLUDED_HOSTTOOLS}","")
Ben Avison's avatar
Ben Avison committed
108 109
include StdTools
endif
Ben Avison's avatar
Ben Avison committed
110
endif
Ben Avison's avatar
Ben Avison committed
111 112 113 114 115 116 117 118 119 120 121
ifeq ("${INCLUDED_APPLIBS}","")
include AppLibs
endif

ifeq ("${INCLUDED_APPSTDRULE}","")
include AppStdRule
endif
ifeq ("${INCLUDED_DBGRULES}","")
include DbgRules
endif

122 123 124 125 126 127 128 129
all: ${TARGET}
        @${ECHO} ${COMPONENT}: application built

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

130
clean ::
131 132 133 134 135 136 137 138
        @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

139 140 141
install: install_${INSTTYPE}

install_: install_tool
142
        @${NOP}
143

Robert Sprowson's avatar
Robert Sprowson committed
144
INSTAPP_DEPENDS += $(filter ${TARGET},${INSTAPP_FILES})
145

Robert Sprowson's avatar
Robert Sprowson committed
146
install_app${CUSTOMINSTALLAPP}: ${INSTAPP_DEPENDS}
147
        ${MKDIR} ${INSTAPP}
Robert Sprowson's avatar
Robert Sprowson committed
148 149
        ${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${INSTAPP} ${INSTAPP_FILES}
ifneq (,$(filter Messages,${INSTAPP_VERSION}))
Jeffrey Lee's avatar
Jeffrey Lee committed
150
        ${CHMOD} +w ${INSTAPP}.Messages
Robert Sprowson's avatar
Robert Sprowson committed
151
        ${INSERTVERSION} LocalRes:Messages > ${INSTAPP}.Messages
152
endif
Robert Sprowson's avatar
Robert Sprowson committed
153
ifneq (,$(filter Desc,${INSTAPP_VERSION}))
Jeffrey Lee's avatar
Jeffrey Lee committed
154
        ${CHMOD} +w ${INSTAPP}.Desc
Robert Sprowson's avatar
Robert Sprowson committed
155
        ${INSERTVERSION} descmode=1 LocalRes:Desc > ${INSTAPP}.Desc
156
endif
Robert Sprowson's avatar
Robert Sprowson committed
157
ifneq (,$(filter !Run,${INSTAPP_VERSION}))
Jeffrey Lee's avatar
Jeffrey Lee committed
158
        ${CHMOD} +w ${INSTAPP}.!Run
Robert Sprowson's avatar
Robert Sprowson committed
159 160
        ${INSERTVERSION} obeymode=1 LocalRes:!Run > ${INSTAPP}.!Run
        ${SETTYPE} ${INSTAPP}.!Run Obey
161
endif
162 163
        @${ECHO} ${COMPONENT}: application installation complete

164 165 166 167
install_debug_app${CUSTOMINSTALLDBGAPP}: ${DBG_TARGET} install_app
        ${CP} ${DBG_TARGET} ${INSTAPP}.${TARGET} ${CPFLAGS}
        @${ECHO} ${COMPONENT}: ${TARGET} replaced with ${DBG_TARGET}

168
install_tool${CUSTOMINSTALLTOOL}: ${TARGET}
169 170
        ${MKDIR} ${INSTDIR}
        ${CP} ${TARGET} ${INSTDIR}.${TARGET} ${CPFLAGS}
171
        @${ECHO} ${COMPONENT}: tool installation complete
172 173 174 175

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

Robert Sprowson's avatar
Robert Sprowson committed
176 177
${TARGET}${CUSTOMLINK}: ${APP_OBJS_} ${APP_LIBS} ${DIRS}
        ${LD} ${LDFLAGS} -o ${TARGET} ${APP_OBJS_} ${APP_LIBS}
178 179
        ${SQZ} ${SQZFLAGS} $@

180 181
${DBG_TARGET}${CUSTOMLINK}: ${DBG_OBJS_} ${DBG_LIBS} ${DIRS}
        ${LD} ${LDFLAGS} ${LDDFLAGS} -o ${DBG_TARGET} ${DBG_OBJS_} ${DBG_LIBS}
182 183

# EOF