summaryrefslogtreecommitdiff
path: root/ext/rpc/java/config.m4
blob: bb258e8ebb5dae4cf154c99b8712649c7dfbb897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
dnl
dnl $Id$
dnl

PHP_ARG_WITH(java, for JAVA support,
[  --with-java[=DIR]       Include Java support. DIR is the JDK base install directory. 
                          This extension is always built as shared.])

if test "$PHP_JAVA" != "no"; then

  pltform=`uname -s 2>/dev/null`
  java_libext=libjava.so
  case $pltform in
    AIX) java_libext=libjava.a ;;
    HP-UX) java_libext=libjava.sl ;;
  esac  

  if test "$withval" = "yes"; then
    if JAVA_JAR=`which jar 2>/dev/null`; then
      JAVA_JAR="$JAVA_JAR cf"
    else
      JAVA_JAR=
    fi
    withval=`cd \`dirname \\\`which javac\\\`\`/..;pwd`
  else
    test -x $withval/bin/jar && JAVA_JAR="$withval/bin/jar cf"
  fi
    
  # substitute zip for systems which don't have jar
  if test -z "$JAVA_JAR"; then
    JAVA_JAR='zip -q0'
  fi

  if test -x $withval/bin/javac; then
    JAVA_C=$withval/bin/javac
  else
    AC_MSG_ERROR([Can not find the javac binary under $withval/bin/])
  fi

  if test -d $PHP_JAVA/lib/kaffe; then
    PHP_ADD_LIBPATH($PHP_JAVA/lib)
    JAVA_CFLAGS=-DKAFFE
    JAVA_INCLUDE=-I$PHP_JAVA/include/kaffe
    JAVA_CLASSPATH=$PHP_JAVA/share/kaffe/Klasses.jar
    JAVA_LIB=kaffevm
    JAVA_LIBPATH=$PHP_JAVA/lib/kaffe
    java_libext=kaffevm

    test -f $PHP_JAVA/lib/$JAVA_LIB       && JAVA_LIBPATH=$PHP_JAVA/lib
    test -f $PHP_JAVA/lib/kaffe/$JAVA_LIB && JAVA_LIBPATH=$PHP_JAVA/lib/kaffe

    # accomodate old versions of kaffe which don't support jar
    if kaffe -version 2>&1 | grep 1.0b > /dev/null; then
      JAVA_JAR='zip -q0'
    fi

  elif test -f $PHP_JAVA/lib/$java_libext; then
    JAVA_LIB=java
    JAVA_LIBPATH=$PHP_JAVA/lib
    JAVA_INCLUDE=-I$PHP_JAVA/include
    test -f $PHP_JAVA/lib/classes.zip && JAVA_CFLAGS=-DJNI_11
    test -f $PHP_JAVA/lib/jvm.jar     && JAVA_CFLAGS=-DJNI_12
    test -f $PHP_JAVA/lib/classes.zip && JAVA_CLASSPATH=$PHP_JAVA/lib/classes.zip
    test -f $PHP_JAVA/lib/jvm.jar     && JAVA_CLASSPATH=$PHP_JAVA/lib/jvm.jar

    for i in $PHP_JAVA/include/*; do
      test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE $i"
    done

  else

    for i in `find $PHP_JAVA/include -type d`; do
      test -f $i/jni.h    && JAVA_INCLUDE=-I$i
      test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE -I$i"
    done

    for i in `find $PHP_JAVA/. -type d`; do
      test -f $i/classes.zip && JAVA_CFLAGS=-DJNI_11
      test -f $i/rt.jar      && JAVA_CFLAGS=-DJNI_12
      test -f $i/classes.zip && JAVA_CLASSPATH=$i/classes.zip
      test -f $i/rt.jar      && JAVA_CLASSPATH=$i/rt.jar

      if test -f $i/$java_libext; then 
        JAVA_LIB=java
        JAVA_LIBPATH=$i
        test -d $i/hotspot && PHP_ADD_LIBPATH($i/hotspot)
        test -d $i/classic && PHP_ADD_LIBPATH($i/classic)
        test -d $i/server  && PHP_ADD_LIBPATH($i/server)
        test -d $i/native_threads && PHP_ADD_LIBPATH($i/native_threads)
      fi
    done

    if test -z "$JAVA_INCLUDE"; then
      AC_MSG_RESULT(no)
      AC_MSG_ERROR(unable to find Java VM libraries)
    fi

    JAVA_CFLAGS="$JAVA_CFLAGS -D_REENTRANT"
  fi

  AC_DEFINE(HAVE_JAVA,1,[ ])

  if test -z "$JAVA_LIBPATH"; then
    AC_MSG_ERROR(unable to find Java VM libraries)
  fi

  PHP_ADD_LIBPATH($JAVA_LIBPATH)
  JAVA_CFLAGS="$JAVA_CFLAGS '-DJAVALIB=\"$JAVA_LIBPATH/$java_libext\"'"

  if test "$PHP_SAPI" != "servlet"; then
    PHP_NEW_EXTENSION(java, java.c, shared,, $JAVA_CFLAGS $JAVA_INCLUDE)

    if test "$PHP_SAPI" = "cgi"; then
      PHP_ADD_LIBRARY($JAVA_LIB)
    fi

    INSTALL_IT="$INSTALL_IT; \$(srcdir)/build/shtool mkdir -p -f -m 0755 \$(INSTALL_ROOT)\$(libdir)"
    INSTALL_IT="$INSTALL_IT; \$(INSTALL) -m 0755 \$(srcdir)/ext/java/php_java.jar \$(INSTALL_ROOT)\$(libdir)"
  fi

  PHP_SUBST(JAVA_CLASSPATH)
  PHP_SUBST(JAVA_JAR)
  PHP_SUBST(JAVA_C)

  PHP_ADD_MAKEFILE_FRAGMENT
fi