#
# Makefile for the Hafta Checkpoint library (checkpoint)
#

DEBUG=-g

# Directories
DESTDIR=.
LIBDIR=.
BINDIR:=/usr/local/bin

# Platform specific
ifeq '$(shell uname)' 'Linux'
CC:=gcc
LINTFILE:=co-linux.lnt
else ## qnx6
CC:=qcc -Vgcc_ntox86
LINTFILE:=co.lnt
endif

TARGET=checkpoint
INCLUDE:=-I../include -I../../acfl/include -I.
LINT:=$(BINDIR)/flint -b -v $(INCLUDE) $(LIBDIR)/$(LINTFILE)

CFLAGS:=-shared $(INCLUDE) $(DEBUG)

HFILES:=../include/checkpoint.h checkpoint_int.h

SRCS:=HC_Checkpoint.c HC_Default.c HC_Log.c HC_Nodelist.c \
      HC_Normal.c HC_Rollback.c HC_Sequence.c HC_Stack.c

OBJS:=$(addsuffix .o,   $(basename $(SRCS)))
LOBS:=$(addsuffix .lob, $(basename $(SRCS)))

TLIB:=$(DESTDIR)/lib$(TARGET).a
TSLIB:=$(DESTDIR)/lib$(TARGET).so
TLINT:=$(DESTDIR)/$(TARGET).lob


# library targets
all: $(TLIB) $(TSLIB)

$(OBJS): $(HFILES)

$(TLIB): $(OBJS)
	$(AR) rc $@ $^ 

$(TSLIB): $(OBJS)
	$(CC) -shared -o $@ $^


# lint targets
lint: $(TLINT)

$(TLINT): $(LOBS)
	$(LINT) -e126 $^

%.lob: %.c
	$(LINT) -u $*.c -oo


# misc targets

doxygen: Doxyfile $(SRCS)
	doxygen $<

docs: doxygen
	$(MAKE) -C docs/latex pdf

install-docs: docs
	cp docs/latex/refman.pdf ../../docs/pdf/checkpoint_api.pdf
	cp -R docs/html ../../docs/html/hafta_en/checkpoint_api/
	cp -R docs/checkpoint_api.toc ../../docs/html/hafta_en/
	cp -R docs/html/book.toc ../../docs/html/hafta_en/checkpoint_api/

clean:
	rm -f *.o *.a *.so *.lob
