libthread: Apple OS X 10.5 (Leopard) tweaks (Jeff Sickel, Bakul Shah)
diff --git a/src/libthread/mkfile b/src/libthread/mkfile
index ac9e260..99f899c 100644
--- a/src/libthread/mkfile
+++ b/src/libthread/mkfile
@@ -19,15 +19,15 @@
 OpenBSD.$O FreeBSD.$O: BSD.c
 NetBSD.$O: Linux.c
 
-tprimes: tprimes.$O
-	9l -o $target $target.$O $PLAN9/lib/$LIB -l9 -lpthread
-tspawn: tspawn.$O
-	9l -o $target $target.$O $PLAN9/lib/$LIB -l9 -lpthread
-tspawnloop: tspawnloop.$O
-	9l -o $target $target.$O $PLAN9/lib/$LIB -l9 -lpthread
+tprimes: test/tprimes.$O
+	9l -o $target test/$target.$O
+tspawn: test/tspawn.$O
+	9l -o $target test/$target.$O
+tspawnloop: test/tspawnloop.$O
+	9l -o $target test/$target.$O
 
 %.$O: %.c
-	$CC $CFLAGS -I. $stem.c
+	$CC -o $target $CFLAGS -I. $stem.c
 
 # cannot use generic .S rule because it conflicts
 # with generic .s rule in mkcommon on case-insensitive
diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh
index cdc1ad0..a683662 100644
--- a/src/libthread/sysofiles.sh
+++ b/src/libthread/sysofiles.sh
@@ -20,9 +20,12 @@
 *-NetBSD-*)
 	echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o
 	;;
-*-Darwin-*)
+*-Darwin-[6-8].*)
 	echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o pthread.o
 	;;
+*-Darwin-*)
+	echo pthread.o
+	;;
 *-OpenBSD-*)
 	echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o $SYSNAME.o
 	;;
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index bc18d3a..3d68299 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -21,7 +21,7 @@
 extern	void		makecontext(ucontext_t*, void(*)(), int, ...);
 #endif
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(__DARWIN_UNIX03)
 #	define mcontext libthread_mcontext
 #	define mcontext_t libthread_mcontext_t
 #	define ucontext libthread_ucontext