#
# Makefile for libklib
#
# Copyright 2000 Silicon Graphics, Inc. All rights reserved.
#
DEPTH 	  = .
EXTRA_CFLAGS = $(GFLAGS) -DARCH=$(ARCH) 

# set up include directory search order
EXTRA_CFLAGS += -Iinclude -I../liballoc -I../libutil -I$(TOPDIR)/include

# Turn on strict protype and error checking
EXTRA_CFLAGS += -Wall -Wstrict-prototypes

LIBKLIB   = libklib.a
NAMELIST  = namelist
TARGETS   = $(LIBKLIB) 
CFILES    = klib.c kl_cmp.c kl_libc.c kl_mem.c kl_memory.c kl_nmlist.c \
	    kl_print.c kl_savedump.c kl_signal.c kl_stabs.c kl_symbol.c \
	    kl_task.c kl_typeinfo.c kl_util.c 
OFILES    = $(CFILES:.c=.o)

all: default

default: $(TARGETS)

clean:
	/usr/bin/find . -name ".[A-z]*.flags" -print | xargs /bin/rm -f
	/usr/bin/find . -name ".depend" -print | xargs /bin/rm -f
	(cd arch/$(ARCH) ; make TOPDIR=$(TOPDIR) ARCH=$(ARCH) clean; cd ..)
	/bin/rm -f include/asm
	/bin/rm -f *.o
	/bin/rm -f $(TARGETS)

mrproper clobber: clean
	(cd arch/$(ARCH) ; make TOPDIR=$(TOPDIR) ARCH=$(ARCH) clobber; cd ..)
	/bin/rm -f $(NAMELIST) $(LIBKLIB)

$(NAMELIST): namelist.c
	$(CC) $(EXTRA_CFLAGS) -c namelist.c -o namelist
	
$(LIBKLIB): symlinks $(OFILES)
	make -C arch/$(ARCH) TOPDIR=$(TOPDIR) ARCH=$(ARCH)
	$(AR) ccurl $(LIBKLIB) $(OFILES)

headers: symlinks
	(cd include ; make TOPDIR=$(TOPDIR) ARCH=$(ARCH) headers; cd ..)

exports install: headers $(TARGETS)
	mkdir -p $(ROOT)/usr/lib/lkcd
	install -m 644 $(TARGETS) $(ROOT)/usr/lib/lkcd

symlinks:
	/bin/rm -f include/asm
	(cd include ; /bin/ln -s asm-$(ARCH) asm; cd ..)

include $(DEPTH)/../Rules.make
