Commit 02c570ff authored by Ben Avison's avatar Ben Avison Committed by ROOL
Browse files

Extend `CApp` to support module-wrapped applications

This involves grafting in the `resources`, `rom` and `rom_link` rules from
`CModule` (support for `CmdHelp` files is not copied across, because no
module-wrapped application can provide star commands). Module-wrapped
applications typically want to support `install INSTTYPE=app` in the same way
as other applications, to permit a non-wrapped version to be built (for
example, for debugging purposes).

Because this feature is typically used with applications that use RISC_OSLib,
the rules have been made slightly more sophisticated than those in CModule,
in the sense that if `LIBS` contains `${RLIB}`, it automatically selects the
larger ROM stubs and symbols files that include the RISC_OSLib library chunk,
so there is no need to override these from the calling makefile.

Compared to the `install` phase, where all resource files go into the
application directory, for ROM builds, only a subset of files go there,
the remainder being placed under `Resources:$.Resources`, and some of the
files differ in contents from the `install` versions. The application
directory resources in the ROM build case are (in a change from previous
behaviour) all now registered with ResourceFS by the module-wrapped
application rather than by the Messages module, and they are packaged using
the `ResGen` tool. This means that you can kill (or unplug) the module and
teh application will disappear from `Resources:$.Apps`.

The resource files are categorised using the separate macros `INSTAPP_FILES`,
`RES_FILES` and `RESAPP_FILES`.

