###############################################################################
#
# $(MAKE)file for exec.library
#
###############################################################################

#
# Server directory for the data...
#
REMOTE = V:src/kickstart/exec
VERSION= 40
MAKE= smake

#
# Name of the module
#
MODNAME	= exec

#
# The ".LD" file we want to produce.
#
LD_FILE	= $(MODNAME).ld$(TYPE)
LD_STRIP= $(MODNAME).ld.strip$(TYPE)
MAP_FILE= $(MODNAME).map$(TYPE)

#
# Define the macro below if this is a full release build
# (with the words BETA removed)  If you change this line,
# you should do a MAKE CLEAN
#
#RELEASE	= -D FINAL_RELEASE=1

#
# Magic loop-back to do the various versions
#
# $(TYPE)   = The type extention of the file.
# $(MACHINE)= The machine name definition.
# $(LOC)    = The location to load.
#
ALL:
	$(MAKE) -s TYPE=       MACHINE=MACHINE_A2000 LOC=LOC_F8 $(LD_STRIP)        "RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.a3000 MACHINE=MACHINE_A3000 LOC=LOC_F8 $(LD_STRIP).a3000  "RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.a4000 MACHINE=MACHINE_A4000 LOC=LOC_F8 $(LD_STRIP).a4000  "RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.a1200 MACHINE=MACHINE_A1200 LOC=LOC_F8 $(LD_STRIP).a1200  "RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.cdgs  MACHINE=MACHINE_CDGS  LOC=LOC_F8 $(LD_STRIP).cdgs   "RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.20    MACHINE=MACHINE_A2000 LOC=LOC_20 $(LD_STRIP).20    #"RELEASE=-D FINAL_RELEASE=1"
	$(MAKE) -s TYPE=.F0    MACHINE=MACHINE_A2000 LOC=LOC_F0 $(LD_STRIP).F0    #"RELEASE=-D FINAL_RELEASE=1"

#
# Compiler, assembler, and linker
#
CC = lc
AS = hx68 -a
LN = blink

#
# Compiler flags...
#
CFLAGS	= -b0 -v -me -ms -cfistqm -d1 -O

#
# Assembler flags...  NOTE how they are used below...
#
AFLAGS	= -cqs -i include: $(RELEASE) -o

#
# Default rules...
#
.c.o:
	$(CC) $(CFLAGS) $*.c

.asm.o:
	$(AS) $*.asm $(AFLAGS) $*.o

#
# Linker flags
#
LFLAGS		= SMALLCODE SMALLDATA QUIET
LFLAGS_STRIP	= ND

#
# System libraries
#
LIBS= LIB:small.lib LIB:debug.lib debug.lib

#
# My headers...
#
PUBLIC_HDR =	types.i ables.i alerts.i devices.i errors.i execbase.i initializers.i \
		interrupts.i io.i libraries.i lists.i memory.i nodes.i ports.i \
		semaphores.i resident.i strings.i tasks.i exec.i types.h devices.h \
		errors.h execbase.h initializers.h interrupts.h io.h libraries.h \
		lists.h memory.h nodes.h ports.h semaphores.h resident.h tasks.h \
		exec.h alerts.h macros.i exec_lib.i

MY_HDR	=	assembly.i \
		calls.i \
		constants.i \
		privinfo.i \
		privintr.i \
		wackbase.i \
		$(PUBLIC_HDR)

#
# My C source...
#
MY_C	=

#
# My Assebly source...
#
MY_A	=	autodocs.asm \
coldstart.asm \
startexec.asm \
devices.asm \
exceptions.asm \
initializers.asm \
interrupts.asm \
lists.asm \
libraries.asm \
memory.asm \
offsets.asm \
ports.asm \
resources.asm \
tasks.asm \
dofmt.asm \
execlib.asm \
copymem.asm \
semaphores.asm \
debug.asm \
alert.asm \
sad.asm

#
# My object files...
#
MY_OBJS=	coldstart.o$(TYPE) \
		startexec.o$(TYPE) \
		devices.o \
		exceptions.o \
		initializers.o \
		interrupts.o \
		lists.o \
		libraries.o \
		memory.o \
		offsets.o \
		ports.o \
		resources.o \
		tasks.o \
		dofmt.o \
		execlib.o \
		copymem.o \
		semaphores.o \
		sad.o \
		alert.o$(TYPE)

