AAsmModule 11.1 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 41 42 43 44 45 46 47 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
# Makefile fragment for assembler modules, previously built using AAsm but now using objasm
# Such modules are characterised by the use of position-independent code
# and multiple source files (if applicable) linked at the assembly stage
# (using LNK and GET directives) rather than at the link stage.

INCLUDED_AASMMODULE = YES

#
# This makefile provides the following phony targets:
#
#    all     rom           install_rom   resources
#    export  export_libs   export_hdrs   standalone         install
#    clean   debug         gpa_debug
#
#
# This fragment uses the following macros set by the master makefile.
#
#
# COMPONENT             (the name of the component)
# TARGET          (opt) (the leafname of the module - otherwise ${COMPONENT})
# RESFSDIR        (opt) (actual directory to export resources to - otherwise ${RESDIR}/${TARGET})
# ROM_MODULE      (opt) (output filename - otherwise ${TARGET})
# ROM_OBJECT      (opt) (object file for romming - otherwise ${TARGET}.o)
# ROM_LIBS        (opt) (libraries to link again ROM_OBJECT to generate ROM_MODULE)
# ROM_DEPEND      (opt) (any extra dependency to assert on ROM_MODULE)
# DBG_MODULE      (opt) (output filename for debug - otherwise ${TARGET}D
# DBG_OBJECT      (opt) (object file for debug - otherwise ${TARGET}D.o
# DBG_LIBS        (opt) (libraries to link against DBG_OBJECT to generate DBG_MODULE - otherwise ${ROM_LIBS})
# SA_MODULE       (opt) (output filename for softload - otherwise ${TARGET}SA
# SA_OBJECT       (opt) (object file for softload - otherwise ${TARGET}SA.o
# SA_LIBS         (opt) (libraries to link against SA_OBJECT to generate SA_MODULE - otherwise ${ROM_LIBS})
# SA_DEPEND       (opt) (any extra dependency to assert on SA_MODULE and DBG_MODULE)
# DIRS            (opt) (magic target to ensure object directories are present - otherwise _dirs)
# HEADER[1-3]     (opt) (leafname of file in hdr to copy to ${EXPORTDIR} on export_hdrs)
# ASMCHEADER[1-3] (opt) (C-from-assembly auto-generated header files to export, no Hdr. prefix - otherwise none)
# CHEADER[1-3]    (opt) (C header files to export - otherwise none)
# EXPORTS         (opt) (list of C and C-from-assembly headers to export)
# C_EXP_HDR       (opt) (C header target directory - otherwise ${CEXPORTDIR}/Interface)
# EXP_HDR         (opt) (directory for exported assembler interface headers)
# CUSTOMEXP       (opt) (set to "custom" to override the export rules)
# CUSTOMRES       (opt) (set to "custom" to override the resources rules, or "no" for no resources)
# CUSTOMROM       (opt) (set to "custom" to override the rom rules)
# CUSTOMSA        (opt) (set to "custom" to override the standalone rules)
# CUSTOMDBG       (opt) (set to "custom" to override the debug rules)
# CUSTOMGPA       (opt) (set to "custom" to override the GPA rules)
# SOURCES_TO_LINK (opt) (files which need be linked to by the link farm, in addition to contents of hdr and s directories)
#
#
# It relies on the following from the build system:
#
#
# INSTDIR          (installation directory for ROM_MODULE or disc install)
# INSTALLDIR       (if INSTDIR was not specified by the build system)
# RESDIR           (installation directory for resources - cf. RESFSDIR)
# EXPORTDIR        (export directory for assembler interface headers)
# CEXPORTDIR       (export directory for C interface headers)
# HDRDIR           (top-level export directory for assembler headers)
# CMDHELP          (optional, set to None to exclude syntax errors from Messages)
# PHASE            (export phase discriminator)
#
#
# It relies on the following generic tool macros from the Tools makefile
#
# CP + CPFLAGS     (copy, cp etc.)
# AS + ASFLAGS     (assembler)
# MKDIR            (cdir/mkdir -p)
# RM + WIPE        (deletions)
# ECHO
# LD               (linker)
#
#

TARGET     ?= ${COMPONENT}
INSTDIR    ?= ${INSTALLDIR}
ROM_MODULE ?= ${TARGET}
ROM_SOURCE ?= ${TARGET}.s
ROM_OBJECT ?= ${TARGET}.o
DIRS       ?= _dirs
EXP_HDR    ?= ${EXPORTDIR}
RESFSDIR   ?= ${RESDIR}/${TARGET}
RESAPPDIR  ?= ${RESDIR}/../Apps/${APP}
C_EXP_HDR  ?= ${CEXPORTDIR}/Interface

