##  -*- Mode: Makefile -*-
##
##

########################################################################
## pthread
##

THREADED=1

ifdef THREADED
  PTHREAD_LIBS = -L/usr/local/lib -lpthread
  PTHREAD_INCS = -I/usr/local/include
endif

########################################################################
## machine dependence
##

CXXLIB_machdep = 

LDOPT_SO_machdep = -shared
LDOPT_machdep = -rdynamic

########################################################################
## for configure
##

LOCAL_INCLUDES = -I. -I.. -I../.. -I../../config

CC = gcc
CFLAGS = -g -O2 -Wall
CXX = g++ 
DEFS = -DHAVE_CONFIG_H -DCPU_x86 -DLinux
CXXFLAGS = -g -O2 $(DEFS) $(CXXFLAGS_machdep) \
		$(LOCAL_INCLUDES) -Wall 
LDFLAGS = 
LIBS = 

LDOPT_SO	= $(LDOPT_SO_machdep)
LDOPT           = $(LDOPT_machdep)

RANLIB = ranlib

PERL = perl

ifdef THREADED
  CXXFLAGS := $(CXXFLAGS) -DTHREADED $(PTHREAD_INCS)
  LDOPT_SO := $(LDOPT_SO) $(PTHREAD_LIBS)
  LDOPT    := $(LDOPT) $(PTHREAD_LIBS)
endif

########################################################################
## suffix
##

.SUFFIXES: .cc $(SUFFIXES)

########################################################################
## Files
##

TESTPROG        = foo testSimpleSexp2

########################################################################
## General Rules
##

.cc.o:
	$(CXX) -c $(CXXFLAGS) $<

########################################################################
## Top Goals
##

all: test

test: $(TESTPROG)

##======================================================================
## clean up
##

clean:
	rm -f *~ *.o *.a $(TESTPROG)

config:
	(cd .. ; make config)

depend:
	$(CXX) -MM $(CXXFLAGS) *.cc > Makefile.depend

include Makefile.depend

########################################################################
## dependency
##

ITKLIBDIR = ..
ITKLIB = $(ITKLIBDIR)/libitk.a
ITKLIBSO = $(ITKLIBDIR)/libitk.so

itk : $(ITKLIB) 

$(ITKLIB) :
	(cd $(ITKLIBDIR) ; make)
	ln -s $(ITKLIBSO)

foo : $(ITKLIB)
foo : foo.o
	$(CXX) -o $@ $^ $(LIBS) -L.. -litk $(LDOPT)


testSimpleSexp2 : $(ITKLIB)
testSimpleSexp2 : testSimpleSexp2.o
	$(CXX) -o $@ $^ $(LIBS) -L.. -litk $(LDOPT)

FrameSexp : $(ITKLIB)
FrameSexp : FrameSexp.o
	$(CXX) -o $@ $^ $(LIBS) -L.. -litk $(LDOPT)

testSTL : $(ITKLIB)
testSTL : testSTL.o
	$(CXX) -o $@ $^ $(LIBS) -L.. -litk $(LDOPT)
