##############################################################################
#									     #
# This is a Makefile for making the XSB emu directory.			     #
# It has two main entries: xsb and xsbora. The latter for generating	     #
# executables with oracle support.					     #
# The EXECUTABLE variable is set by the top make file, build/Makefile	     #
#									     #
##############################################################################

## File:      emuMakefile.in
## Author(s): kifer (adapted from the original XSB makefile)
## Copyright (C) The Research Foundation of SUNY, 1998
## 
## XSB is free software; you can redistribute it and/or modify it under the
## terms of the GNU Library General Public License as published by the Free
## Software Foundation; either version 2 of the License, or (at your option)
## any later version.
## 
## XSB 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 Library General Public License for
## more details.
## 
## You should have received a copy of the GNU Library General Public License
## along with XSB; if not, write to the Free Software Foundation,
## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## $Id: emuMakefile.in,v 1.53 2005/01/14 18:30:41 ruim Exp $
## 


CC=@CC@
CPP=@CPP@
CFLAGS=@CFLAGS@
# Compilation flags for files requiring lower optimization level
# (builtin.c,emuloop.c,tr_utils.c)
loaderCFLAGS=@loaderCFLAGS@
builtinsCFLAGS=@builtinsCFLAGS@
emuloopCFLAGS=@emuloopCFLAGS@
trutilsCFLAGS=@trutilsCFLAGS@
CPPFLAGS=@CPPFLAGS@
LDFLAGS=@LDFLAGS@
ODBCSRC=@ODBCSRC@
ODBCOBJ=@ODBCOBJ@
INTERPROLOGSRC=@INTERPROLOGSRC@
INTERPROLOGOBJ=@INTERPROLOGOBJ@
DLLTYPE=@DLLTYPE@
JAVA_HEADER_PATH=@JAVA_HEADER_PATH@
JAVA_PLATFORM_HEADER_PATH=@JAVA_PLATFORM_HEADER_PATH@

# For mno-cygwin 
# -mdll option is needed so that MSVC files could link to dll
# however for old cygwin versions -dll option is used  
DLLNAME=xsb.dll
DLL_LIBS=$(LDFLAGS) 
LIB_OBJECTS=xsb.o dllinit_xsb.o
BASE_FILE=xsb.base
DEF_FILE=$(arch_config_prefix)/saved.o/xsb.def
LIB_FILE=libxsb.a
ENTRY_FUNCTION=_win_xsbent@12




# This one is used for SGI only
LINKFLAGS=@LINKFLAGS@

# Substitute an assignment for the MAKE variable, because
# BSD doesn't have it as a default.
@SET_MAKE@


# just to be sure the sh is used 
SHELL=/bin/sh


# The default location for installation. 
prefix=@prefix@
# where sources are
srcdir=@topdir@
VPATH=@topdir@
# Like `prefix', but used for architecture-specific files.
arch_config_prefix=@arch_config_prefix@

# Where to install XSB binaries
bindir=$(arch_config_prefix)/bin
# where XSB emu directory lives
emudir=$(srcdir)/emu
# where the object code goes
arch_config_objlibdir=$(arch_config_prefix)/saved.o

# Passed in from the top Makefile
EXECUTABLE=xsb

#=======================================================================
# Stuff to automatically make the dependencies.
#=======================================================================
#
DEPEND = makedepend
#DEPENDFLAGS = -m
#


SRCS =	auxlry.c biassert.c builtin.c cinterf.c \
	debug_xsb.c dis.c dynload.c dynamic_stack.c \
	emuloop.c error_xsb.c findall.c function.c \
	hash_xsb.c hashtable_xsb.c \
	heap_xsb.c init_xsb.c inst_xsb.c io_builtins_xsb.c \
	loader_xsb.c main_xsb.c memory_xsb.c orient_xsb.c \
	pathname_xsb.c psc_xsb.c random_xsb.c \
        remove_unf.c residual.c rw_lock.c \
	scc_xsb.c slgdelay.c socket_xsb.c string_xsb.c \
	storage_xsb.c struct_manager.c sub_delete.c subp.c \
	system_xsb.c table_stats.c tables.c \
	thread_xsb.c timer_xsb.c token_xsb.c \
	tr_utils.c trace_xsb.c trie_lookup.c trie_search.c tries.c \
	tst_insert.c tst_retrv.c tst_unify.c tst_utils.c varstring.c \
	ubi_BinTree.c ubi_SplayTree.c


