# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html
#
# Portions Copyright (c) 2003 Apple Computer, Inc.

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config

CFLAGS=${LWP_DBG} ${LWP_OPTMZ} ${XCFLAGS} ${ARCHFLAGS} ${COMMON_INCL}

LIBOBJS=lwp.o process.o lock.o iomgr.o timer.o fasttime.o preempt.o \
	waitkey.o threadname.o AFS_component_version_number.o

all: ${TOP_LIBDIR}/liblwp.a ${TOP_INCDIR}/lock.h ${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/preempt.h ${TOP_INCDIR}/timer.h

depinstall: ${TOP_INCDIR}/lock.h ${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/preempt.h ${TOP_INCDIR}/timer.h

#
# Build rules
#
liblwp.a: ${LIBOBJS}
	-$(RM) -f $@
	$(AR) crv $@ ${LIBOBJS}
	$(RANLIB) $@

# This is required so sgi_64+ does not try to build this file.
process.s:
	@echo Nothing to be done for process.s

# Making process.o for $(SYS_NAME)
process.o	: process.s process.i386.s process.c
	@set -x; case "$(SYS_NAME)" in \
	pmax_he1) \
		$(CCOBJ) ${LWP_DBG} ${LWP_OPTMZ} -c -I${TOP_INCDIR} process.s;; \
	sun4c_51 | sun4c_52 | sun4m_51 | sun4m_52 | sun4c_53 | sun4m_53  | sun4_53 | sun4_52 | sun4_54 | sun4c_54 | sun4m_54 | sun4x_5* ) \
		/usr/ccs/lib/cpp -P -I${TOP_INCDIR} ${srcdir}/process.s process.ss; \
		${AS} process.ss -o process.o; \
			$(RM) process.ss ;; \
	sgi_5* ) \
		$(CCOBJ) ${LWP_DBG} ${LWP_OPTMZ} -c -I${TOP_INCDIR} -KPIC -G0  ${srcdir}/process.s;; \
	sgi_61 | sgi_62 | sgi_63 ) \
		$(CCOBJ) ${LWP_DBG} ${LWP_OPTMZ} -c ${XCFLAGS} ${ARCHFLAGS} -I${TOP_INCDIR} -KPIC -G0  ${srcdir}/process.s;; \
	s390_*) \
		/lib/cpp -P -I${TOP_INCDIR} ${srcdir}/process.s390.s >process.ss; \
		${AS} -ahlns process.ss -o process.o >process.lst; \
		$(RM) process.ss ;; \
	s390x_*) \
		/lib/cpp -P -I${TOP_INCDIR} ${srcdir}/process.s390x.s >process.ss; \
		${AS} -ahlns process.ss -o process.o >process.lst; \
		$(RM) process.ss ;; \
	*_darwin* ) \
		ppc=`echo "${ARCHFLAGS}" | grep -q -w ppc && echo yes` ; \
		i386=`echo "${ARCHFLAGS}" | grep -q -w i386 && echo yes` ; \
		if [ -z "$${ppc}" -a -z "$${i386}" ] ; then \
			if [ `arch` = ppc ] ; then \
				ppc=yes ; \
			else \
				i386=yes ; \
			fi ; \
		fi ; \
		if [ -n "$${ppc}" ] ; then \
			$(CC) ${LWP_DBG} ${LWP_OPTMZ} -c -arch ppc -I${TOP_INCDIR} ${srcdir}/process.s -o process.ppc.o ; \
			if [ -z "$${i386}" ] ; then \
				${MV} process.ppc.o process.o ; \
			fi ; \
		fi ; \
		if [ -n "$${i386}" ] ; then \
			$(CC) -x assembler-with-cpp -c -arch i386 -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.i386.s -o process.i386.o ; \
			if [ -z "$${ppc}" ] ; then \
				${MV} process.i386.o process.o ; \
			fi ; \
		fi ; \
		if [ -n "$${ppc}" -a -n "$${i386}" ] ; then \
			lipo -create process.ppc.o process.i386.o -output process.o ;\
		fi ;; \
	i386_*bsd*) \
		cp ${srcdir}/process.i386.s process.S ; \
		${CCOBJ} -DIGNORE_STDS_H -E -I${srcdir} -I${TOP_INCDIR} process.S > process.ss ; \
		${AS} process.ss -o process.o ;  \
		$(RM) -f process.S ;;\
	amd64_*bsd*) \
		cp ${srcdir}/process.amd64.s process.S ; \
		${CCOBJ} -DIGNORE_STDS_H -E -I${srcdir} -I${TOP_INCDIR} process.S > process.ss ; \
		${AS} process.ss -o process.o ;  \
		$(RM) -f process.S ;;\
	ncrx86_* | sunx86_*) \
		/usr/ccs/lib/cpp -P -D__sun -D__i386 -DIGNORE_STDS_H -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.i386.s process.ss; \
		${AS} -o process.o process.ss; \
		$(RM) process.ss ;; \
	alpha_nbsd* ) \
		/usr/bin/cpp -DASSEMBLER -P -I${TOP_INCDIR} ${srcdir}/process.s > process.ss; \
		${AS} -o process.o process.ss; \
		$(RM) process.ss ;; \
	hp* | *_linux* | *_umlinux* | sgi_64 | sgi_65 ) \
		${CCOBJ} ${CFLAGS} -c ${srcdir}/process.c;; \
	alpha_osf1 | alpha_osf20 |  alpha_osf30 | alpha_osf32 | alpha_osf32c | alpha_dux?? ) \
		${AS} -v  -P -DOSF -I${TOP_INCDIR} -DASSEMBLER ${srcdir}/process.s; \
		${AS} -v process.i -o process.o;; \
	ia64_hpux11* | hp_ux11* ) \
		${CC} ${CFLAGS} -c ${srcdir}/process.c;; \
	i386_*) \
		/lib/cpp -P -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.i386.s process.ss; \
		${AS} process.ss -o process.o; \
		$(RM) process.ss ;; \
	*) \
		/lib/cpp -P -I${TOP_INCDIR} ${srcdir}/process.s process.ss; \
		${AS} process.ss -o process.o; \
		$(RM) process.ss ;; \
	esac

