#> Makefile
# "@(#)makefile	1.4	96/06/07 VLSI"
# Build control for the C-Demon build.
#
# At the moment you need to perform a make clean when switching being
# target builds. This will be sorted, by forcing the creation of the
# objects within the target DRIVER directory. A full dependancy tree
# will also be constructed to ensure that everything is re-made, without
# having to resort to "make clean" after updating a header file.
#
# $Revision: 0.1 $
#   $Author: jsmith $
#     $Date: 941103 $
#
# Copyright (c) 1994, VLSI Technology Inc. All Rights Reserved.
#------------------------------------------------------------------------------
# This first section declares all the macros and build rules that are
# generic to all the target architecture builds.
#
ARMCC = armcc
ARMLINK = armlink
ARMASM = armasm
#
HOSTCC = cc
#HOSTCC = gcc
#
# The $(LINKVIA) file is used to hold the list of objects being linked
# into the target:
LINKVIA = link.via
LINKMAP = -symbols link.sym -map -list link.map
LDFLAGS = $(LINKMAP)
#
# If we wanted "sort -f link.sym" will give an alphabetically sorted
# symbol list, and "sort -b +1 link.sym" will give a numerically
# sorted list.
#
# FPE2 is specified (rather than allowing the compiler to default to
# FPE3) to avoid the armlink attribute warning bug, and to make the
# resulting code work with the currently released FP Emulator:
#CFLAGS = -apcs 3/32bit/hardfp/FPE2 -c
CFLAGS = -apcs 3/32bit/FPE2 -c
AFLAGS = -apcs 3/32bit
# NOTE: The "hardfp" APCS modifier is a new feature in the latest ARM
# tools. It forces the compiler to generate FP instructions, rather than
# library calls. It is not compatible with earlier versions of the
# compiler command line, and should not be specified if using 1.62 or
# earlier.
#
#------------------------------------------------------------------------------
#
noarg :
	@echo "** NOTE ** You MUST do a \"make clean\" between different target builds **"
	@echo "Use: \"make pid\"   for VY86CPID board"
	@echo "Use: \"make pid3\"  for PID3 board"
	@echo "Use: \"make pid3rev2\"  for PID3 REV2 board"
	@echo " or: \"make ruby2\" for Communicate StarRuby V2.0 board"
	@echo " or: \"make clean\" to remove objects and targets"
#
#------------------------------------------------------------------------------
# The following is the list of targets this file can build:
#
TARGETS = vy86pid.rom ruby2.rom pid3rom pid3rev2
#
# Host based tools:
BUILDTOOLS = crc makemmu split
#
#------------------------------------------------------------------------------
# Target build aliases:
#
vy86pid VY86PID pid: 		vy86pid.rom
pid3:				pid3rom
#
RUBY2 ruby2:			ruby2.rom
#
#------------------------------------------------------------------------------
# Generic objects, common to all C-Demon targets:
#
OBJS =	vectors.o level0.o bp.o swi.o rdi.o fp_init.o main_prg.o handler.o \
	sizemem.o driver.o
#
#------------------------------------------------------------------------------
# VY86PID build control:
#
vy86pid.rom := DRIVER = vy86pid
vy86pid.rom := CODESEG = 0x03000000
vy86pid.rom := DATASEG = 0x00000000
vy86pid.rom := CFLAGS += -li -DVY86PID -Ivy86pid
vy86pid.rom := AFLAGS += -li -PD "VY86PID SETL {TRUE}" -PD "SMC91C92 SETL {FALSE}"

pid3rom := DRIVER = vy86pid
pid3rom := CODESEG = 0x03000000
pid3rom := DATASEG = 0x00000000
pid3rom := CFLAGS += -li -DSMC91C92 -DVY86PID -Ivy86pid
pid3rom := AFLAGS += -li -PD "VY86PID SETL {TRUE}" -PD "SMC91C92 SETL {TRUE}"
pid3rom := OBJS += e9192.o eproc.o

#
# PID3 rev 2
#
pid3rev2 := DRIVER = vy86pid
pid3rev2 := CODESEG = 0x03000000
pid3rev2 := DATASEG = 0x00000000
pid3rev2 := CFLAGS += -li -DSMC91C92 -DVY86PID -DPID3_REV2 -Ivy86pid
pid3rev2 := AFLAGS += -li -PD "VY86PID SETL {TRUE}" -PD "SMC91C92 SETL {TRUE}" -PD "PID3_REV2 SETL {TRUE}"
pid3rev2 := OBJS += e9192.o eproc.o

#
# The VY86PID version no longer uses the "mmu.c" and "mmusupp.s"
# source files.
#vy86pid.rom := OBJS += mmu.o mmusupp.o
#
#------------------------------------------------------------------------------
# RUBY2 build control: The TARSERIAL manifest should be set to either
# SR16C550 or Z85C30 depending on the serial channel to be used for
# the C-Demon communications.
#
CDEMONSERIAL = Z85C30 # Z85C30 or SR16C550
#CDEMONSERIAL = SR16C550
#
ruby2.rom := DRIVER = ruby2
ruby2.rom := CODESEG = 0x01000000
ruby2.rom := DATASEG = 0x00000000
ruby2.rom := CFLAGS += -li -DRUBY2 -Iruby2 -D$(CDEMONSERIAL)
ruby2.rom := AFLAGS += -li -PD "RUBY2 SETL {TRUE}" -PD "$(CDEMONSERIAL) SETL {TRUE}"
#
# The following lines should be included if you want to make use of the
# RUBY2 hardware breakpoint:
ruby2.rom := CFLAGS += -DHWBREAKPOINT
ruby2.rom := AFLAGS += -PD "HWBREAKPOINT SETL {TRUE}"
#
#------------------------------------------------------------------------------

tools:	$(BUILDTOOLS)

crc:	crc.c
	$(HOSTCC) -o $@ crc.c

makemmu: makemmu.c
	$(HOSTCC) -o $@ makemmu.c

split:	split.c
	$(HOSTCC) -o $@ split.c

#------------------------------------------------------------------------------

vy86pid.rom pid3rom pid3rev2:	$$(OBJS) fpe_32lr.o $(BUILDTOOLS)
		@echo $(OBJS) fpe_32lr.o > $(LINKVIA)
		$(ARMLINK) $(LDFLAGS) -B $(CODESEG) -DATA $(DATASEG) -FIRST 'level0.o(C-Demon)' -bin -o $@ -VIA $(LINKVIA)
		crc $@
		makemmu $@
		./split $@

#------------------------------------------------------------------------------

ruby2.rom:	$$(OBJS) fpe_32lr.o $(BUILDTOOLS)
		@echo $(OBJS) fpe_32lr.o > $(LINKVIA)
		$(ARMLINK) $(LDFLAGS) -B $(CODESEG) -DATA $(DATASEG) -FIRST 'level0.o(C-Demon)' -bin -o $@ -VIA $(LINKVIA)
		crc $@

#------------------------------------------------------------------------------
# Include file dependencies:

global_h.s:	modes_h.s

#------------------------------------------------------------------------------
# Object dependencies:

level0.o : level0.s global_h.s $$(DRIVER)/driver_h.s
	$(ARMASM) $(AFLAGS) level0.s -o $@

handler.o : handler.s global_h.s $$(DRIVER)/driver_h.s bp_h.s swis_h.s rdi_h.s
	$(ARMASM) $(AFLAGS) handler.s -o $@

vectors.o : vectors.s global_h.s $$(DRIVER)/driver_h.s rdi_h.s swis_h.s bp_h.s
	$(ARMASM) $(AFLAGS) vectors.s -o $@

bp.o	: bp.c global.h bp.h
	$(ARMCC) $(CFLAGS) -o $@ bp.c

rdi.o   : rdi.c global.h $$(DRIVER)/driver.h rdi.h bp.h swi.h
	$(ARMCC) $(CFLAGS) -o $@ rdi.c

swi.o   : swi.c global.h $$(DRIVER)/driver.h bp.h swi.h rdi.h
	$(ARMCC) $(CFLAGS) -o $@ swi.c

main_prg.o : main_prg.c global.h rdi.h
	$(ARMCC) $(CFLAGS) -o $@ main_prg.c

eproc.o : eproc.c global.h
	$(ARMCC) $(CFLAGS) -o $@ eproc.c

e9192.o : e9192.s global_h.s $$(DRIVER)/driver_h.s e9192_h.s
	$(ARMASM) $(AFLAGS) e9192.s -o $@

fp_init.o : fp_init.s global_h.s swis_h.s
	$(ARMASM) $(AFLAGS) fp_init.s -o $@

mmu.o   : mmu.c global.h mmu.h
	$(ARMCC) $(CFLAGS) -o $@ mmu.c

mmusupp.o : mmusupp.s global_h.s $$(DRIVER)/driver_h.s
	$(ARMASM) $(AFLAGS) mmusupp.s -o $@

memc2.o : $$(DRIVER)/memc2.c
	$(ARMCC) $(CFLAGS) -o $@ $(DRIVER)/memc2.c

sizemem.o : sizemem.s
	$(ARMASM) $(AFLAGS) sizemem.s -o $@

driver.o : $$(DRIVER)/driver.c global.h $$(DRIVER)/driver.h
	$(ARMCC) $(CFLAGS) -o $@ $(DRIVER)/driver.c

#------------------------------------------------------------------------------

clean:
	@rm -f $(BUILDTOOLS) $(OBJS) mmu.o mmusupp.o  $(TARGETS) *.[0123] link.sym* link.map $(LINKVIA) eproc.o e9192.o

#------------------------------------------------------------------------------
# EOF Makefile
