#----------------------------------------------------------------------------
# 
#  USAGE:	make install
# 
#  DESCRIPTION: performs code patching and prepares files as required for
#		installing RCI on a SPARC SUNOS 4.1 system.
# 
#  AUTHOR/DATE: John Lloyd, 1990
#
#  MODIFICATION HISTORY:
# 
#----------------------------------------------------------------------------

OBJD = ../sun4/OBJ

PATCH =		$(OBJD)/sparc_subr.o \
		$(OBJD)/locore.o \
		$(OBJD)/trap.o \
		$(OBJD)/kern_mman.o

ORIG = 		$(OBJD)/sparc_subr.o.orig \
		$(OBJD)/locore.o.orig \
		$(OBJD)/trap.o.orig \
		$(OBJD)/kern_mman.o.orig

support:	assym.s mctlFix patchsym move

install:	support $(PATCH)

clean:
		rm -f *.o patchsym mctlFix assym.s

assym.s: 	genassym
		genassym > assym.s

genassym:	genassym.o
		$(CC) -o genassym genassym.o

mctlFix:	mctlFix.o
		$(CC) -o mctlFix mctlFix.o

patchsym:	patchsym.o
		$(CC) -o patchsym patchsym.o

move:		move.o
		$(CC) -o move move.o

$(OBJD)/locore.o.orig: 
		cp $(OBJD)/locore.o $(OBJD)/locore.o.orig

locore1.o: 	locore1.s
		as -o locore1.o locore1.s

locore2.o: 	$(OBJD)/locore.o.orig
		cp $(OBJD)/locore.o.orig locore2.o
		patchsym locore2.o intstack intstk..
#		subst intstack intstk.. < $(OBJD)/locore.o.orig | \
#			subst eintstk.. eintstack > locore2.o

$(OBJD)/locore.o:	locore1.o locore2.o
		@echo ""
		@echo "*** Patching $@ ***"	
		@echo ""
		ld -r -o $(OBJD)/locore.o locore1.o locore2.o

# hardclock patch now done on line ...
#$(OBJD)/kern_clock.o.orig: 
#		cp $(OBJD)/kern_clock.o $(OBJD)/kern_clock.o.orig
#
#$(OBJD)/kern_clock.o: $(OBJD)/kern_clock.o.orig
#		cp $(OBJD)/kern_clock.o.orig \#_tmp.o
#		@echo ""
#		@echo "*** Patching $@ ***"
#		@echo ""
#		patchsym \#_tmp.o _hardclock _LMT_clock
#		mv \#_tmp.o $(OBJD)/kern_clock.o

$(OBJD)/sparc_subr.o.orig: 
		cp $(OBJD)/sparc_subr.o $(OBJD)/sparc_subr.o.orig

$(OBJD)/sparc_subr.o: $(OBJD)/sparc_subr.o.orig
		cp $(OBJD)/sparc_subr.o.orig \#_tmp.o
		@echo ""
		@echo "*** Patching $@ ***"
		@echo ""
		patchsym \#_tmp.o _spl0 XX__0 \
				  _spl1 XX__1 \
				  _spl2 XX__2 \
				  _spl3 XX__3 \
				  _spl4 XX__4 \
				  _spl5 XX__5 \
				  _spl6 XX__6 \
				  _spl7 XX__7 \
				  _spl8 XX__8 \
				  _splzs XX__zs \
				  _spltty XX__tty \
				  _splbio XX__bio \
				  _splaudio XX__audio \
				  _splx XX__x
		mv \#_tmp.o $(OBJD)/sparc_subr.o

$(OBJD)/trap.o.orig: 
		cp $(OBJD)/trap.o $(OBJD)/trap.o.orig

$(OBJD)/trap.o: $(OBJD)/trap.o.orig
		cp $(OBJD)/trap.o.orig \#_tmp.o
		@echo ""
		@echo "*** Patching $@ ***"
		@echo ""
		patchsym \#_tmp.o _syscall _LMTcall \
				  _trap _LMTt
		mv \#_tmp.o $(OBJD)/trap.o

$(OBJD)/kern_mman.o.orig: 
		cp $(OBJD)/kern_mman.o $(OBJD)/kern_mman.o.orig

$(OBJD)/kern_mman.o: $(OBJD)/kern_mman.o.orig
		@echo ""
		@echo "*** Patching $@ ***"
		@echo ""
		cp $(OBJD)/kern_mman.o.orig \#_tmp.o
		rm -f core
		@echo "mctlFix \#_tmp.o /vmunix"
		@ if mctlFix \#_tmp.o /vmunix ; then \
		   mv \#_tmp.o $(OBJD)/kern_mman.o ; \
		else \
echo "" ; echo "patch to kern_mman.o failed ... " ; echo "" ; \
echo "Make sure that /vmunix is an original, non-RCI kernel, and then " ; \
echo "run 'make install' again. Otherwise, you can ignore the patch " ; \
echo "to kern_mman.o, but it means that RCCL/RCI programs will have to" ; \
echo "be run from a super user account. " ; \
		fi


