CApp 11.5 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
#
# This makefile provides the following phony targets:
#
8
#    all  install  debug  resources  rom  rom_link
9 10 11 12 13
#
#
# This fragment uses the following macros set by the master makefile.
#
#
14 15 16
# COMPONENT                 (the name of the component)
# TARGET              (opt) (the leafname of the application - otherwise ${COMPONENT})
# DBG_TARGET          (opt) (debug application leafname - otherwise ${TARGET}-D)
17 18
# ROM_TARGET          (opt) (partially linked module-wrapped leafname - otherwise ${TARGET}.aof)
# LNK_TARGET          (opt) (fixed-position module-wrapped leafname - otherwise ${TARGET}.linked)
19 20
# INSTAPP             (opt) (the application target directory - otherwise ${INSTDIR}/!${COMPONENT})
# INSTDIR             (opt) (the target directory - otherwise ${INSTALLDIR}/${TARGET})
21 22
# RESFSDIR            (opt) (actual directory to export non-application-dir resources to - otherwise ${RESDIR}/${COMPONENT})
# RESFSAPPDIR         (opt) (where to register application-dir resources to within ResourceFS, using RISC OS style directory separators - otherwise Apps.!${COMPONENT})
23 24 25 26
# 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})
27
# ROM_OBJS            (opt) (ROM module-wrap build objects - otherwise ${OBJS} plus modulewrap and ${RES_OBJ})
28 29 30
# 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)
31 32 33
# ROM_LIBS            (opt) (libraries to link for ROM module-wrap targets - otherwise ${LIBS}; ${ROMSTUBS} or ${ROMCSTUBS} is always used, depending on whether ${LIBS} contains ${RLIB} or not)
# WRAPPER             (opt) (module-wrap source file to use - defaults to $LIBDIR/RISC_OSLib/modulewrap.s)
# ROM_DEPEND          (opt) (any extra dependency to assert on ROM_TARGET)
34 35 36 37 38
# 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)
39 40
# RES_FILES           (opt) (list of files to be installed in ${RESFSDIR} when building a module-wrap ROM - use InstRes specification rules. Where these conflict with the files in INSTAPP_FILES, prefer a subdirectory named 'ROM')
# RESAPP_FILES        (opt) (list of files to be installed in ${RESFSAPPDIR} when building a module-wrap ROM - use InstRes specification rules. Where these conflict with the files in INSTAPP_FILES, prefer a subdirectory named 'ROM')
41 42 43 44
# 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)
45
# CUSTOMROM           (opt) (set to "custom" to override the rom module-wrap rules)
46
# SOURCES_TO_SYMLINK  (opt) (files which need be linked to by the link farm, in addition to contents of c and h directories)
47 48 49 50 51
#
#
# It relies on the following generic tool macros from the StdTools makefile
#
#
52
# C + CFLAGS       (C compiler; CDFLAGS also used in debug builds; -g implicit)
53 54 55 56 57 58 59 60 61
# 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)
62
# INSERTVERSION    (awk script to substitute from VersionNum)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#
#
# 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
81 82
ROM_TARGET   ?= ${TARGET}
LNK_TARGET   ?= ${TARGET}
83
INSTDIR      ?= ${INSTALLDIR}/${TARGET}
84
INSTAPP      ?= ${INSTDIR}/!${COMPONENT}
85 86 87 88 89
RESFSDIR     ?= ${RESDIR}/${COMPONENT}
RESFSAPPDIR  ?= Apps.!${COMPONENT}
MERGEDRDIR   ?= _ResData_
RES_AREA     ?= Resources
RES_OBJ      ?= resources
90 91
DIRS         ?= _dirs
OBJS         ?= ${TARGET}
92
APP_OBJS     ?= ${OBJS}
93
DBG_OBJS     ?= ${OBJS}
94
ROM_OBJS     ?= ${OBJS} modulewrap ${RES_OBJ}
Ben Avison's avatar
Ben Avison committed
95
APP_LIBS     ?= ${LIBS}
96 97
DBG_LIBS     ?= ${LIBS}
DBG_LIBS     += ${DEBUGLIBS}
98
ROM_LIBS     ?= ${LIBS}
99
ifeq (C++,${LINK_TYPE})
Ben Avison's avatar
Ben Avison committed
100
APP_LIBS     += ${C++LIB}
101
DBG_LIBS     += ${C++LIB}
102
ROM_LIBS     += ${C++LIB}
103
endif
Ben Avison's avatar
Ben Avison committed
104
APP_LIBS     += ${CLIB}
105
DBG_LIBS     += ${CLIB}
106 107 108 109 110 111 112 113 114
ifeq ($(filter ${RLIB},${ROM_LIBS}),)
ROM_LIBS_     = $(filter-out ${RLIB},${ROM_LIBS})
ROM_LIBS_    += ${ROMSTUBS}
ROM_SYMS      = ${ABSSYM}
else
ROM_LIBS_     = ${ROM_LIBS} ${ROMCSTUBS}
ROM_SYMS      = ${C_ABSSYM}
endif
WRAPPER      ?= ${LIBDIR}/RISC_OSLib/modulewrap.s
115 116 117

APP_OBJS_     = $(addsuffix .o,${APP_OBJS})
DBG_OBJS_     = $(addsuffix .od,${DBG_OBJS})
118
ROM_OBJS_     = $(addsuffix .oz,${ROM_OBJS})
119 120 121 122 123 124 125 126

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

