JDK1.1.3 + SICStus Prolog 3 #6 on Linux 用 jspmkrs

spmkrs は、SICStus Prolog を利用する実行ファイルを作成するツールです。 これを改良して、Java の Native Method から利用できるように Shared Object を 出力するようにしたのが、下の jspmkrs です。 と言っても gcc のオプションを変えただけです。

#! /bin/sh
#########################################################################
#                                                       
# File: spmkrs                                           
#                                                       
# This file has been automatically generated by sicstus3/misc/Makefile
# DO NOT EDIT THIS FILE!                                
#                                                       
# Generated on: Fri Feb 13 15:34:26 JST 1998                                  
#                                                       
#########################################################################

# Usage: spmkrs  \
#		[+c ] \
#		[+o ] \
#		[+l ] \
#		[+r ]

outfile=$1
cfiles=
libraries=
rnames=
rfiles=
rlibs=

shift

# Collect file names

while [ "$1" ] ; do
    if [ "$1" = "+c" ] ; then
        pref=c
    elif [ "$1" = "+o" ] ; then
        pref=o
    elif [ "$1" = "+l" ] ; then
        pref=l
    elif [ "$1" = "+r" ] ; then
        pref=r
    elif [ $pref = c ] ; then
        cfiles="$cfiles $1"
    elif [ $pref = o ] ; then
        ofiles="$ofiles $1"
    elif [ $pref = l ] ; then
        libraries="$libraries $1"
    elif [ $pref = r ] ; then
        case $1 in
# Suffixed resource
            *.s.o | *.so)
                rfile=$1
                ;;
# Unsuffixed resource, prefer *.s.o (i.e. static) if both exist
            *)
                if [ -r $1.s.o ] ; then
                    rfile=$1.s.o
                else
                    rfile=$1.so
                fi
                ;;
        esac
        case $rfile in            
            *.s.o)
                rname=`basename $rfile .s.o`
                rlibs="$rlibs `/usr/local/lib/sicstus/bin/spxtrlib $rfile`"
                ;;
            *.so)
                rname=`basename $rfile .so`
                ;;
        esac
        if [ $rnames ] ; then
            rnames="$rnames,$rname"
        else
            rnames=$rname
        fi
        rfiles="$rfiles $rfile"
    fi
    shift
done

rtable=`/usr/local/lib/sicstus/bin/sptmp`.c
prtable=\'$rtable\'
echo "prolog:prepare_resource_table([$rnames],$prtable). " | /usr/local/bin/sicstus -f

# Here C-files, object files and libraries are compiled and liked with
# the runtime kernel to an executable

gcc -shared -O2 -fomit-frame-pointer \
    -malign-loops=2 -malign-jumps=2 -malign-functions=2 \
    /usr/local/lib/sicstus/bin/runtime.o $rtable $cfiles \
    -I/usr/local/include \
    -I/usr/local/jdk1.1.3/include \
    -I/usr/local/jdk1.1.3/include/genunix \
    $ofiles $rfiles $rlibs $libraries -rdynamic -ldl -lm -o ${outfile}

/bin/rm -f $rtable

Bold が主な変更個所です。

% jspmkrs libjpl.so +c jpl.c +r /usr/local/lib/sicstus/library/random.so
として、使います。