Requires RISC_OSLib-6_08.
parent bccb299b
......@@ -5,7 +5,7 @@ INCLUDED_CAPP = YES
#
# This makefile provides the following phony targets:
#
# all install debug
# all install debug resources rom rom_link
#
#
# This fragment uses the following macros set by the master makefile.
......@@ -14,24 +14,35 @@ INCLUDED_CAPP = YES
# COMPONENT (the name of the component)
# TARGET (opt) (the leafname of the application - otherwise ${COMPONENT})
# DBG_TARGET (opt) (debug application leafname - otherwise ${TARGET}-D)
# ROM_TARGET (opt) (partially linked module-wrapped leafname - otherwise ${TARGET}.aof)
# LNK_TARGET (opt) (fixed-position module-wrapped leafname - otherwise ${TARGET}.linked)
# INSTAPP (opt) (the application target directory - otherwise ${INSTDIR}/!${COMPONENT})
# INSTDIR (opt) (the target directory - otherwise ${INSTALLDIR}/${TARGET})
# 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})
# 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})
# ROM_OBJS (opt) (ROM module-wrap build objects - otherwise ${OBJS} plus modulewrap and ${RES_OBJ})
# 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)
# 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)
# 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)
# 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')
# 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)
# CUSTOMROM (opt) (set to "custom" to override the rom module-wrap rules)
# SOURCES_TO_SYMLINK (opt) (files which need be linked to by the link farm, in addition to contents of c and h directories)
#
#
......@@ -67,24 +78,44 @@ INCLUDED_CAPP = YES
TARGET ?= ${COMPONENT}
DBG_TARGET ?= ${TARGET}-D
ROM_TARGET ?= ${TARGET}
LNK_TARGET ?= ${TARGET}
INSTDIR ?= ${INSTALLDIR}/${TARGET}
INSTAPP ?= ${INSTDIR}/!${COMPONENT}
RESFSDIR ?= ${RESDIR}/${COMPONENT}
RESFSAPPDIR ?= Apps.!${COMPONENT}
MERGEDRDIR ?= _ResData_
RES_AREA ?= Resources
RES_OBJ ?= resources
DIRS ?= _dirs
OBJS ?= ${TARGET}
APP_OBJS ?= ${OBJS}
DBG_OBJS ?= ${OBJS}
ROM_OBJS ?= ${OBJS} modulewrap ${RES_OBJ}
APP_LIBS ?= ${LIBS}
DBG_LIBS ?= ${LIBS}
DBG_LIBS += ${DEBUGLIBS}
ROM_LIBS ?= ${LIBS}
ifeq (C++,${LINK_TYPE})
APP_LIBS += ${C++LIB}
DBG_LIBS += ${C++LIB}
ROM_LIBS += ${C++LIB}
endif
APP_LIBS += ${CLIB}
DBG_LIBS += ${CLIB}
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
APP_OBJS_ = $(addsuffix .o,${APP_OBJS})
DBG_OBJS_ = $(addsuffix .od,${DBG_OBJS})
ROM_OBJS_ = $(addsuffix .oz,${ROM_OBJS})
SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard c++/*) $(wildcard h/*) $(wildcard s/*) VersionNum VersionASM
......@@ -107,7 +138,7 @@ clean::
@rm -rf objs
@echo ${COMPONENT}: cleaned
else
all install debug links: ${SYMLINK_DEPEND}
all install debug resources rom rom_link links: ${SYMLINK_DEPEND}
$(foreach linksource,${SOURCES_TO_SYMLINK}, \
$(shell \
linkdest=`echo ${linksource} | sed -e 's,\([^/]*\)/\([^/]*\)$$,\2.\1,' -e 's,^,objs/,'`; \
......@@ -133,9 +164,16 @@ ifeq ("${INCLUDED_HOSTTOOLS}","")
include StdTools
endif
endif
ifeq ($(filter rom%,${MAKECMDGOALS}),)
ifeq ("${INCLUDED_APPLIBS}","")
include AppLibs
endif
else
ifeq ("${INCLUDED_MODULELIBS}","")
include ModuleLibs
endif
endif
ifeq ("${INCLUDED_APPSTDRULE}","")
include AppStdRule
......@@ -187,6 +225,27 @@ install_tool${CUSTOMINSTALLTOOL}: ${TARGET}${SUFFIX_ABSOLUTE}
debug: ${DBG_TARGET}${SUFFIX_DEBIMAGE}
@${ECHO} ${COMPONENT}: debug application built
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
${TARGET}${SUFFIX_ABSOLUTE}${CUSTOMLINK}: ${DIRS} ${APP_OBJS_} ${APP_LIBS}
${LD} ${LDFLAGS} -o $@ ${APP_OBJS_} ${APP_LIBS}
${STRIP} $@
......@@ -195,6 +254,21 @@ ${TARGET}${SUFFIX_ABSOLUTE}${CUSTOMLINK}: ${DIRS} ${APP_OBJS_} ${APP_LIBS}
${DBG_TARGET}${SUFFIX_DEBIMAGE}${CUSTOMLINK}: ${DIRS} ${DBG_OBJS_} ${DBG_LIBS}
${LD} ${LDFLAGS} ${LDDFLAGS} -o $@ ${DBG_OBJS_} ${DBG_LIBS}
${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_
include $(wildcard *.d)
include $(wildcard *.dd)
......
......@@ -21,7 +21,7 @@ INCLUDED_CAPP = YES
#
# This makefile provides the following phony targets:
#
# all install debug
# all install debug resources rom rom_link
#
#
# This fragment uses the following macros set by the master makefile.
......@@ -30,24 +30,35 @@ INCLUDED_CAPP = YES
# COMPONENT (the name of the component)
# TARGET (opt) (the leafname of the application - otherwise ${COMPONENT})
# DBG_TARGET (opt) (debug application leafname - otherwise ${TARGET}-D)
# ROM_TARGET (opt) (partially linked module-wrapped leafname - otherwise ${TARGET} in aof)
# LNK_TARGET (opt) (fixed-position module-wrapped leafname - otherwise ${TARGET} in linked)
# INSTAPP (opt) (the application target directory - otherwise ${INSTDIR}.!${COMPONENT})
# INSTDIR (opt) (the target directory - otherwise <Install$Dir>.${TARGET})
# 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 - otherwise Apps.!${COMPONENT})
# 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})
# ROM_OBJS (opt) (ROM module-wrap build objects - otherwise ${OBJS} plus modulewrap and ${RES_OBJ})
# 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)
# 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 RISCOSLib:s.modulewrap)
# ROM_DEPEND (opt) (any extra dependency to assert on ROM_TARGET)
# 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)
# 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')
# 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)
# CUSTOMROM (opt) (set to "custom" to override the rom module-wrap rules)
#
#
# It relies on the following generic tool macros from the StdTools makefile
......@@ -85,32 +96,59 @@ INSTALLDIR = <Install$Dir>
TARGET ?= ${COMPONENT}
DBG_TARGET ?= ${TARGET}-D
ROM_TARGET ?= ${TARGET}
LNK_TARGET ?= ${TARGET}
INSTDIR ?= ${INSTALLDIR}.${TARGET}
INSTAPP ?= ${INSTDIR}.!${COMPONENT}
RESFSDIR ?= ${RESDIR}.${COMPONENT}
RESFSAPPDIR ?= Apps.!${COMPONENT}
MERGEDRDIR ?= oz._ResData_
RES_AREA ?= Resources
RES_OBJ ?= resources
DIRS ?= o._dirs
OBJS ?= ${TARGET}
APP_OBJS ?= ${OBJS}
DBG_OBJS ?= ${OBJS}
ROM_OBJS ?= ${OBJS} modulewrap ${RES_OBJ}
APP_LIBS ?= ${LIBS}
DBG_LIBS ?= ${LIBS}
ROM_LIBS ?= ${LIBS}
ifeq (C++,${LINK_TYPE})
APP_LIBS += ${C++LIB}
DBG_LIBS += ${C++LIB}
ROM_LIBS += ${C++LIB}
endif
APP_LIBS += ${CLIB}
DBG_LIBS += ${DEBUGLIBS} ${CLIB}
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 ?= RISC_OSLib:s.modulewrap
APP_OBJS_ = $(addprefix o.,${APP_OBJS})
DBG_OBJS_ = $(addprefix od.,${DBG_OBJS})
ROM_OBJS_ = $(addprefix oz.,${ROM_OBJS})
ifeq ("${INCLUDED_STDTOOLS}","")
ifeq ("${INCLUDED_HOSTTOOLS}","")
include StdTools
endif
endif
ifeq ($(filter rom%,${MAKECMDGOALS}),)
ifeq ("${INCLUDED_APPLIBS}","")
include AppLibs
endif
else
ifeq ("${INCLUDED_MODULELIBS}","")
include ModuleLibs
endif
endif
ifeq ("${INCLUDED_APPSTDRULE}","")
include AppStdRule
......@@ -125,6 +163,9 @@ all: ${TARGET}
${DIRS} ::
${MKDIR} o
${MKDIR} od
${MKDIR} oz
${MKDIR} aof
${MKDIR} linked
${TOUCH} $@
clean ::
......@@ -132,6 +173,12 @@ clean ::
@IfThere o Then ${WIPE} o ${WFLAGS}
@IfThere od Then ${ECHO} ${WIPE} od ${WFLAGS}
@IfThere od Then ${WIPE} od ${WFLAGS}
@IfThere oz Then ${ECHO} ${WIPE} oz ${WFLAGS}
@IfThere oz Then ${WIPE} oz ${WFLAGS}
@IfThere aof Then ${ECHO} ${WIPE} aof ${WFLAGS}
@IfThere aof Then ${WIPE} aof ${WFLAGS}
@IfThere linked Then ${ECHO} ${WIPE} linked ${WFLAGS}
@IfThere linked Then ${WIPE} linked ${WFLAGS}
${RM} ${TARGET}
${RM} ${DBG_TARGET}
@${ECHO} ${COMPONENT}: cleaned
......@@ -173,6 +220,29 @@ install_tool${CUSTOMINSTALLTOOL}: ${TARGET}
debug: ${DBG_TARGET}
@${ECHO} ${COMPONENT}: debug application built
resources:
${MKDIR} ${RESFSDIR}
${TOKENCHECK} LocalRes:Messages
${CP} LocalRes:Messages ${RESFSDIR}.Messages ${CPFLAGS}
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_
${TOUCH} -r LocalRes:Messages ${RESFSDIR}.Messages
endif
@${ECHO} ${COMPONENT}: resources copied to Messages module
rom${CUSTOMROM}: aof.${ROM_TARGET}
@${ECHO} ${COMPONENT}: rom module built
rom_link${CUSTOMROM}: linked.${LNK_TARGET}
${CP} linked.${LNK_TARGET} ${LINKDIR}.${COMPONENT} ${CPFLAGS}
${CP} linked.${LNK_TARGET}_sym ${LINKDIR}.${COMPONENT}_sym ${CPFLAGS}
@${ECHO} ${COMPONENT}: rom_link complete
${TARGET}${CUSTOMLINK}: ${APP_OBJS_} ${APP_LIBS} ${DIRS}
${LD} ${LDFLAGS} -o ${TARGET} ${APP_OBJS_} ${APP_LIBS}
${SQZ} ${SQZFLAGS} $@
......@@ -180,4 +250,22 @@ ${TARGET}${CUSTOMLINK}: ${APP_OBJS_} ${APP_LIBS} ${DIRS}
${DBG_TARGET}${CUSTOMLINK}: ${DBG_OBJS_} ${DBG_LIBS} ${DIRS}
${LD} ${LDFLAGS} ${LDDFLAGS} -o ${DBG_TARGET} ${DBG_OBJS_} ${DBG_LIBS}
aof.${ROM_TARGET}: ${ROM_OBJS_} ${ROM_LIBS_} ${DIRS} ${ROM_DEPEND}
${LD} -o $@ -aof ${ROM_OBJS_} ${ROM_LIBS_}
linked.${LNK_TARGET}: aof.${ROM_TARGET} ${ROM_SYMS} ${FORCEROMLINK}
${LD} ${LDFLAGS} ${LDLINKFLAGS} -o $@ -rmf -base ${ADDRESS} aof.${ROM_TARGET} ${ROM_SYMS} -Symbols linked.${LNK_TARGET}_sym
oz.modulewrap: s.modulewrap s.AppName
${AS} ${ASFLAGS} s.modulewrap $@
s.modulewrap: ${WRAPPER}
${CP} ${WRAPPER} $@ ${CPFLAGS}
oz.${RES_OBJ}:
${MKDIR} ${MERGEDRDIR}
${INSTRES} -I Resources.${LOCALE}.ROM,Resources.UK.ROM,Resources.ROM,Resources.${LOCALE},Resources.UK,Resources ${MERGEDRDIR} ${RESAPP_FILES}
${INSTVIARG} ${MERGEDRDIR} ${RESFSAPPDIR} oz._ResGen_
${RESGEN} ${RES_AREA} $@ -via oz._ResGen_
# EOF
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment