# 
# Midway Distributed Shared Memory System
# Copyright (c) 1994 Carnegie Mellon University
# All Rights Reserved.
# 
# Permission to use, copy, modify and distribute this software and its
# documentation is hereby granted, provided that both the copyright
# notice and this permission notice appear in all copies of the
# software, derivative works or modified versions, and any portions
# thereof, and that both notices appear in supporting documentation.
# 
# CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
# ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#VERSION=BSD
VERSION=MACH -DMIDWAY

all: crt0.o mcrt0.o test

crt0.o:	crt0.c makefile
	cc -O2 -S -D${VERSION} crt0.c
	sed	-e 's<__start:<__start: la $$28,_gp;move $$4,$$29<' \
		-e 's<\.option<\#\.option<' \
		-e 's<jal.*fixup_sp<move $$29, $$4<' \
		crt0.s > crt0t.s && mv crt0t.s crt0.s
	cc -O2 -c crt0.s  # && rm -f crt0.s
	@ld -x -r crt0.o
	@mv a.out crt0.o

mcrt0.o:	crt0.c makefile
	cc -O2 -S -DMCRT0 -D${VERSION} crt0.c
	@sed	-e 's<__start:<__start: la $$28,_gp;move $$4,$$29<' \
		-e 's<\.option<\#\.option<' \
		crt0.s > mcrt0.s && rm -f crt0.s
	cc -O2 -c mcrt0.s && rm -f mcrt0.s
	@ld -x -r mcrt0.o
	@mv a.out mcrt0.o

test:	test.c
	@echo "Testing new crt0.o ..."
	@cc -c -D${VERSION} test.c
	@ld -G 8 -g0 -o test crt0.o test.o -lthreads -lmach -lc
	@test for crt0.o >and.the.actual.result
	@echo "test for crt0.o " >out2
	@printenv >out3
	@cat out2 out3 >the.expected.result && rm -f out2 out3
	@cmp the.expected.result and.the.actual.result
	@echo "Test passed ok"
	@-rm -f test test.o the.expected.result and.the.actual.result

clean:
	-rm -f crt0.o test
