# Makefile for stm projects

# !! THIS VERSION ASSUME THE DOT-H version of stm.c

#
# COURSE V22.0202: Operating Systems, Fall 2006
# Prof.Yap 
# 
############################################################

############################################################
# VARIABLES
############################################################

# EXE should be .exe for windows and cygwin, and blank for unix.
EXE=
EXE=.exe

stmVer=
sosVer=2

dbg=2
dbg=0

stm=stm${stmVer}
sos=sos${sosVer}

p=stm${stmVer}
p=sos${stmVer}

############################################################
# TARGETS
############################################################

h:
	${sos}${EXE} -d ${dbg} hello.stm

d:
	${sos}${EXE} -d ${dbg} dump.stm

e:
	${sos}${EXE} -d ${dbg} echo.stm

t test: a
	${sos}${EXE} -d ${dbg} test.stm

a test-assem:
	assem2.pl test.asm
	
######################################### Testing Primes
t1 test1 primes: ${sos}${EXE} primes.stm
	@echo "Type any positive number n, and this program will compute"
	@echo "    all primes less than n.  E.g. n=7 will print 2, 3, 5."
	${sos}${EXE} -d ${dbg} primes.stm
	@echo "End of testing primes"

######################################### Testing Sort
t2 test2 sort: ${sos}${EXE} sort.stm
	@echo "Type any list of numbers (separated by white spaces or newlines)."
	@echo "    newlines).  End with -1." 
	@echo "    The list will be printed in sorted order."
	@echo "    E.g., typing 5 2 1 9 -1 will result in 1 2 5 9."
	${sos}${EXE} -d ${dbg} sort.stm
	@echo "End of testing sort"

######################################### Testing Sort
t3 test3 fraction: ${sos}${EXE} fraction2.stm
	@echo "Type four number: N D B L "
	@echo "    (separated by white spaces or newlines)." 
	@echo "    The sort program will print L digits of the fraction N/D"
	@echo "    in base B.  E.g., typing 1 3 10 4 will result in 3 3 3 3."
	@echo "    (Since 1/3 in base 10 is 0.3333...).  Try 1 2 10 4."
	@echo "    Make sure that N < D."
	${sos}${EXE} -d ${dbg} fraction2.stm
	@echo "End of testing fraction"

######################################### 
p:
	gcc -o ${p}${EXE} ${p}.c

######################################### 
stm ${stm}.o:
	gcc -c ${stm}.c -o ${stm}.o 

######################################### 
os sos ${sos}${EXE}: ${stm}.o
	gcc ${stm}.o ${sos}.c -o ${sos}${EXE}

############################################################
# House keeping
############################################################
tar:
	-@tar cvf stm.tar \
		Makefile stm*.c stm*.h \
			sos*.c sos*.h \
			queue.* \
			*.stm \
			assem* \
			README* \

clean:
	rm -f *.o

veryclean: clean
	rm -f *.exe
############################################################
# END
############################################################