SA_MODULE  ?= ${TARGET}SA
SA_OBJECT  ?= ${TARGET}SA.o
MERGEDMDIR ?= _Messages_
MERGEDMSGS ?= ${MERGEDMDIR}/${TARGET}
ifeq (${CMDHELP},None)
SA_FLAGS   ?= -PD "standalone SETL {TRUE}" -PD "MergedMsgs SETS \"${MERGEDMSGS}\"" -PD "international_help SETL {FALSE}"
else
SA_FLAGS   ?= -PD "standalone SETL {TRUE}" -PD "MergedMsgs SETS \"${MERGEDMSGS}\""
endif
SA_LIBS    ?= ${ROM_LIBS}

DBG_MODULE ?= ${TARGET}D
DBG_OBJECT ?= ${TARGET}D.o
SA_DEBUG   ?= -g -PreDefine "debugging SETL {TRUE}"
DBG_LIBS   ?= ${ROM_LIBS}

#GPA_FILE   ?= ${TARGET}.gpa
#GPA_AIF    ?= ${TARGET}.aif

TOKENS     ?= ${HDRDIR}/Global/Tokens

TOKENSOURCE ?= TokHelpSrc.s

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

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

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

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 debug export export_hdrs export_libs gpa_debug install install_rom links resources rom standalone: ${SYMLINK_DEPEND}
	$(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'`; \
			[ -d ${linksource} ] || [ -L $$linkdest ] || mkdir -p $$linkdestdir; \
			[ -d ${linksource} ] || [ -L $$linkdest ] || ln -s $$linkbackpath/${linksource} $$linkdest; \
		 ) \
	)
	@[ -L objs/Resources ] || ln -s ../Resources objs/Resources
	@mkdir -p objs
ifneq (links,${MAKECMDGOALS})
	@${MAKE} -C objs -f ../$(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}
endif
endif

else

# Makefile invoked from objs subdirectory

ifeq ("${INCLUDED_STDTOOLS}","")
include StdTools
endif

all: rom debug standalone

${DIRS} ::
	${TOUCH} $@

#
# ROM build rules
#
rom${CUSTOMROM}: ${ROM_MODULE}
	@${ECHO} ${COMPONENT}: rom module built

install_rom${CUSTOMROM}: ${ROM_MODULE}
	${CP} ${ROM_MODULE} ${INSTDIR}/${TARGET} ${CPFLAGS}
	#${CP} ${ROM_MODULE}_gpa ${INSTDIR}/${TARGET}_gpa ${CPFLAGS}
	@${ECHO} ${COMPONENT}: rom module installed

${ROM_MODULE}: ${ROM_DEPEND} ${DIRS} ${ROM_LIBS} ${ROM_OBJECT}
	${LD} -rmf -o $@ ${ROM_OBJECT} ${ROM_LIBS}
	#${LD} -aif -bin -d -Entry 0 -o ${ROM_MODULE}_aif ${ROM_OBJECT} ${ROM_LIBS}
	#${TOGPA} -s ${ROM_MODULE}_aif ${ROM_MODULE}_gpa

${ROM_OBJECT}: ${DIRS} ${TOKHELPSRC} ${ROM_SOURCE}
	${AS} ${ASFLAGS} -depend $(subst .o,.d,$@) -g -o $@ ${ROM_SOURCE}

#
# Standalone builds
#
standalone${CUSTOMSA}: ${SA_MODULE}
	@${ECHO} ${COMPONENT}: standalone module built

${SA_MODULE}: ${SA_DEPEND} ${DIRS} ${SA_LIBS} ${SA_OBJECT}
	${LD} -rmf -o $@ ${SA_OBJECT} ${SA_LIBS}
	${MODSQZ} -f ${MODSQZFLAGS} $@

${SA_OBJECT}: ${DIRS} ${TOKHELPSRC} ${MERGEDMSGS} ${ROM_SOURCE}
	${AS} ${ASFLAGS} -depend $(subst .o,.d,$@) -o $@ ${ROM_SOURCE} ${SA_FLAGS}

${MERGEDMSGS}${PRIVATEMSGS}:
	${MKDIR} ${MERGEDMDIR}
	${TOUCH} ${MERGEDMDIR}.Messages
	${TOUCH} ${MERGEDMDIR}.CmdHelp
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${MERGEDMDIR} [Messages] [CmdHelp]
	${CAT} ${MERGEDMDIR}.Messages ${MERGEDMDIR}.CmdHelp > $@
	${RM} ${MERGEDMDIR}.Messages ${MERGEDMDIR}.CmdHelp

install${CUSTOMSA}: ${SA_MODULE}
	${MKDIR} ${INSTDIR}
	${CP} ${SA_MODULE} ${INSTDIR}/${TARGET} ${CPFLAGS}
	@${ECHO} ${COMPONENT}: standalone module installed

debug${CUSTOMDBG}: ${DBG_MODULE}
	@${ECHO} ${COMPONENT}: standalone debug module built

${DBG_MODULE}: ${DBG_OBJECT} ${DBG_LIBS} ${DIRS} ${SA_DEPEND}
	${LD} -rmf -o $@ ${DBG_OBJECT} ${DBG_LIBS}

${DBG_OBJECT}: ${ROM_SOURCE} ${MERGEDMSGS} ${TOKHELPSRC} ${DIRS}
	${AS} ${ASFLAGS} -depend $(subst .o,.d,$@) -o $@ ${ROM_SOURCE} ${SA_FLAGS} ${SA_DEBUG}

#gpa_debug${CUSTOMGPA}: ${GPA_FILE}
#	@${ECHO} ${COMPONENT}: GPA debug listing generated
#
#${GPA_FILE}: ${GPA_AIF}
#	${TOGPA} -s ${GPA_AIF} ${GPA_FILE}
#
#${GPA_AIF}: ${DBG_OBJECT}
#	${LD} -aif -bin -d -o ${GPA_AIF} ${DBG_OBJECT}

#
# Export phases
#

export_hdrs: ${EXPORTS}
	@if [ -e ${HEADER1}.hdr ]; then ${ECHO} ${CP} ${HEADER1}.hdr ${EXP_HDR}/${HEADER1} ${CPFLAGS}; fi
	@if [ -e ${HEADER1}.hdr ]; then ${CP} ${HEADER1}.hdr ${EXP_HDR}/${HEADER1} ${CPFLAGS}; fi
	@if [ -e ${HEADER2}.hdr ]; then ${ECHO} ${CP} ${HEADER2}.hdr ${EXP_HDR}/${HEADER2} ${CPFLAGS}; fi
	@if [ -e ${HEADER2}.hdr ]; then ${CP} ${HEADER2}.hdr ${EXP_HDR}/${HEADER2} ${CPFLAGS}; fi
	@if [ -e ${HEADER3}.hdr ]; then ${ECHO} ${CP} ${HEADER3}.hdr ${EXP_HDR}/${HEADER3} ${CPFLAGS}; fi
	@if [ -e ${HEADER3}.hdr ]; then ${CP} ${HEADER3}.hdr ${EXP_HDR}/${HEADER3} ${CPFLAGS}; fi
	@${ECHO} ${COMPONENT}: header export complete

export_libs:
	@${ECHO} ${COMPONENT}: library export complete

export${CUSTOMEXP}: export_${PHASE}
	${NOP}

export_:: export_hdrs export_libs
	${NOP}

# Need these to stop complaints about the rules below
ASMCHEADER1 ?= _!_x_!_
ASMCHEADER2 ?= _!_x_!_
ASMCHEADER3 ?= _!_x_!_
CHEADER1    ?= _!_x_!_
CHEADER2    ?= _!_x_!_
CHEADER3    ?= _!_x_!_

${C_EXP_HDR}/${ASMCHEADER1} :: ${ASMCHEADER1}.hdr
	${HDR2H} ${ASMCHEADER1}.hdr $@

${C_EXP_HDR}/${ASMCHEADER2} :: ${ASMCHEADER2}.hdr
	${HDR2H} ${ASMCHEADER2}.hdr $@

${C_EXP_HDR}.${ASMCHEADER3} :: ${ASMCHEADER3}.hdr
	${HDR2H} ${ASMCHEADER3}.hdr $@

${C_EXP_HDR}.${CHEADER1}.h :: ${CHEADER1}.h
	${CP} ${CHEADER1}.h $@ ${CPFLAGS}

${C_EXP_HDR}.${CHEADER2}.h :: ${CHEADER2}.h
	${CP} ${CHEADER2}.h $@ ${CPFLAGS}

${C_EXP_HDR}.${CHEADER3}.h :: ${CHEADER3}.h
	${CP} ${CHEADER3}.h $@ ${CPFLAGS}

#
# Resources rules
#
resources${CUSTOMRES}:: resources-${CMDHELP} ${RESOURCEEXTRA}
	@${ECHO} ${COMPONENT}: resources copied to Messages module

ifeq (${CUSTOMRES},no)
resources:
	@${ECHO} ${COMPONENT}: no resources to export
endif        

resources-None:
	${MKDIR} ${RESFSDIR}
	${MKDIR} ${MERGEDMDIR}
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${RESFSDIR} Messages
	${RM} ${MERGEDMDIR}.Messages

resources-: ${MERGEDMSGS}
	${MKDIR} ${RESFSDIR}
	${CP} ${MERGEDMSGS} ${RESFSDIR}/Messages
        
resources_res::
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${RESFSDIR} Res
        
resources_messages::
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${RESFSDIR} Messages

resources_templates::
	${INSTRES} -I Resources.${USERIF}.${LOCALE},Resources.${USERIF}.UK,Resources.${LOCALE},Resources.UK,Resources ${RESFSDIR} Templates

#
# Build the help tokens
#
${TOKENSOURCE}: ${TOKENS} ${HELPSRC}
	${TOKENISE} ${TOKENS} ${HELPSRC} $@

include $(wildcard *.d)

endif

# EOF