#
# My library objects...
#
MY_LIB_OBJS =

#
# My library files...
#
MY_LIBS	=

#
# Build the stripped LD file...
#
$(LD_STRIP):	$(LD_FILE)
	$(LN) FROM $(LD_FILE) TO $(LD_STRIP) $(LFLAGS_STRIP)

#
# Build the various versions
#
$(LD_FILE):	$(MY_OBJS) debug.lib
	$(LN) <with <
FROM $(MY_OBJS)
TO $(LD_FILE)
LIB $(MY_LIBS) $(LIBS)
MAP $(MAP_FILE) HLSXF PLAIN SWIDTH 16
$(LFLAGS)
<

#
# Bump the version...
#
version:
	@bumprev $(VERSION) $(MODNAME)_rev

$(MODNAME)_rev.i:
	@bumprev $(VERSION) $(MODNAME)_rev

$(MODNAME)_rev.h:
	@bumprev $(VERSION) $(MODNAME)_rev

#
# The following files need to be made for each of the ROM versions
#
# coldstart.asm    vers.asm    startexec.asm
#
coldstart.o$(TYPE):	coldstart.asm romconstants.i constants.i $(MODNAME)_rev.i
	$(AS) $*.asm $(AFLAGS) $*.o$(TYPE) -D $(MACHINE)=1 -D $(LOC)=1

startexec.o$(TYPE):	startexec.asm romconstants.i
	$(AS) $*.asm $(AFLAGS) $*.o$(TYPE) -D $(MACHINE)=1 -D $(LOC)=1

alert.o$(TYPE):	alert.asm romconstants.i
	$(AS) $*.asm $(AFLAGS) $*.o$(TYPE) -D $(MACHINE)=1 -D $(LOC)=1

offsets.o:	offsets.asm	exec_lib.i

debug.lib:	debug.o
	@Copy debug.o debug.lib

#
# Release just the headers
#
headers:	$(PUBLIC_HDR)
	copy $(PUBLIC_HDR) V:include/exec NOPRO

#
# Release the current build to the server
#
internal:
	@delete $(REMOTE)/((\#?.(c|h|asm|i|rev|doc|sfd|ld|ld.\#?))|makefile|lmkfile)
	@protect ((\#?.(c|h|asm|i|ld|rev|doc|sfd))|makefile|lmkfile) +r quiet
	@copy ((\#?.(c|h|asm|i|rev|doc|sfd|ld|ld.\#?))|makefile|lmkfile) $(REMOTE)
	@copy \#?.doc V:doc NOPRO
	@copy \#?.sfd V:lib/sfd NOPRO

#
# Blow away all files that would need to be rebuilt
#
clean:
	@delete (\#?.o|\#?.o.\#?|$(MODNAME).doc|$(MODNAME).ld\#?|$(MODNAME).map\#?)

#
# Make the AutoDocs
#
doc:	$(MODNAME).doc

$(MODNAME).doc:	$(MY_C) $(MY_A)
	@Echo "Making $(MODNAME).doc"
	@JOIN <as RAM:$(MODNAME).cat ~? ~< <
	$(MY_A) $(MY_C) ;
	<
	@AutoDoc >$(MODNAME).doc RAM:$(MODNAME).cat
	@Delete RAM:$(MODNAME).cat QUIET
	@Protect $(MODNAME).doc +rwd

#
# Make a complete new release (This still is in testing...)
#
release:
	$(MAKE) clean
	$(MAKE) version
	$(MAKE)
	$(MAKE) doc
	$(MAKE) headers
	$(MAKE) internal

#
# The following rule is to bring the source down to the local directory
# To do the following you should copy this LMKfile to the local directory
# and make sure it is readable.  Then type MAKE ToLocal to have the
# code copied down...
#
tolocal:
	@protect \#? rwed QUIET
	@copy $(REMOTE)/\#? ""
	@protect \#? +r QUIET
	@protect \#?_rev\#? rwd QUIET
	@Echo "Local is updated..."
