#
#  Makefile for kstrax 
#

ARCH = $(shell uname -m)

ifeq ($(ARCH),ia64)
MODULE = ../module
ARCH_SRC = arch/ia64
CFLAGS = -I$(MODULE)/$(ARCH_SRC)/ \
	 -I$(MODULE) \
	 -I$(ARCH_SRC) \
	 -D_IA64_KSTRAX_

KS_REC = ia64_kstrax-rec

else

MODULE = ../module
ARCH_SRC = arch/i386
CFLAGS = -I$(MODULE)/$(ARCH_SRC)/ \
	 -I$(MODULE)/ \
	 -I$(ARCH_SRC)/

KS_REC = i386_kstrax-rec
endif

CC    = gcc
OBJS   = kstrax.o kstrax_buf.o syscall_name.o
TARGET = kstrax
SCRIPT = kstrax-simple kstrax-rec kstrax-filter kstrax-graph \
	 kstrax-graph-count.gp kstrax-graph-average.gp \
	 kstrax-graph-total.gp kstrax-graph-all.gp \
	 kstrax-graph-exec.gp kstrax-graph-count+.gp \
	 kstrax-graph-average+.gp kstrax-graph-total+.gp \
	 kstrax-graph-count++.gp kstrax-graph-average++.gp \
	 kstrax-graph-total++.gp kstrax-graph-exec-c.gp

SBINDIR= /usr/sbin
BINDIR= /usr/bin
PROGS = kstrax

RM     = rm -f
VERSION = $(findstring 2.4,$(shell uname -r))

all:$(TARGET)

$(TARGET): $(OBJS)
	$(CC) -o $@ $(OBJS) -Wall -lpthread $(CFLAGS)

#suffix rule
syscall_name.o:$(ARCH_SRC)/syscall_name.c
	$(CC) -c $(ARCH_SRC)/syscall_name.c -Wall $(CFLAGS)

.c.o:
	$(CC) -c $< -Wall $(CFLAGS)

install: $(TARGET)
	cp $(PROGS) $(SBINDIR); \
	cd ../script; \
	cp $(KS_REC) kstrax-rec; \
	cp $(SCRIPT) $(SBINDIR); \
	rm kstrax-rec

uninstall:
	@( for p in $(PROGS) $(SCRIPT) ; do \
	  echo "rm -f" $(SBINDIR)/$$p; \
	  rm -f $(SBINDIR)/$$p; \
	done )

distclean: clean

clean:
	$(RM) $(TARGET) $(OBJS)

kstrax.o:kstrax.h kstrax_buf.h $(ARCH_SRC)/syscall_name.h $(ARCH_SRC)/kstrax_arch.h
kstrax_buf.o:kstrax.h kstrax_buf.h $(ARCH_SRC)/syscall_name.h $(ARCH_SRC)/kstrax_buf_arch.h