iomgr.o		: iomgr.c lwp.h timer.h
		${CCOBJ} -c ${CFLAGS} ${srcdir}/iomgr.c

preempt.o	: preempt.c lwp.h preempt.h
lwp.o		: lwp.c lwp.h
	case "$(SYS_NAME)" in \
		rs_aix*) \
			$(CCOBJ) ${LWP_DBG} ${LWP_OPTMZ} -I${srcdir} -I. -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -c ${srcdir}/lwp.c;; \
		*)  \
			$(CCOBJ) ${CFLAGS} -c ${srcdir}/lwp.c;; \
		esac
lock.o		: lock.c lock.h lwp.h
timer.o		: timer.c
fasttime.o	: fasttime.c
threadname.o    : threadname.c

exc_handling.o	: exc_handling.c

#
# tests
#
rw: rw.o liblwp.a $(TOP_LIBDIR)/util.a
	${CC} ${CFLAGS} -o rw rw.o liblwp.a $(TOP_LIBDIR)/util.a

rw.o: rw.c
	${CC} ${CFLAGS} -c ${srcdir}/rw.c


#
# Install targets
#
install: ${DESTDIR}${libdir}/liblwp.a ${DESTDIR}${includedir}/lock.h ${DESTDIR}${includedir}/lwp.h ${DESTDIR}${includedir}/preempt.h ${DESTDIR}${includedir}/timer.h

${DEST}/lib/liblwp.a: liblwp.a
	${INSTALL} $? $@

${DEST}/include/lock.h: lock.h
	${INSTALL} $? $@

${DEST}/include/lwp.h: lwp.h
	${INSTALL} $? $@

${DEST}/include/preempt.h: preempt.h
	${INSTALL} $? $@

${DEST}/include/timer.h: timer.h
	${INSTALL} $? $@

#
# Misc. targets
#
clean:
	$(RM) -f *.o *.a core AFS_component_version_number.c

include ../config/Makefile.version
${DESTDIR}${libdir}/liblwp.a: liblwp.a
	${INSTALL} $? $@

${TOP_LIBDIR}/liblwp.a: liblwp.a
	${INSTALL} $? $@

${DESTDIR}${includedir}/lock.h: lock.h
	${INSTALL} $? $@

${TOP_INCDIR}/lock.h: lock.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/lwp.h: lwp.h
	${INSTALL} $? $@

${TOP_INCDIR}/lwp.h: lwp.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/preempt.h: preempt.h
	${INSTALL} $? $@

${TOP_INCDIR}/preempt.h: preempt.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/timer.h: timer.h
	${INSTALL} $? $@

${TOP_INCDIR}/timer.h: timer.h
	${INSTALL} $? $@

dest: ${DEST}/lib/liblwp.a ${DEST}/include/lock.h ${DEST}/include/lwp.h ${DEST}/include/preempt.h ${DEST}/include/timer.h

