MCRASH_VERSION	= 1.1
HDRS	= crash.h def.h
CSRCS	= main.c table.c subr.c dump.c superblock.c filesystem.c dentry.c\
	  module.c sys_call.c expr.c statement.c console.c sizeof.c\
	  semaphore.c task.c date.c cmds.c
TARGET	= mcrash
STRIPPED_TARGET = $(TARGET).strip

ifneq ($(wildcard Rules.make),Rules.make)

all: config
	$(MAKE)

clean:
	/bin/rm -f *.o *~ *.swp DOC/ja/*~ DOC/ja/*.swp

else

include	Rules.make

CFLAGS	= $(CDEBUG) -I$(INCDIR)
bindir	= $(prefix)/bin
docdir	= $(prefix)/doc
FULLVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)

ifeq ($(wildcard arch/$(ARCH)),arch/$(ARCH))
ARCHDIR	= arch/$(ARCH)
else
ARCHDIR	= arch/dummy
endif

CRLIB	= Linux$(LINUXVER)/libmcrash.a $(ARCHDIR)/libarch.a xfs/libxfs.a

all: subdirs $(STRIPPED_TARGET)

$(STRIPPED_TARGET): $(TARGET)
	/bin/cp $(TARGET) $(STRIPPED_TARGET)
	/usr/bin/strip $(STRIPPED_TARGET)

$(TARGET): $(OBJS) $(CRLIB) version.o
	$(CC) $(OBJS) version.o $(CRLIB) $(LIBS) -o $@

version.o: version.c
	$(CC) -c -DKERNEL=\"$(FULLVERSION)/$(ARCH)\" -DMCRASH_VERSION=\"$(MCRASH_VERSION)\" -DDATE=`date +\"%Y%m%d\"` version.c

$(OBJS): $(HDRS)

subdirs: subvers subarch subxfs

subvers:
	$(MAKE) -C Linux$(LINUXVER)

subarch:
	$(MAKE) -C $(ARCHDIR)

subxfs:
	$(MAKE) -C xfs

install: all
	if [ ! -d $(bindir) ]; then mkdir -p $(bindir); fi
	umask 022; /bin/cp $(STRIPPED_TARGET) $(bindir)/$(TARGET)-for$(FULLVERSION)
	/bin/rm -f $(bindir)/$(TARGET)
	/bin/ln -s $(TARGET)-for$(FULLVERSION) $(bindir)/$(TARGET)
	if [ ! -d $(docdir)/$(TARGET)-$(MCRASH_VERSION) ]; then mkdir -p $(docdir)/$(TARGET)-$(MCRASH_VERSION); fi
	umask 022; /bin/cp -r DOC/* $(docdir)/$(TARGET)-$(MCRASH_VERSION)

clean:
	/bin/rm -f *.o *~ *.swp DOC/ja/*~ DOC/ja/*.swp
	$(MAKE) -C Linux$(LINUXVER) clean
	$(MAKE) -C $(ARCHDIR) clean
	$(MAKE) -C xfs clean

endif

config:
	./configure

distclean: clean
	/bin/rm -f $(TARGET) $(STRIPPED_TARGET) Rules.make config.h makelog index.*

tarball: distclean
	grep -q "^Version: *$(MCRASH_VERSION)$$" sample/$(TARGET).spec.sample
	D=`basename \`pwd\``; cd ..; tar czf $(TARGET)-$(MCRASH_VERSION).tar.gz $$D
