###########################################################################
#
# Makefile -- runtime-src/src/oaiservr
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the
# University of Waikato, New Zealand.
#
# Copyright (C) 1999-2008  The New Zealand Digital Library Project
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################

GSDL_DIR = ../../..
COMMON_DIR = $(GSDL_DIR)/common-src
RUNTIME_DIR = $(GSDL_DIR)/runtime-src

GSDLOS = @gsdlos@
GSDLARCH = @gsdlarch@

INDEXERS_DIR = $(COMMON_DIR)/indexers
COMMON_PACKAGES_DIR = $(COMMON_DIR)/packages
COLSERVR_DIR = $(RUNTIME_DIR)/src/colservr
PROTOCOL_DIR = $(RUNTIME_DIR)/src/protocol
RECPT_DIR = $(RUNTIME_DIR)/src/recpt


ENABLE_ACCENTFOLD = @ENABLE_ACCENTFOLD@
ifeq ($(ENABLE_ACCENTFOLD), 1)
ifeq ($(GSDLOS),darwin)
ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a -liconv
else
ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a $(COMMON_PACKAGES_DIR)/iconv/lib/libiconv.a
endif
else
ACCENTFOLD_LIBS = 
endif


ENABLE_MG = @ENABLE_MG@
ifeq ($(ENABLE_MG), 1)
MG_INDEXERS_LIBS = $(INDEXERS_DIR)/mg/src/text/libmgtext.a \
	$(INDEXERS_DIR)/mg/lib/libmglib.a
else
MG_INDEXERS_LIBS =
endif

ENABLE_MGPP = @ENABLE_MGPP@
ifeq ($(ENABLE_MGPP), 1)
MGPP_INDEXERS_LIBS = $(INDEXERS_DIR)/mgpp/text/libmgpptext.a \
	$(INDEXERS_DIR)/mgpp/lib/libmgpplib.a
MGPP_INCLUDES = -I$(INDEXERS_DIR)/mgpp/text   -I$(INDEXERS_DIR)/mgpp/lib
else
MGPP_INDEXERS_LIBS =
MGPP_INCLUDES =
endif

USE_GDBM = @USE_GDBM@
ifeq ($(USE_GDBM), 1)
GDBM_DEFINES = -DUSE_GDBM
GDBM_LIBS = $(COMMON_PACKAGES_DIR)/gdbm/lib/libgdbm.a
else
GDBM_DEFINES = 
GDBM_LIBS =
endif

USE_JDBM = @USE_JDBM@
ifeq ($(USE_JDBM), 1)
JDBM_DEFINES = -DUSE_JDBM
else
JDBM_DEFINES = 
endif

USE_SQLITE = @USE_SQLITE@
ifeq ($(USE_SQLITE), 1)
SQLITE_DEFINES = -DUSE_SQLITE
SQLITE_LIBS = $(COMMON_PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread
else
SQLITE_LIBS = 
SQLITE_DEFINES =
endif

# Extension support
EXT_DEFINES =
EXT_INCLUDES =
EXT_LDFLAGS =
EXT_LIBS =

CC = @CC@
CFLAGS = @CFLAGS@ @ARCH_DEP_FLAGS@
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @ARCH_DEP_FLAGS@
DEFS = @DEFS@ $(GDBM_DEFINES) $(JDBM_DEFINES) $(SQLITE_DEFINES) $(EXT_DEFINES)
INCLUDES = -I$(COMMON_DIR)/src/lib -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) -I$(RECPT_DIR) $(MGPP_INCLUDES) $(EXT_INCLUDES)
LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@ $(EXT_LDFLAGS)
LIBS = @LIBS@ $(GDBM_LIBS) -L$(COMMON_PACKAGES_DIR)/expat/lib -lexpat \
	$(ACCENTFOLD_LIBS) $(SQLITE_LIBS) $(EXT_LIBS)
INSTALL = @INSTALL@


CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
CXXLINK = $(CXX) $(LDFLAGS) -o $@


.SUFFIXES:
.SUFFIXES: .cpp .o
.cpp.o:
	$(CXXCOMPILE) -o $@ $< 


RECPT_OBJECTS = \
	$(RECPT_DIR)/cgiargs.o \
	$(RECPT_DIR)/cgiutils.o \
	$(RECPT_DIR)/htmlutils.o

SOURCES = \
	abstractlistaction.cpp \
	dublincore.cpp \
	qualified_dublincore.cpp \
	identifyaction.cpp \
	listidsaction.cpp \
	listrecsaction.cpp \
	listsetsaction.cpp \
	metaformat.cpp \
	metaformatsaction.cpp \
	oaiaction.cpp \
	oaiargs.cpp \
	oaiconfig.cpp \
	oaidispatcher.cpp \
	oaimain.cpp \
	oaitools.cpp \
	recordaction.cpp \
	resumptiontoken.cpp \
	rfc1807.cpp

OBJECTS = \
	abstractlistaction.o \
	dublincore.o \
	qualified_dublincore.o \
	identifyaction.o \
	listidsaction.o \
	listrecsaction.o \
	listsetsaction.o \
	metaformat.o \
	metaformatsaction.o \
	oaiaction.o \
	oaiargs.o \
	oaiconfig.o \
	oaidispatcher.o \
	oaimain.o \
	oaitools.o \
	recordaction.o \
	resumptiontoken.o \
	rfc1807.o

GSDL_LIBS = \
	$(PROTOCOL_DIR)/gsdlprotocol.a \
	$(COLSERVR_DIR)/gsdlcolservr.a \
	$(MG_INDEXERS_LIBS) \
	$(MGPP_INDEXERS_LIBS) \
	$(COMMON_DIR)/src/lib/gsdllib.a

EXECUTABLE_OBJECTS = \
	$(OBJECTS) \
	$(RECPT_OBJECTS) \
	$(GSDL_LIBS)

EXECUTABLE = oaiserver.cgi


# Default target: make the oaiserver executable
all: $(EXECUTABLE)

$(EXECUTABLE): $(EXECUTABLE_OBJECTS)
	$(CXXLINK) $(EXECUTABLE_OBJECTS) $(LIBS)

install: $(EXECUTABLE)
	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/cgi-bin/$(GSDLOS)$(GSDLARCH)

clean:
	rm -f $(OBJECTS) $(EXECUTABLE)

distclean:
	rm -f $(OBJECTS) $(EXECUTABLE) Makefile

depend:
	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
