#
# Copyright (c) 1991, 1992, 1993, 1994 Xerox Corporation.  All Rights Reserved.
#
# Unlimited use, reproduction, and distribution of this software is
# permitted.  Any copy of this software must include both the above
# copyright notice of Xerox Corporation and this paragraph.  Any
# distribution of this software must comply with all applicable United
# States export control laws.  This software is made available AS IS,
# and XEROX CORPORATION DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
# INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE, AND NOTWITHSTANDING ANY OTHER
# PROVISION CONTAINED HEREIN, ANY LIABILITY FOR DAMAGES RESULTING FROM
# THE SOFTWARE OR ITS USE IS EXPRESSLY DISCLAIMED, WHETHER ARISING IN
# CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, EVEN IF
# XEROX CORPORATION IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# $Id: Imakefile,v 1.35 1996/02/28 03:18:56 janssen Exp $
#

pythonversion.h: ../../imake/ilu.defs.new
	$(RM) pythonversion.h
	echo "#define ILUPYTHON_MAJOR_VERSION " PYTHON_MAJOR_VERSION >pythonversion.h
	echo "#define ILUPYTHON_MINOR_VERSION " PYTHON_MINOR_VERSION >>pythonversion.h

CleanTarget(pythonversion.h)

LOCALINCLUDES	= -I$(PYTHON_PREFIX)/include/Py -I../kernel
ILUCINCLUDES =
KERNELHEADERS = ../kernel/iluxport.h ../kernel/iluerror.h ../kernel/iluerrs.h ../kernel/iluconf.h ../kernel/ilubasic.h

NormalObjectRule()

python.h	: pythonversion.h
iluPrmodule.o	: python.h ilualobject.h ilucaobject.h iluclobject.h \
		  iluftobject.h ilulrobject.h ilusvobject.h iohcobject.h \
		  ivobject.h thcobject.h $(KERNELHEADERS)
ilualobject.o	: python.h ilualobject.h iluftobject.h $(KERNELHEADERS)
ilucaobject.o	: python.h ilucaobject.h $(KERNELHEADERS)
iluclobject.o	: python.h iluclobject.h $(KERNELHEADERS)
iluftobject.o	: python.h iluftobject.h $(KERNELHEADERS)
ilulrobject.o	: python.h ilulrobject.h $(KERNELHEADERS)
ilusvobject.o	: python.h ilusvobject.h $(KERNELHEADERS)
ilulpobject.o	: python.h ilulpobject.h $(KERNELHEADERS)
iohcobject.o	: python.h iohcobject.h $(KERNELHEADERS)
ivobject.o	: python.h ivobject.h $(KERNELHEADERS)
thcobject.o	: python.h thcobject.h iluftobject.h $(KERNELHEADERS)

OBJS		= \
		ilualobject.o \
		ilucaobject.o \
		iluclobject.o \
		iluftobject.o \
		ilulrobject.o \
		ilusvobject.o \
		ilulpobject.o \
		iohcobject.o \
		ivobject.o \
		thcobject.o \
		iluPrmodule.o

ILU_LIB		= ../kernel/libilu.a

#ifdef USING_ILUGSS
SECURITYLIBS = ../../GSS/kernel/libgss.a $(RSALIBS) $(DESLIBS)
#endif

#if ((PYTHON_MAJOR_VERSION == 1) && (PYTHON_MINOR_VERSION > 2))

ADDOBJS = $(PYTHON_EXEC_PREFIX)/lib/python/lib/main.o getpath.o

getpath.o : $(PYTHON_EXEC_PREFIX)/lib/python/lib/getpath.c
	$(ANSI_C_COMPILER) -DPYTHONPATH=\".:/usr/lib/python:/usr/lib/python/test:/usr/lib/python:/usr/lib/python/tkinter\" $(CFLAGS) -c -o ./getpath.o $(PYTHON_PREFIX)/lib/python/lib/getpath.c
#else

ADDOBJS =
getpath.c : getpath.c.dist
	$(RM) getpath.c
	cp getpath.c.dist getpath.c

getpath.o : getpath.c

CleanTarget(getpath.c)

#endif /* Python version > 1.2 */

#ifdef PYTHON_USES_SHARED_LIBRARIES_FOR_EXTENSIONS

ObjectTarget(iluPrmodule.o)
ObjectTarget(ilualobject.o)
ObjectTarget(ilucaobject.o)
ObjectTarget(iluclobject.o)
ObjectTarget(iluftobject.o)
ObjectTarget(ilulrobject.o)
ObjectTarget(ilusvobject.o)
ObjectTarget(iohcobject.o)
ObjectTarget(ivobject.o)
ObjectTarget(thcobject.o)

PythonExtension(iluPrmodule, $(OBJS), $(ILU_LIB), $(SECURITYLIBS))

#else /* build new Python executable with ILU linked in */

Makefiles:: Makefile.build Setup

all:: ilupython

#ifdef ADD_SECURE_TRANSPORT
Setup.in:
	echo iluPr $(OBJS) -I../kernel -L../kernel -lilu $(SECURITYLIBS) >Setup.in
#else /* no SECURE_TRANSPORT */
Setup.in:
	echo iluPr $(OBJS) -I../kernel -L../kernel -lilu >Setup.in
#endif /* ADD_SECURE_TRANSPORT */

Makefile.pre.in : Makefile.pre.in.1.2
	-rm -f Makefile.pre.in
	cp Makefile.pre.in.1.2 Makefile.pre.in

config.c Setup Makefile.build: Setup.in Makefile.pre.in
	-rm -f Setup
	make -f Makefile.pre.in Makefile.build installdir=$(PYTHON_EXEC_PREFIX)

ilupython: config.c Makefile.build Setup $(OBJS) $(ADDOBJS) ../kernel/libilu.a
	make -f Makefile.build ilupython CC="$(ANSI_C_COMPILER)" ADDOBJS="$(ADDOBJS)"
	
CleanTarget(python ilupython Makefile.build Setup.in Setup Makefile.pre sedscript)

InstallProgram(ilupython, $(DESTDIR)/bin)

#endif /* PYTHON_USES_SHARED_LIBRARIES_FOR_EXTENSIONS */

#ifdef PYTHON_LIBRARIES_INSTALLED
/*
	Build and install libilupython.a, so that users can
	build standalone programs with ILU and Python linked in.
*/

libconfig.c : $(PYTHON_PREFIX)/lib/python/lib/config.c
	$(SED) -f makelibconfig.sed <$(PYTHON_EXEC_PREFIX)/lib/python/lib/config.c >libconfig.c

libconfig.o : libconfig.c
	$(ANSI_C_COMPILER) $(CFLAGS) -I$(PYTHON_PREFIX)/include/Py -DNO_MAIN -o libconfig.o -c libconfig.c

LibraryTarget(libilupython.a, $(OBJS) libconfig.o)
InstallLibrary(libilupython.a, $(DESTDIR)/lib)

LibraryTarget(libilupythonaux.a, getpath.o getprogramname.o)
InstallLibrary(libilupythonaux.a, $(DESTDIR)/lib)

#endif /* PYTHON_LIBRARIES_INSTALLED */

CleanTarget(libconfig.c libconfig.o)

InstallRO(iluRt.py ilu.py ilu_tk.py SunRPCUNIXAuthUsername.py, $(DESTDIR)/lib)
