###########################################################################
#
# Makefile -- runtime-src/src/corba
# 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@
GSLDARCH = @gsdlarch@

INDEXERS_DIR = $(COMMON_DIR)/indexers
COMMON_PACKAGES_DIR = $(COMMON_DIR)/packages
RUNTIME_PACKAGES_DIR = $(RUNTIME_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
MG_INCLUDES = -I$(INDEXERS_DIR)/mg/lib
else
MG_INDEXERS_LIBS =
MG_INCLUDES =
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
else
GDBM_DEFINES = 
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_LIBS = $(COMMON_PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread
SQLITE_DEFINES = -DUSE_SQLITE
else
SQLITE_LIBS = 
SQLITE_DEFINES =
endif

MICO_DIR = @MICO_DIR@
MICO_VER = @MICO_VER@
ifeq ($(MICO_DIR), default)
MICO_INCLUDES = -I. -I$(RUNTIME_PACKAGES_DIR)/mico/mico/include
MICO_PATH = $(RUNTIME_PACKAGES_DIR)/mico/bin/
else
MICO_INCLUDES = -I. -I$(MICO_DIR)
MICO_PATH =
endif

USE_CORBA = @USE_CORBA@
ifeq ($(USE_CORBA), 1)
AR = ar
CC = @CC@
CFLAGS = -I. @CFLAGS@
CXXFLAGS = -I. @CXXFLAGS@
DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DGSDLSERVER $(GDBM_DEFINES) $(JDBM_DEFINES) $(SQLITE_DEFINES)
INCLUDES = -I$(COMMON_DIR)/src/lib -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) -I$(RECPT_DIR) $(MG_INCLUDES) $(MGPP_INCLUDES) \
	$(MICO_INCLUDES)
INSTALL = @INSTALL@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ $(COMMON_PACKAGES_DIR)/gdbm/lib/libgdbm.a -L$(COMMON_PACKAGES_DIR)/expat/lib -lexpat \
	$(ACCENTFOLD_LIBS) $(SQLITE_LIBS) -L$(RUNTIME_PACKAGES_DIR)/mico/lib -lmico$(MICO_VER)
RANLIB = @RANLIB@


COMPILE = $(MICO_PATH)mico-c++ -x c++ $(CFLAGS) $(DEFS) $(INCLUDES) -c
LINK = $(MICO_PATH)mico-ld $(LDFLAGS) -o $@


.SUFFIXES: .mpp .o
.mpp.o:
	$(COMPILE) $<


SOURCES = \
	corbaconv_text_t.mpp \
	corbaiface.mpp \
	corbaproto.mpp \
	corbatext_t.mpp
#	corbaiface_skel.mpp \

OBJECTS = \
	corbaconv_text_t.o \
	corbaiface.o \
	corbaproto.o \
	corbatext_t.o
#	corbaiface_skel.o \

CORBASERVER_OBJECTS = \
	corbaServer.o

CORBARECPT_OBJECTS = \
	corbaclient.o

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

CORBASERVER_EXECUTABLE_OBJECTS = \
	$(OBJECTS) \
	$(CORBASERVER_OBJECTS) \
	$(GSDL_LIBS)

CORBARECPT_EXECUTABLE_OBJECTS = \
	$(OBJECTS) \
	$(CORBARECPT_OBJECTS) \
	$(GSDL_LIBS)

EXECUTABLES = corbaserver corbarecptldd


# Default target: make both corbaserver and corbarecptldd
all: $(EXECUTABLES)

corbaserver: $(CORBASERVER_EXECUTABLE_OBJECTS)
	$(LINK) $(CORBASERVER_EXECUTABLE_OBJECTS) $(LIBS)

corbarecptldd: $(CORBARECPT_EXECUTABLE_OBJECTS)
	$(LINK) $(CORBARECPT_EXECUTABLE_OBJECTS) $(LIBS)

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

install:
# We're in a linux makefile, so we know what the GSDLOS is if this
# Makefile is run:
	cp corbaserver ../../../cgi-bin/linux/.
	if test -e corbarecptldd; then cp corbarecptldd ../../../cgi-bin/linux/.; fi

clean:
	rm -f $(OBJECTS) $(CORBASERVER_OBJECTS) $(CORBARECPT_OBJECTS) $(EXECUTABLES)

else
all:
depend:
install:
clean:
endif

corbaiface.h corbaiface.mpp: corbaiface.idl

# Because sequential commands are independent (each line seems to be run in its own shell),
# need to set the path env vars and run the IDL command in the same cmd, so it remembers
# the env vars when running the idl executable
# (NOTE: In the past, before BOA changed to POA in corba code, skeleton files were
# required. If needed again, generate them with the --c++-skel option to idl.)
	export PATH=$(RUNTIME_PACKAGES_DIR)/mico/bin:${PATH};export LD_LIBRARY_PATH=$(RUNTIME_PACKAGES_DIR)/mico/lib:${LD_LIBRARY_PATH};idl --c++-suffix mpp corbaiface.idl;

# Want to do distclean regardless of whether or not been compiled
# distclean needs to get rid of anything produced by ./configure such
# as this makefile!


distclean: clean
	rm -f Makefile

