#
# Makefile for lcrash
#
# Copyright 1999 Silicon Graphics, Inc. All rights reserved.
#
DEPTH  = .
include $(DEPTH)/commondefs

TARGET    = lcrash
CFILES    = main.c util.c eval.c report.c stabs.c struct.c vmdump.c sial.c \
	    module.c
LIBS      = -lcmds -larch -llkcd_alloc -llkcd_rl -lklib -lncurses -lopcodes \
	    -lbfd -liberty -ldl -lsial -llkcd_util -lz 
LFLAGS    = $(GFLAGS) -rdynamic -L. -L$(TOPDIR) -L$(LKCDDIR)/libklib \
	    -L$(GDB_DIR)/bfd -L$(GDB_DIR)/libiberty -L$(GDB_DIR)/opcodes \
	    -L$(LKCDDIR)/liballoc -L$(LKCDDIR)/librl -L$(LKCDDIR)/libsial \
	    -L$(LKCDDIR)/libutil
OFILES    = $(CFILES:.c=.o)
SUB_DIRS  = man arch/$(ARCH) cmds 

all: default

default: $(TARGET)

$(TARGET): subdirs_make
	$(CC) -o $@ $(LDFLAGS) $(LFLAGS) $(OFILES) $(LIBS)

subdirs_make: $(OFILES)
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) ARCH=$(ARCH); cd .. ); \
	done

clean:
	/bin/rm -f *.o *.a
	/bin/rm -f $(DEPTH)/include/arch
	/usr/bin/find . -name ".[A-z]*.flags" -print | xargs /bin/rm -f
	/usr/bin/find . -name ".depend" -print | xargs /bin/rm -f
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) ARCH=$(ARCH) clean; cd .. ); \
	done

mrproper clobber: clean
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; \
			make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) clobber; cd .. ); \
	done
	/bin/rm -f $(TARGET)

$(OFILES): $(HEADERS)

#
# We avoid this for now -- you'll need to do a make clobber followed
# by a make if you want to fix this later.
#
modules modules_install:

depend dep fastdep: symlinks

$(HEADERS): symlinks

symlinks:
	/bin/rm -f $(DEPTH)/include/asm
	(cd include ; /bin/ln -sf asm-$(ARCH) asm)
	(cd $(LKCDDIR)/libklib ; make ARCH=$(ARCH) symlinks)

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

exports install: headers $(TARGET)
	mkdir -p $(ROOT)/sbin
	mkdir -p $(ROOT)/usr/man/man1
	install -m 755 lcrash $(ROOT)/sbin/lcrash
	install -m 644 man/lcrash.1 $(ROOT)/usr/man/man1
