srcdir	= .
include $(srcdir)/../Makefile.common

ifdef ($(OS),OSF1)
	EXTRA_CLEAN += cxx_repository
endif

LIBNAME	= otf

HDRS	= GetOpt.h Reg.h Symbol.h null.h config.h
SRCS	= GetOpt.cpp Reg.cpp Symbol.cpp
OBJS	= $(SRCS:.cpp=.o)
LIBS	= -lm

DOCDIR	= $(OTFDOC)/lib/$(LIBNAME)
DOCS	= GetOpt.html Symbol.html

ifneq ($(srcdir),.)
INCS	+= -I.
ifndef WIN32
INCS	+= -I$(srcdir)
else
INCS	+= -I"$(shell cygpath -m "$(srcdir)")"
endif
endif

ifeq ($(OS),Darwin)
	SRCS    += osxDylibInit.cpp   
	LDFLAGS	+= -init _callStaticInitOTF
endif
ifdef UNIX
	DEFS	+= -DOTF_PATHSEP="'/'"
endif
ifdef WIN32
	DEFS	+= -DOTF_DLL_EXPORT -DOTF_PATHSEP="'\\\\'"
	HDRS	+= win32_dirent.h
	CSRCS	= win32_dirent.c
	OBJS	+= $(CSRCS:.c=.o)
endif

ifdef NEED_REGEX
DEFS	+= -DOTF_NEED_REGEX
OBJS	+= regex/*.o

regex/*.o regex/regex.h:
	cd $(srcdir)/regex; $(MAKE) OS=$(OS) TARGET_ARCH="$(TARGET_ARCH)" lib

Reg.o: regex/regex.h
endif

ifdef WIN32
all: $(SHLIB)
else
all: $(LIB)
endif

$(LIB): $(OBJS)
	$(LIB_LINK)

$(SHLIB): $(OBJS)
	$(SHLIB_LINK)

tester: tester.cpp $(LIB)
	$(CXX) $(CFLAGS) -o tester tester.cpp $(LIB)

tester2: tester2.cpp $(LIB)
	$(CXX) $(CFLAGS) -o tester2 tester2.cpp $(LIB)

clean:
	rm -rf $(OBJS) tester tester2 $(EXTRA_CLEAN)
ifdef NEED_REGEX
	cd $(srcdir)/regex; $(MAKE) clean
endif

distclean:
	rm -f $(LIB) $(SHLIB)

$(OBJS): config.h

install: all
ifdef WIN32
	cp -fp $(SHLIB) $(OTFBIN)
endif