ORASRCS = $(SRCS) orastuff.c


OBJS =	auxlry.o biassert.o builtin.o cinterf.o \
	debug_xsb.o dis.o dynload.o dynamic_stack.o \
	emuloop.o error_xsb.o findall.o function.o \
	hash_xsb.o  hashtable_xsb.o \
	heap_xsb.o init_xsb.o inst_xsb.o io_builtins_xsb.o \
	loader_xsb.o memory_xsb.o orient_xsb.o \
	pathname_xsb.o private_builtin.o psc_xsb.o random_xsb.o \
        remove_unf.o residual.o rw_lock.o \
	scc_xsb.o slgdelay.o socket_xsb.o string_xsb.o \
	storage_xsb.o struct_manager.o sub_delete.o subp.o \
	system_xsb.o table_stats.o tables.o \
	thread_xsb.o timer_xsb.o token_xsb.o \
	tr_utils.o trace_xsb.o trie_lookup.o trie_search.o tries.o \
	tst_insert.o tst_retrv.o tst_unify.o tst_utils.o varstring.o \
	ubi_BinTree.o ubi_SplayTree.o


allOBJS = main_xsb.o ${OBJS} ${ODBCOBJ} ${INTERPROLOGOBJ}

ORAOBJS = $(OBJS) orastuff.o

allORAOBJS = $(allOBJS) orastuff.o

xsb:: $(allOBJS)
	@echo ""; echo "Making XSB executable $(EXECUTABLE) "; echo ""
	cd $(emudir); \
	$(CC) -o $(EXECUTABLE) $(allOBJS) $(LDFLAGS) 

xsbora:: $(allORAOBJS)
	@echo ""; \
	  echo "Making XSB executable $(EXECUTABLE) with support for Oracle"; \
	  echo ""
	cd $(emudir); \
	$(CC) -o $(EXECUTABLE) $(allORAOBJS) $(LDFLAGS)

# Goal for making an XSB load module to be linked with external
# C-drivers that pass queries to XSB
xsbmod:: $(OBJS) ${ODBCOBJ} ${INTERPROLOGOBJ}
	@echo ""; \
	   echo "Making a C-callable XSB module $(arch_config_objlibdir)/xsb.o"; \
	   echo ""
	@LD@ -o xsb.o $(LINKFLAGS) -r $(OBJS) ${ODBCOBJ} ${INTERPROLOGOBJ}
	@cp xsb.o $(arch_config_objlibdir) 2> /dev/null || echo ""

xsbdynmod::
	echo "Making XSB Shared Library $(bindir)/libxsb.so"
	@LD@ -o libxsb.so -shared $(LINKFLAGS)  $(OBJS) ${ODBCOBJ} ${INTERPROLOGOBJ}
	@cp libxsb.so $(bindir) 2>/dev/null || echo ""

# same as xsbmod, but with oracle support
xsboramod:: $(ORAOBJS)
	@echo ""; \
	   echo "Making a C-callable XSB module $(arch_config_objlibdir)/xsb.o with support for Oracle"; \
	   echo ""
	@LD@ -o xsb.o $(LINKFLAGS) -r $(ORAOBJS)
	@cp xsb.o $(arch_config_objlibdir) 2> /dev/null || echo ""


depend::
	$(DEPEND) $(DEPENDFLAGS) -- -I$(arch_config_prefix)  -I$(JAVA_PLATFORM_HEADER_PATH) -I$(JAVA_HEADER_PATH) $(CFLAGS) -- $(SRCS) $(ODBCSRC) ${INTERPROLOGSRC}

