# $Id: Makefile.in,v 1.10 2002/06/28 11:27:53 indoh Exp $

CFLAGS=	  @CFLAGS@
CC=	  @CC@
LD=       @LD@
SMP=	  @SMP@
MODVERSIONS=@MODVERSIONS@
KVER=	  @KVER@
KDIR=     @KTOPDIR@
prefix=  @prefix@
SBINDIR=  $(prefix)/sbin

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

CFLAGS+=-I$(KDIR)/include
CFLAGS_LKCD=-I/usr/include/lkcd

SUB_DIRS  = man
PROGS=lkst lkstm lkstbuf lksteh lkstlogger lkstlogd
PROGS_PL=logformat.pl
PROGS_LKCDLIB=lkstdumplib.so
PROGS_LKCDSIAL=lkstdump.sial
LKSTLOGD_LOGDIR=/var/log/lkst
LKCDSIALDIR=$(prefix)/share/sial/lcrash

all: $(PROGS) $(PROGS_LKCDLIB) subdirs_make

subdirs_make: 
	for dir in $(SUB_DIRS); do \
		$(MAKE) -C $$dir; \
	done

install: $(PROGS) $(PROGS_PL) $(PROGS_LKCDLIB) $(PROGS_LKCDSIAL)
	mkdir -p $(LKSTLOGD_LOGDIR)
	for dir in $(SUB_DIRS); do \
		( $(MAKE) -C $$dir install; ); \
	done
	for p in $(PROGS) $(PROGS_PL); do \
	  install -c -m 755 $$p $(SBINDIR)/$$p; \
	done
	install -c -m 644 $(PROGS_LKCDSIAL) $(LKCDSIALDIR)/
	install -c -m 755 $(PROGS_LKCDLIB) $(LKCDSIALDIR)/


uninstall:
	for dir in $(SUB_DIRS); do \
		( $(MAKE) -C $$dir uninstall; ); \
	done
	for p in $(PROGS) $(PROGS_PL); do \
	  rm -f $(SBINDIR)/$$p; \
	done
	rmdir $(LKSTLOGD_LOGDIR)
	rm -f $(LKCDSIALDIR)/$(PROGS_LKCDSIAL)
	rm -f $(LKCDSIALDIR)/$(PROGS_LKCDLIB)

clean :
	for dir in $(SUB_DIRS); do \
		( $(MAKE) -C $$dir clean; ); \
	done
	-rm -f $(PROGS) *.o *.so core

distclean: clean
	-rm -f config.* *~ Makefile configure .config

lkst : lkst.c command.c buffer.c maskset.c evhandler.c
lkstbuf : lkstbuf.c command.c buffer.c
lkstm : lkstm.c command.c maskset.c
lksteh : lksteh.c command.c evhandler.c
lkstlogger : lkstlogger.c command.c
lkstlogd : lkstlogd.c command.c
lkstdumplib.so : lkstdumplib.o
	$(CC) -shared -o lkstdumplib.so lkstdumplib.o
lkstdumplib.o :
	$(CC) $(CFLAGS) $(CFLAGS_LKCD) -O -c -fPIC -o $@ lkstdumplib.c

