# Makefile for producing SWIG runtime libraries. 
#
# The SWIG runtime library consists of the pointer-type checker
# and other support functions.  Multi-file SWIG modules 
# generally link with these libraries.
#
# By default, the installation processs will attempt to 
# build shared libraries.  If that doesn't work, a static
# library is built instead.

prefix      = @prefix@
exec_prefix = @exec_prefix@
CC          = @CC@
AR          = @AR@
RANLIB      = @RANLIB@
SO          = @SO@
CCSHARED    = @CCSHARED@
LDSHARED    = @LDSHARED@
DYN_LIBS    = libswigtcl8$(SO) libswigtcl$(SO) libswigpl$(SO) libswigpy$(SO)
STATIC_LIBS = libswigtcl8.a libswigtcl.a libswigpl.a libswigpy.a
LIBS        = $(STATIC_LIBS) $(DYN_LIBS)
LIB_DIR     = $(exec_prefix)/lib

INSTALL_DATA = ../install-sh -c -m 644
INSTALL_SHLB = ../install-sh -c -m 555

all:
	@sh make.sh


install:
	@echo "Installing runtime libraries"
	@for i in $(STATIC_LIBS); \
	do \
	if [ -f $$i ]; then \
	   echo "Installing $$i in $(LIB_DIR)/$$i"; \
	   $(INSTALL_DATA) $$i $(LIB_DIR)/$$i; \
        fi; \
	done;
	@for i in $(DYN_LIBS); \
	do \
	if [ -f $$i ]; then \
	   echo "Installing $$i in $(LIB_DIR)/$$i"; \
	   $(INSTALL_SHLB) $$i $(LIB_DIR)/$$i; \
        fi; \
	done;


clean::
	rm -rf *.o *.a *$(SO) *.c *.swg *~ core

# ----------------------------------------------------------------------
# Tcl runtime library
# ----------------------------------------------------------------------

TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB     = @TCLLIB@

# Tcl 7.x shared

tcl_shared:
	../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
	$(CC) $(CCSHARED) -c -DSWIG_GLOBAL libtcl.c
	$(LDSHARED) libtcl.o -o libswigtcl$(SO)

# Tcl 7.x library

tcl_lib:
	../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
	$(CC) -c -DSWIG_GLOBAL libtcl.c
	$(AR) cr libswigtcl.a libtcl.o

# Tcl 8.x shared

tcl8_shared:
	../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
	$(CC) $(CCSHARED) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
	$(LDSHARED) libtcl8.o -o libswigtcl8$(SO)

tcl8_lib:
	../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
	$(CC) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
	$(AR) cr libswigtcl8.a libtcl8.o

# ----------------------------------------------------------------------
# Python run-time library
# ----------------------------------------------------------------------

PYTHON_INCLUDE= -DHAVE_CONFIG_H @PYINCLUDE@
PYTHON_LIB    = @PYLIB@

# Python shared

py_shared:
	../swig -python -co -o libpy.c -I../swig_lib python.swg
	$(CC) $(CCSHARED) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c 
	$(LDSHARED) libpy.o -o libswigpy$(SO)

# Python library

py_lib:
	../swig -python -co -o libpy.c -I../swig_lib python.swg
	$(CC) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
	$(AR) cr libswigpy.a libpy.o 

# ----------------------------------------------------------------------
# Perl run-time library
# ----------------------------------------------------------------------

PERL5_INCLUDE= -I@PERL5EXT@

# Perl shared

perl_shared:
	rm -f libperl.c libperl.swg
	../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
	cat perlrun.h >> libperl.c
	cat libperl.swg >> libperl.c
	$(CC) $(CCSHARED) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
	$(LDSHARED) libperl.o -o libswigpl$(SO)

# Perl library

perl_lib:
	rm -f libperl.c libperl.swg
	../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
	cat perlrun.h >> libperl.c
	cat libperl.swg >> libperl.c
	$(CC) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
	$(AR) cr libswigpl.a libperl.o 
