CApp 7.68 KB
Newer Older
1
# Makefile fragment for C and C++ applications
Ben Avison's avatar
Ben Avison committed
2 3 4

INCLUDED_CAPP = YES

5 6 7 8 9 10 11 12 13
#
# This makefile provides the following phony targets:
#
#    all  install  debug
#
#
# This fragment uses the following macros set by the master makefile.
#
#
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# 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 ${INSTALLDIR}/${TARGET})
# DIRS                (opt) (stamp object for directory creation - otherwise _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)
35
# SOURCES_TO_SYMLINK  (opt) (files which need be linked to by the link farm, in addition to contents of c and h directories)
36 37 38 39 40
#
#
# It relies on the following generic tool macros from the StdTools makefile
#
#
41
# C + CFLAGS       (C compiler; CDFLAGS also used in debug builds; -g implicit)
42 43 44 45 46 47 48 49 50
# 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)
51
# INSERTVERSION    (awk script to substitute from VersionNum)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#
#
# 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
#
#

TARGET       ?= ${COMPONENT}
DBG_TARGET   ?= ${TARGET}-D
INSTDIR      ?= ${INSTALLDIR}/${TARGET}
71
INSTAPP      ?= ${INSTDIR}/!${COMPONENT}
72 73
DIRS         ?= _dirs
OBJS         ?= ${TARGET}
74
APP_OBJS     ?= ${OBJS}
75
DBG_OBJS     ?= ${OBJS}
Ben Avison's avatar
Ben Avison committed
76
APP_LIBS     ?= ${LIBS}
77 78 79
DBG_LIBS     ?= ${LIBS}
DBG_LIBS     += ${DEBUGLIBS}
ifeq (C++,${LINK_TYPE})
Ben Avison's avatar
Ben Avison committed
80
APP_LIBS     += ${C++LIB}
81 82
DBG_LIBS     += ${C++LIB}
endif
Ben Avison's avatar
Ben Avison committed
83
APP_LIBS     += ${CLIB}
84
DBG_LIBS     += ${CLIB}
85 86 87

APP_OBJS_     = $(addsuffix .o,${APP_OBJS})
DBG_OBJS_     = $(addsuffix .od,${DBG_OBJS})
88 89 90 91 92 93 94 95

SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard c++/*) $(wildcard h/*) $(wildcard s/*) VersionNum VersionASM

ifneq (objs,$(notdir ${CURDIR}))

# Makefile invoked from same directory
# Create link farm, then execute the makefile from within it

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
ifeq (clean,${MAKECMDGOALS})
# With a double-colon rule which can have additional actions assigned from the
# master makefile, we'd normally need the master makefile to include the
# ${CURDIR} check to ensure that it's performed on the same invocation as us.
# However, there's no real benefit to performing clean from within the objs
# directory, and it adds an ordering problem between the different double-colon
# rules (the one that deletes the objs directory has to be last otherwise the
# cwd is invalid for the others) so to simplify things, we only ever do cleans
# from the same directory as the Makefile.
clean::
	@echo Cleaning...
	@rm -rf objs
	@echo ${COMPONENT}: cleaned
else
all install debug links: ${SYMLINK_DEPEND}
111 112 113 114 115
	$(foreach linksource,${SOURCES_TO_SYMLINK}, \
		$(shell \
			linkdest=`echo ${linksource} | sed -e 's,\([^/]*\)/\([^/]*\)$$,\2.\1,' -e 's,^,objs/,'`; \
			linkdestdir=`echo $$linkdest | sed -e 's,/[^/]*$$,,'`; \
			linkbackpath=`echo $$linkdestdir | sed -e 's,[^/]*,..,g'`; \
Ben Avison's avatar
Ben Avison committed
116
			[ -d ${linksource} ] || [ -L $$linkdest ] || mkdir -p $$linkdestdir; \
117 118 119 120
			[ -d ${linksource} ] || [ -L $$linkdest ] || ln -s $$linkbackpath/${linksource} $$linkdest; \
		 ) \
	)
	@[ -L objs/Resources ] || ln -s ../Resources objs/Resources
Ben Avison's avatar
Ben Avison committed
121
	@mkdir -p objs
122 123 124
ifneq (links,${MAKECMDGOALS})
	@${MAKE} -C objs -f ../$(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}
endif
125
endif
126 127 128 129 130

else

# Makefile invoked from objs subdirectory

Ben Avison's avatar
Ben Avison committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
ifeq ("${INCLUDED_STDTOOLS}","")
ifeq ("${INCLUDED_HOSTTOOLS}","")
include StdTools
endif
endif
ifeq ("${INCLUDED_APPLIBS}","")
include AppLibs
endif

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

147 148 149
all: ${TARGET}${SUFFIX_ABSOLUTE}
	@${ECHO} ${COMPONENT}: application built

150 151 152 153 154 155
# GNU make seems to treat any double-colon rule with no dependencies as
# always out-of-date, therefore always rebuilds it and anything which in turn
# depends on the target of the double-colon rule. So use a single-colon rule
# instead. If any cross builds need to create extra directories on a
# per-component basis, we'll cross that bridge when we get to it.
${DIRS}:
156 157 158 159 160 161
	${TOUCH} $@

install: install_${INSTTYPE}

install_: install_tool

162
INSTAPP_DEPENDS +=  $(addsuffix ${SUFFIX_ABSOLUTE},$(filter ${TARGET},${INSTAPP_FILES}))
163

164
install_app${CUSTOMINSTALLAPP}: ${INSTAPP_DEPENDS}
165
	${MKDIR} ${INSTAPP}
166 167 168 169 170 171 172 173 174
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${INSTAPP} ${INSTAPP_FILES}
ifneq (,$(filter Messages,${INSTAPP_VERSION}))
	TMP=`mktemp`; ${INSERTVERSION} ${INSTAPP}/Messages > $$TMP; mv $$TMP ${INSTAPP}/Messages
endif        
ifneq (,$(filter Desc,${INSTAPP_VERSION}))
	TMP=`mktemp`; ${INSERTVERSION} descmode=1 ${INSTAPP}/Desc ${INSTAPP}/Desc > $$TMP; mv $$TMP ${INSTAPP}/Desc
endif        
ifneq (,$(filter !Run,${INSTAPP_VERSION}))
	TMP=`mktemp`; ${INSERTVERSION} obeymode=1 ${INSTAPP}/!Run${SUFFIX_OBEY} > $$TMP; mv $$TMP ${INSTAPP}/!Run${SUFFIX_OBEY}
175 176 177
endif
	@${ECHO} ${COMPONENT}: application installation complete

178 179 180 181
install_debug_app${CUSTOMINSTALLDBGAPP}: ${DBG_TARGET}${SUFFIX_DEBIMAGE}
	${CP} ${DBG_TARGET}${SUFFIX_DEBIMAGE} ${INSTAPP}/${TARGET}${SUFFIX_DEBIMAGE} ${CPFLAGS}
	@${ECHO} ${COMPONENT}: ${TARGET} replaced with ${DBG_TARGET}

182 183 184 185 186 187 188 189
install_tool${CUSTOMINSTALLTOOL}: ${TARGET}${SUFFIX_ABSOLUTE}
	${MKDIR} ${INSTDIR}
	${CP} ${TARGET}${SUFFIX_ABSOLUTE} ${INSTDIR}/${TARGET}${SUFFIX_ABSOLUTE} ${CPFLAGS}
	@${ECHO} ${COMPONENT}: tool installation complete

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

190 191
${TARGET}${SUFFIX_ABSOLUTE}${CUSTOMLINK}: ${DIRS} ${APP_OBJS_} ${APP_LIBS}
	${LD} ${LDFLAGS} -o $@ ${APP_OBJS_} ${APP_LIBS}
192 193 194
	${STRIP} $@
	${SQZ} ${SQZFLAGS} $@

195 196
${DBG_TARGET}${SUFFIX_DEBIMAGE}${CUSTOMLINK}: ${DIRS} ${DBG_OBJS_} ${DBG_LIBS}
	${LD} ${LDFLAGS} ${LDDFLAGS} -o $@ ${DBG_OBJS_} ${DBG_LIBS}
197

198 199 200
include $(wildcard *.d)
include $(wildcard *.dd)

201 202 203
endif

# EOF