# Common Makefile fragment for toolbox object modules
#
# $Id$
#

#
# Export Paths for Messages module
#
RESDIR = <resource$dir>.Resources2.${COMPONENT}

#
# Standard internal toolbox library and headers
#
TBOXINTLIBDIR = C:tboxlibint
TBOXINTLIB    = ${TBOXINTLIBDIR}.o.tboxlibm
TBOXINTHDR    = -I${TBOXINTLIBDIR}

#
# Build options
#
CFLAGS += -zm -zps1 -ffah -D${SYSTEM}
CINCLUDES += ${TBOXINTHDR} -Itbox: -IC:

#
# Libraries
#
include Makefiles:ModuleLibs
RAM_LIBS = ${TBOXINTLIB} ${EXTRARAMLIBS}
ROM_LIBS = ${TBOXINTLIB} ${EXTRAROMLIBS}

ABSSYM = RISC_OSLib:o.c_abssym

#
# Find the rest of the Makefile fragments for C modules
#
include Makefiles:StdTools
include Makefiles:ModStdRule
include Makefiles:RAMCModule
include Makefiles:ROMCModule

#
# Toolbox modules hold just a Messages file, just a Res file or both.
# Thus we provide three rules, and the including makefile simply selects one
# or other of the rules as appropriate.
#
resources-messages: LocalRes:Messages
	${MKDIR} ${RESDIR}
	${CP} LocalRes:Messages ${RESDIR}.Messages ${CPFLAGS}

resources-res: LocalRes:Res
	${MKDIR} ${RESDIR}
	${CP} LocalRes:Res ${RESDIR}.Res ${CPFLAGS}

resources-both: LocalRes:Messages LocalRes:Res
	${MKDIR} ${RESDIR}
	${CP} LocalRes:Messages ${RESDIR}.Messages ${CPFLAGS}
	${CP} LocalRes:Res      ${RESDIR}.Res      ${CPFLAGS}


#
# Provide defaults so that the rules below are valid
#
RAMMESSAGES .= unused.ram.messages
RAMRES      .= unused.ram.resources
RAMBOTH     .= unused.ram.both

#
# RAM builds require the resources to be packaged up into a ResourceFS
# registerable area.
#

${RAMMESSAGES}: LocalRes:Messages
	resgen messages_file $@ LocalRes:Messages Resources.${COMPONENT}.Messages

${RAMRES}: LocalRes:Res
	resgen res_file $@ LocalRes:Res Resources.${COMPONENT}.Res

${RAMBOTH}: LocalRes:Messages LocalRes:Res
	resgen messages_file $@ \
        LocalRes:Messages Resources.${COMPONENT}.Messages \
        LocalRes:Res Resources.${COMPONENT}.Res

#
# The clean rules are relatively similar too:
#
toolbox-clean:
	${WIPE} o.* ${WFLAGS}
	${WIPE} od ${WFLAGS}
	${WIPE} aof ${WFLAGS}
	${WIPE} rm ${WFLAGS}
	${WIPE} linked ${WFLAGS}
	${WIPE} map ${WFLAGS}

#
# Typically, the ROM and RAM modules will be identical except for main.c
# which will switch on the ROM symbol to not register resources.  We provide
# this rule generically here.
#
o.mainROM: main.c
	$(CC) ${CFLAGS} -DROM -o $@ main.c

#
# Debug builds of modules
#
DBG_MODULE .= rm.D${COMPONENT}
DBG_OBJS   .= ${RAM_OBJS}
DBG_LIBS   .= ${RAM_LIBS} C:tboxlibint.o.debuglibm ${DEBUGLIB} ${NET4LIBS}
DBG_DIRS   .= od._dirs

${DBG_MODULE}: ${DBG_OBJS} ${DBG_LIBS} ${CLIB} ${DIRS} ${RAM_DEPEND} ${DBG_DIRS}
	${MKDIR} rm
	${LD} ${LDFLAGS} ${LDRAMFLAGS} -o $@ -rmf ${DBG_OBJS} ${DBG_LIBS} ${CLIB}

trace: ${DBG_MODULE} ${DBG_DIRS}
	@echo ${COMPONENT}: debug module built

${DBG_DIRS}:
	${MKDIR} od
	${TOUCH} $@

.SUFFIXES: .c .s .od

.c.od:; ${CC} ${CFLAGS} -Ddebugging=1 -o $@ $<
.s.od:; ${AS} ${ASFLAGS} -PD "debugging SETA 1" -o $@ $<


EOFTboxMakefile=Common.TboxMake
# EOF