#
# Copyright (c) 1998 University of Utah and the Flux Group.
# All rights reserved.
# 
# This file is part of the Flux OSKit.  The OSKit is free software, also known
# as "open source;" you can redistribute it and/or modify it under the terms
# of the GNU General Public License (GPL), version 2, as published by the Free
# Software Foundation (FSF).  To explore alternate licensing terms, contact
# the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
# 
# The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
# received a copy of the GPL along with the OSKit; see the file COPYING.  If
# not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
#

ifndef _oskit_threads_makerules_
_oskit_threads_makerules_ = yes

#
# Need two .o files because of pthread programs. One has everything for
# non-pthread programs and the other has slightly less. The .a file is
# for a few other things that if placed in the .o files, would require
# dragging in the universe.
#
TARGETS       = crt0.o unix_support.o unix_support_pthreads.o
PTHREAD_OBJ   = hexdump.o libkern.o mem_unix.o dlmalloc.o morecore.o \
		oskit_linux_block.o irq.o pit.o rtclock.o net.o sendeth.o \
		unix-helper.o bmodfs.o socket.o threaded_fd.o filesystem.o
NOPTHREAD_OBJ = $(PTHREAD_OBJ) \
		base_irq_softint_handler.o mem_lock.o synch.o panic.o perror.o
PTHREAD_ONLY  = pthread_guard.o threaded_stdio.o
NOPTHREAD_ONLY= stdio.o

SRCDIRS	     += $(OSKIT_SRCDIR)/unix \
		$(OSKIT_SRCDIR)/examples/x86/shared
INCDIRS      += $(OSKIT_SRCDIR)/oskit \
		$(OSKIT_SRCDIR)/oskit/c

OSKIT_CFLAGS += -DNATIVE_BUILD -DOSKIT_UNIX
CLEAN_FILES  += $(TARGETS)
ERROBJ	      = ../freebsd/net/error.o

include $(OSKIT_SRCDIR)/GNUmakerules

all:	$(TARGETS) $(addprefix $(OBJDIR)/lib/, $(TARGETS)) 

unix_support.o: $(NOPTHREAD_OBJ) $(ERROBJ) $(NOPTHREAD_ONLY)
	$(LD) -r -o $@ $(NOPTHREAD_OBJ) $(ERROBJ) $(NOPTHREAD_ONLY)

unix_support_pthreads.o: $(PTHREAD_OBJ) $(PTHREAD_ONLY) $(ERROBJ)
	$(LD) -r -o $@ $(PTHREAD_OBJ) $(PTHREAD_ONLY) $(ERROBJ)

$(OBJDIR)/lib/%: %
	test -d $(OBJDIR)/lib || mkdir $(OBJDIR)/lib
	cp $< $@

#
# These two are special (in a bad way). They need /usr/include stuff
# cause of ioctls and other junk that is defined differently in the
# OSKIT header files.
#
sendeth.o:	sendeth.c
	$(CC) -c -o $@ -I- -I/usr/include $(OSKIT_CFLAGS) $(CFLAGS) $<

net.o:		net.c
	$(CC) -c -o $@ $(OSKIT_CFLAGS) $(CFLAGS) -I/usr/include $<

socket.o:	socket.c
	$(CC) -c -o $@ $(OSKIT_CFLAGS) $(CFLAGS) -I/usr/include $<

filesystem.o:	filesystem.c
	$(CC) -c -o $@ $(OSKIT_CFLAGS) $(CFLAGS) -DKERNEL $<

bmodfs.o:	bmodfs.c
	$(CC) -c -o $@ $(OSKIT_CFLAGS) $(CFLAGS) -I/usr/include $<

crt0.o:		crt0.c
	$(CC) -c -o $@ -DOSKIT -DCRT0 -DDYNAMIC $<
	${LD} -O $@ -x -r $@

install: $(addprefix $(INSTALL_LIBDIR)/,$(TARGETS))

endif