#
# create a new DLL library in cygwin (compiled with -mno-cygwin) environment
#
# LIB_OBJECTS: xsb.o, initdll_xsb.o files
# DLLNAME: name of the new dll
# DEFFILE is the name of the definitions file.
# BASEFILE temporary
# EXPFILE  temporary
# ENTRY is the entry point  int WINAPI startup (HINSTANCE, DWORD, LPVOID)

dll: $(DLLTYPE)

nodll:

cygdll: $(allOBJS) $(HEADERS) xsbmod
	chmod ugo+x $(arch_config_prefix)/makedef.sh
	$(CC) -I$(arch_config_prefix) -c $(CFLAGS) dllinit_xsb.cc
	@cp dllinit_xsb.o $(arch_config_objlibdir) 2> /dev/null || echo ""
	$(arch_config_prefix)/makedef.sh $(allOBJS) dllinit_xsb.o
	@mv out.def $(DEF_FILE)
	$(CC) -mno-cygwin -shared -o $(DLLNAME) $(LIB_OBJECTS) $(DEF_FILE) -Wl,--out-implib=xsb.a $(DLL_LIBS) -e $(ENTRY_FUNCTION)
	@mv $(DLLNAME) $(bindir) 2> /dev/null || echo ""
	@mv $(LIB_FILE) $(bindir) 2> /dev/null || echo ""
	@rm -f $(BASE_FILE) 2> /dev/null || echo ""
	$(CC) -o $(arch_config_prefix)/bin/xsb.exe  $(CFLAGS) \
		-I$(arch_config_prefix) -L$(arch_config_prefix)/bin \
		main_xsb.c $(LINKFLAGS) $(DLL_LIBS) -lxsb


#=======================================================================
# Put in this group all actions (rules) of this Makefile.
#=======================================================================

interprolog_callback.o: interprolog_callback.c
	$(CC) -c -I$(arch_config_prefix) -I$(JAVA_PLATFORM_HEADER_PATH) -I$(JAVA_HEADER_PATH) $(CFLAGS) interprolog_callback.c
	@cp interprolog_callback.o $(arch_config_objlibdir) 2> /dev/null || echo ""

init_xsb.o: init_xsb.c
	$(CC) -I$(arch_config_prefix)  -c $(CFLAGS) init_xsb.c
	@cp init_xsb.o $(arch_config_objlibdir) 2> /dev/null || echo ""

dynload.o: dynload.c
	$(CC) -I$(arch_config_prefix)  -c $(CFLAGS) dynload.c
	@cp dynload.o $(arch_config_objlibdir) 2> /dev/null || echo ""

emuloop.o: emuloop.c
	$(CC) -I$(arch_config_prefix)  -c $(emuloopCFLAGS) emuloop.c
	@cp emuloop.o $(arch_config_objlibdir) 2> /dev/null || echo ""

# Higher optimization level has problem with some versions of gcc
tr_utils.o: tr_utils.c
	$(CC) -I$(arch_config_prefix)  -c $(trutilsCFLAGS) tr_utils.c
	@cp tr_utils.o $(arch_config_objlibdir) 2> /dev/null || echo ""

builtin.o: builtin.c
	$(CC) -I$(arch_config_prefix)  -c $(builtinsCFLAGS) builtin.c
	@cp builtin.o $(arch_config_objlibdir) 2> /dev/null || echo ""

loader_xsb.o: loader_xsb.c
	$(CC) -I$(arch_config_prefix)  -c $(loaderCFLAGS) loader_xsb.c
	@cp loader_xsb.o $(arch_config_objlibdir) 2> /dev/null || echo ""

.c.o:
	$(CC) -I$(arch_config_prefix)  -c $(CFLAGS) $*.c
	@cp $*.o $(arch_config_objlibdir) 2> /dev/null || echo ""


#=======================================================================
# All dependencies are automatically generated by makedepend.
#=======================================================================

# DO NOT DELETE THIS LINE -- `makedepend' depends on it!

