CFLAGS=	  @CFLAGS@
CFLAGS_KMODULE=	  @CFLAGS_KMODULE@
CC=	  @CC@
LD=       @LD@
SMP=	  @SMP@
MODVERSIONS=@MODVERSIONS@
KVER=	  @KVER@
KDIR=     @KTOPDIR@
SBINDIR=  @prefix@/sbin
KMODDIR=  @KMODDIR@
ARCH=	  @ARCH@

ifdef	SMP
CFLAGS+=-D__SMP__
endif
ifdef	MODVERSIONS
CFLAGS+=-DMODVERSIONS -include /usr/include/linux/modversions.h $(MODS)
endif

CFLAGS+=-I$(KDIR)/include

SUB_DIRS  = $(ARCH)
PROGS=
PROGS_MOD=lkst_mod_trc.o lkst_mod_panicdump.o
PROGS_PL=

export	CPPFLAGS CFLAGS AFLAGS
export  CFLAGS_KMODULE CC LD SMP KVER KDIR ARCH SBINDIR

all: $(PROGS) $(PROGS_MOD) subdirs_make

subdirs_make: 
	for dir in $(SUB_DIRS); do \
		[ -f $$dir/Makefile ] || continue; \
		$(MAKE) -C $$dir; \
	done

install: $(PROGS) $(PROGS_PL) $(PROGS_MOD)
	for dir in $(SUB_DIRS); do \
		[ -f $$dir/Makefile ] || continue; \
		( $(MAKE) -C $$dir install; ); \
	done
	[ -d $(SBINDIR) ] || mkdir -p $(SBINDIR)
	for p in $(PROGS) $(PROGS_PL); do \
	  install -c -m 755 $$p $(SBINDIR)/$$p; \
	done
	[ -d $(KMODDIR)/kernel/drivers/lkst ] || \
	  mkdir -p $(KMODDIR)/kernel/drivers/lkst
	for p in $(PROGS_MOD); do \
	  install -c -m 644 $$p $(KMODDIR)/kernel/drivers/lkst/$$p; \
	done

uninstall:
	for dir in $(SUB_DIRS); do \
		[ -f $$dir/Makefile ] || continue; \
		( $(MAKE) -C $$dir uninstall; ); \
	done
	for p in $(PROGS) $(PROGS_PL); do \
	  rm -f $(SBINDIR)/$$p; \
	done
	for p in $(PROGS_MOD); do \
	  rm -f $(KMODDIR)/kernel/drivers/lkst/$$p; \
	done

clean :
	for dir in $(SUB_DIRS); do \
		[ -f $$dir/Makefile ] || continue; \
		( $(MAKE) -C $$dir clean; ); \
	done
	-rm -f $(PROGS) *.o core

distclean: clean
	for dir in $(SUB_DIRS); do \
		[ -f $$dir/Makefile ] || continue; \
		( $(MAKE) -C $$dir distclean; ); \
	done
	-rm -rf autom*.cache
	-rm -f config.* *~ Makefile configure .config

lkst_mod_trc.o: lkst_mod_trc.c
	$(CC) $(CFLAGS) $(CFLAGS_KMODULE) -c -o $@ $*.c

lkst_mod_panicdump.o: lkst_mod_panicdump.c
	$(CC) $(CFLAGS) $(CFLAGS_KMODULE) -c -o $@ $*.c

