MCRASH_VERSION	= 1.11
HDRS	= crash.h def.h
CSRCS	= main.c table.c subr.c dump.c superblock.c filesystem.c\
	  module.c sys_call.c expr.c statement.c console.c sizeof.c\
	  semaphore.c task.c date.c cmds.c dmesg.c clean_jiffies.c utsname.c
TARGET	= mcrash
STRIPPED_TARGET = $(TARGET).strip
DEPFILE	= Makefile.dep

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

all: config
	$(MAKE)

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

else

include	Rules.make

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

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

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

all: $(CRLIB) $(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)

$(SUBVERS): FORCE
	$(MAKE) -C Linux$(LINUXVER)

$(SUBARCH): FORCE
	$(MAKE) -C $(ARCHDIR)

$(SUBXFS): FORCE
	$(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 core core.*
	- $(MAKE) -C Linux$(LINUXVER) clean
	- $(MAKE) -C $(ARCHDIR) clean
	- $(MAKE) -C xfs clean

endif

FORCE:

config:
	./configure

depend:
	makedepend -f- $(INCLUDE) $(CSRCS) > $(DEPFILE)
	- $(MAKE) -C Linux$(LINUXVER) depend
	- $(MAKE) -C $(ARCHDIR) depend
	- $(MAKE) -C xfs depend

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

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

ifeq ($(wildcard $(DEPFILE)),$(DEPFILE))
include $(DEPFILE)
endif