127 128 129 130 131 132 133 134 135 136 137 138 139 140
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
141
all install debug resources rom rom_link links: ${SYMLINK_DEPEND}
142 143 144 145 146
	$(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
147
			[ -d ${linksource} ] || [ -L $$linkdest ] || mkdir -p $$linkdestdir; \
148 149 150 151
			[ -d ${linksource} ] || [ -L $$linkdest ] || ln -s $$linkbackpath/${linksource} $$linkdest; \
		 ) \
	)
	@[ -L objs/Resources ] || ln -s ../Resources objs/Resources
Ben Avison's avatar
Ben Avison committed
152
	@mkdir -p objs
153 154 155
ifneq (links,${MAKECMDGOALS})
	@${MAKE} -C objs -f ../$(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}
endif
156
endif
157 158 159 160 161

else

# Makefile invoked from objs subdirectory

Ben Avison's avatar
Ben Avison committed
162 163 164 165 166
ifeq ("${INCLUDED_STDTOOLS}","")
ifeq ("${INCLUDED_HOSTTOOLS}","")
include StdTools
endif
endif
167 168

ifeq ($(filter rom%,${MAKECMDGOALS}),)
Ben Avison's avatar
Ben Avison committed
169 170 171
ifeq ("${INCLUDED_APPLIBS}","")
include AppLibs
endif
172 173 174 175 176
else
ifeq ("${INCLUDED_MODULELIBS}","")
include ModuleLibs
endif
endif
Ben Avison's avatar
Ben Avison committed
177 178 179 180 181 182 183 184

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

185 186 187
all: ${TARGET}${SUFFIX_ABSOLUTE}
	@${ECHO} ${COMPONENT}: application built

188 189 190 191 192 193
# 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}:
194 195 196 197 198 199
	${TOUCH} $@

install: install_${INSTTYPE}

install_: install_tool

200
INSTAPP_DEPENDS +=  $(addsuffix ${SUFFIX_ABSOLUTE},$(filter ${TARGET},${INSTAPP_FILES}))
201

202
install_app${CUSTOMINSTALLAPP}: ${INSTAPP_DEPENDS}
203
	${MKDIR} ${INSTAPP}
204 205 206 207 208 209 210 211 212
	${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}
213 214 215
endif
	@${ECHO} ${COMPONENT}: application installation complete

216 217 218 219
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}

220 221 222 223 224 225 226 227
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

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
resources:
	${MKDIR} ${RESFSDIR}
ifneq (${RES_FILES},)
	${INSTRES} -I Resources.${LOCALE}.ROM,Resources.UK.ROM,Resources.ROM,Resources.{LOCALE},Resources.UK,Resources ${RESFSDIR} ${RES_FILES}
endif
ifneq (,$(filter Messages,${INSTAPP_VERSION}))
	${INSERTVERSION} ${RESFSDIR}/Messages > ${RESFSDIR}/_Awk_
	${CP} ${RESFSDIR}/_Awk_ ${RESFSDIR}/Messages ${CPFLAGS}
	${RM} ${RESFSDIR}/_Awk_
	for path in ${LOCALE}/ROM UK/ROM ROM ${LOCALE} UK ""; do if [ -f Resources/$$path/Messages ]; then touch -r Resources/$$path/Messages ${RESFSDIR}/Messages; break; fi; done
endif
	@${ECHO} ${COMPONENT}: resources copied to Messages module

rom${CUSTOMROM}: ${ROM_TARGET}.aof
	@${ECHO} ${COMPONENT}: rom module built

rom_link${CUSTOMROM}: ${LNK_TARGET}.linked
	${CP} ${LNK_TARGET}.linked ${LINKDIR}/${COMPONENT} ${CPFLAGS}
	${CP} ${LNK_TARGET}_sym.linked ${LINKDIR}/${COMPONENT}_sym ${CPFLAGS}
	@${ECHO} ${COMPONENT}: rom_link complete

249 250
${TARGET}${SUFFIX_ABSOLUTE}${CUSTOMLINK}: ${DIRS} ${APP_OBJS_} ${APP_LIBS}
	${LD} ${LDFLAGS} -o $@ ${APP_OBJS_} ${APP_LIBS}
251 252 253
	${STRIP} $@
	${SQZ} ${SQZFLAGS} $@

254 255
${DBG_TARGET}${SUFFIX_DEBIMAGE}${CUSTOMLINK}: ${DIRS} ${DBG_OBJS_} ${DBG_LIBS}
	${LD} ${LDFLAGS} ${LDDFLAGS} -o $@ ${DBG_OBJS_} ${DBG_LIBS}
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
${ROM_TARGET}.aof: ${ROM_OBJS_} ${ROM_LIBS_} ${DIRS} ${ROM_DEPEND}
	${LD} -o $@ -aof ${ROM_OBJS_} ${ROM_LIBS_}

${LNK_TARGET}.linked: ${ROM_TARGET}.aof ${ROM_SYMS} ${FORCEROMLINK}
	${LD} ${LDFLAGS} ${LDLINKFLAGS} -o $@ -rmf -base ${ADDRESS} ${ROM_TARGET}.aof ${ROM_SYMS} -symbols ${LNK_TARGET}_sym.linked

modulewrap.oz: ${WRAPPER} AppName.s
	${AS} ${ASFLAGS} ${WRAPPER} $@

${RES_OBJ}.oz:
	${MKDIR} ${MERGEDRDIR}
	${INSTRES} -I Resources.${LOCALE}.ROM,Resources.UK.ROM,Resources.ROM,Resources.${LOCALE},Resources.UK,Resources ${MERGEDRDIR} ${RESAPP_FILES}
	${INSTVIARG} ${MERGEDRDIR} ${RESFSAPPDIR} _ResGen_
	${RESGEN} ${RES_AREA} $@ -via _ResGen_

272 273 274
include $(wildcard *.d)
include $(wildcard *.dd)

275 276 277
endif

# EOF