# 
# This is the makefile for the Linux Trace Toolkit Library.
#
# Initial creation date : 19/06/2001 K.Y.
#
#

# Support
# If 1, will support RTAI (www.rtai.org) traces 
SUPP_RTAI = 1
# If 1, the visualizer will only support native traces
TARGET_NATIVE = 0
# If 1, visualizer will read structs as unpacked
LTT_UNPACKED_STRUCTS = 0

# Definitions
CC          = gcc
AR          = ar
DEBUG       =
DEFFLAGS    = -DSUPP_RTAI=$(SUPP_RTAI) -DTARGET_NATIVE=$(TARGET_NATIVE)
DEFFLAGS    += -DLTT_UNPACKED_STRUCTS=$(LTT_UNPACKED_STRUCTS)
INCLUDEDIRS = -I../Include
CFLAGS      = -O2 -Wall $(DEFFLAGS) $(DEBUG) -I../Include
ARFLAGS     = rs
LFLAGS      = -shared -Wl,-soname,libltt 
DEPFILE     = .depend

# Files (note that the INCLUDES variable isn't used anywhere, it's there for reference's sake)
INCLUDES = LTTTypes.h LinuxEvents.h Tables.h LinuxTables.h EventDBI.h EventDB.h EventOptions.h
OBJS = Tables.o LinuxTables.o EventDB.o EventOptions.o

ifeq ($(SUPP_RTAI),1)
INCLUDES += RTAIEvents.h RTAITables.h RTAIDB.h
OBJS     += RTAITables.o RTAIDB.o
endif

# Installation variables
LIB_NAME     = libltt.so
LIBA_NAME    = libltt.a
INSTALL_DIR  = /usr/lib
INSTALL      = install

# Rules
all: libltt

.depend:
	@echo "Building dependencies"
	rm -rf .depend
	touch .depend
	makedepend -f .depend $(DEFFLAGS) $(INCLUDEDIRS) *.c
	@echo "Dependencies built"

depend dep: .depend

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

libltt: ${OBJS}
	$(CC) $(LFLAGS) -o $(LIB_NAME) ${OBJS}
	$(AR) $(ARFLAGS) $(LIBA_NAME) ${OBJS}

install: libltt
	test -d $(INSTALL_DIR) || $(INSTALL) -d -m 755 $(INSTALL_DIR)
	$(INSTALL) -m 755 $(LIB_NAME) $(INSTALL_DIR)
	$(INSTALL) -m 644 $(LIBA_NAME) $(INSTALL_DIR)

clean: 
	rm -rf *.o $(LIB_NAME) core

distclean:
	rm -rf *~
	rm -rf .depend .depend.bak
	rm -rf *.o $(LIB_NAME) $(LIBA_NAME) core

-include .depend
