#
# Copyright (c) 1998, 1999 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

#
# There are three targets:
#
# 1) unix_support.o: for non-pthread programs. Override equiv implementations
#    in the device and clientos library, plus a couple of others.
# 2) unix_support_pthread.o: Almost the same set of files as (1), but with
#    the addition of some files that override stuff in the threads library.
# 3) liboskit_unix.o: The optional stuff, that is only used by unix mode
#    programs. Mostly overrides stuff in other libraries.
#
TARGETS       = liboskit_unix.a unix_support_pthreads.o unix_support.o

#
# This stuff overrides the equivalent osenv code in dev library.
# Both pthread and nonpthread programs need all this stuff.
#
OSENV         = osenv.o osenv_rtc.o osenv_intr.o pit.o rtclock.o irq.o \
		unix_mem.o dlmalloc.o base_stack.o

#
# These are the list of objects that get summarily shoved into the program.
# pthread and non-pthread programs need a slightly different set of files.
#
NOPTHREAD_OBJ = $(OSENV) mem_lock.o stdio.o fd.o
PTHREAD_OBJ   = $(OSENV) pthread_guard.o threaded_stdio.o threaded_fd.o

#
# This is the optional stuff. Note that the UNIX_HOST makefile will add
# to this list.
#
UNIXLIB_OBJ   = oskit_linux_block.o bmodfs.o filesystem.o libkern.o hexdump.o \
		base_irq_softint_handler.o set_async_fd.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)

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

include $(OSKIT_SRCDIR)/unix/$(UNIX_HOST)/GNUmakerules

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

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

liboskit_unix.a: $(UNIXLIB_OBJ)
	$(AR) $(ARFLAGS) $@ $(UNIXLIB_OBJ)
	$(RANLIB) $@

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

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

include $(OSKIT_SRCDIR)/GNUmakerules


$(INSTALL_LIBDIR)/unix/%: %
	-mkdir -p $(INSTALL_LIBDIR)/unix/
	$(INSTALL) $< $@

endif
