configure.ac 26.1 KB
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
AC_INIT(modules/c/src/apache2/mod_caucho.c)
AC_PREFIX_DEFAULT(`pwd`)
AC_CONFIG_AUX_DIR(automake)	

dnl Get os info
AC_CANONICAL_SYSTEM

AM_INIT_AUTOMAKE(resin, 3.1.1)

FULL_VERSION="Resin $VERSION -- `date`"
AC_SUBST(FULL_VERSION)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_LD
AC_PROG_EGREP

dnl Checks for poll.h
AC_CHECK_HEADER(sys/poll.h, [ CFLAGS="$CFLAGS -DPOLL" ])
dnl Checks for epoll.h
AC_CHECK_HEADER(sys/epoll.h, [ CFLAGS="$CFLAGS -DEPOLL" ])

AC_PROG_LIBTOOL			    
#
# libtool stuff
#  
if test -z "${LTFLAGS}"; then
  LTFLAGS="--silent"
fi
	
LIBTOOL_SCRIPT="`pwd`/libtool"
LIBTOOL="${LIBTOOL_SCRIPT} ${LTFLAGS}"    
libtoolversion=`${SHELL} ${LIBTOOL_SCRIPT} --version`
case $libtoolversion in
     *1.4*)
       SH_LIBTOOL="${LIBTOOL_SCRIPT}"
       SHLTCFLAGS="-prefer-pic"
       LTCFLAGS="-prefer-non-pic -static"
       ;;
     *)
       SH_LIBTOOL="${SHELL} ${LIBTOOL_SCRIPT} ${LTFLAGS}"
       SHLTCFLAGS=""
       LTCFLAGS=""
       ;;
esac

AC_SUBST(LTFLAGS)	
AC_SUBST(LIBTOOL_SCRIPT)	
AC_SUBST(LIBTOOL)	
AC_SUBST(SH_LIBTOOL)	
AC_SUBST(LTCFLAGS)	
AC_SUBST(EGREP)
     
INCLUDES=""
plugins=common
LIBEXEC=libexec
		
AC_SUBST(plugins)
AC_SUBST(LIBEXEC)
dnl should be unnecessary
AC_SUBST(LD)

ACLOCAL=aclocal	
AUTOMAKE=automake
AC_SUBST(ACLOCAL)	
AC_SUBST(AUTOMAKE)	

#
# additional CFLAGS
#
# for solaris        
CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS"                          

#
# --with-apache-src
#
AC_ARG_WITH(apache-src,
[  --with-apache-src=DIR  Apache src static compilation
], [
apache_src=${withval}

if test -d "${apache_src}/modules"; then
  a=b
elif test -d "${apache_src}/src/modules"; then
  apache_src=${apache_src}/src
else
  AC_MSG_ERROR([Can't find valid Apache source ${apache_src}])
fi

echo "using Apache source in ${apache_src}"

mkdir ${apache_src}/modules/caucho 2> /dev/null
cp modules/c/src/common/*.c ${apache_src}/modules/caucho
cp modules/c/src/common/*.h ${apache_src}/modules/caucho
cp modules/c/src/apache/*.c ${apache_src}/modules/caucho

cat > ${apache_src}/modules/caucho/Makefile.tmpl <<'END'
LIB=libcaucho.a
OBJS=mod_caucho.o stream.o config.o registry.o memory.o

OBJS_PIC=mod_caucho.lo stream.lo config.lo registry.lo memory.lo

$(OBJS) $(OBJS_PIC): Makefile

all: lib

lib: $(LIB)

libcaucho.a: $(OBJS)
	rm -f $@
	ar cr $@ $(OBJS)
	$(RANLIB) $@

libcaucho.o: $(OBJS)
	$(LD) $(LDFLAGS) -r -o $@ $(OBJS)

libcaucho.so: $(OBJS_PIC)
	rm -f $@
	$(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(OBJS_PIC) $(LIBS_SHLIB) 

.SUFFIXES: .o .lo

.c.o:
	$(CC) -c $(INCLUDES) $(CFLAGS) $<

.c.lo:
	$(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $< && mv $*.o $*.lo

# DO NOT REMOVE
mod_caucho.o: cse.h
mod_caucho.lo: cse.h
stream.o: cse.h
stream.lo: cse.h
config.o: cse.h
config.lo: cse.h
registry.o: cse.h
registry.lo: cse.h
memory.o: cse.h
memory.lo: cse.h

END

cat > ${apache_src}/modules/caucho/Makefile.libdir <<'END'
# dummy
END

#grep caucho ${apache_src}/src/Configuration.tmpl >/dev/null 2>/dev/null
#if test "$?" -ne 0; then
#  cat >> ${apache_src}/src/Configuration.tmpl <<'END'
## mod_caucho incorporates Resin into Apache.
#
## AddModule modules/caucho/libcaucho.a
#END
#fi

])
#
# --with-apache
#
AC_ARG_WITH(apache,
[  --with-apache=DIR  the Apache root directory
], [
apache_dir=${withval}

if test "${apache_dir}" = "yes"; then
  apache_dir=/usr/local/apache
fi

if test ! -d "${apache_dir}"; then
  AC_MSG_ERROR([--with-apache=${apache_dir} is not a valid Apache directory])
fi   

apache=1
])

#
# --with-apxs
#
AC_ARG_WITH(apxs,
[  --with-apxs=PATH  the Apache configuration utility
], [
apxs=${withval}

if test "${apxs}" = "yes"; then
  apxs=apxs
fi

apache=1
])

#
# --with-apache-eapi
#
AC_ARG_WITH(apache-eapi,
[  --with-apache-eapi=DIR  Apache eapi support
], [
apache_eapi=${withval}
])

#
# --with-apache-include
#
AC_ARG_WITH(apache-include,
[  --with-apache-include=DIR  the Apache include directory
], [
apache_include=${withval}

if test "${apache_include}" = "yes"; then
    apache_include=
fi

apache=1
])

#
# --with-apache-libexec
#
AC_ARG_WITH(apache-libexec,
[  --with-apache-libexec=DIR  the Apache module directory
], [
apache_libexec=${withval}

if test "${apache_libexec}" = "yes"; then
    apache_libexec=
fi

apache=1
])

#
# --with-apache-conf
#
AC_ARG_WITH(apache-conf,
[  --with-apache-conf=DIR  the Apache configuration
], [
apache_conf=${withval}

if test "${apache_conf}" = "yes"; then
    apache_conf=
fi

apache=1
])

apache_cflags=

#
# --with-apache-cflags
#
AC_ARG_WITH(apache-cflags,
[  --with-apache-cflags=flags  flags for compiling mod_caucho
], [
apache_cflags=${withval}

apache=1
])

#
# check that apxs is okay
#
if test -n "${apxs}"; then
  ${apxs} -q PREFIX >/dev/null 2>/dev/null
  if test "$?" -ne 0; then
    AC_MSG_ERROR(bad apxs ${apxs})
  fi
elif test -x "${apache_bin}/apxs"; then
  apxs=${apache_bin}/apxs 
elif test -x "${apache_dir}/bin/apxs"; then
  apxs=${apache_dir}/bin/apxs 
elif test -x "${apache_dir}/sbin/apxs"; then
  apxs=${apache_dir}/sbin/apxs 
elif test -x "/sbin/apxs"; then
  apxs=/sbin/apxs 
elif test -x "/usr/sbin/apxs"; then
  apxs=/usr/sbin/apxs 
fi
   
#
# heuristics for finding the Apache include directory
#
if test -z "${apache_include}" -a -n "${apxs}"; then
  apache_include=`${apxs} -q INCLUDEDIR`
fi

if test -z "${apache_include}" -a -r "${apache_dir}/include/httpd.h"; then
  apache_include=${apache_dir}/include
fi

if test -n "${apache_include}"; then	
  APACHE_INC="-I${apache_include}"
fi
  
#
# deal with stronghold
#
if test -z "${apache_include}" -a -r "${apache_dir}/src/include/httpd.h"; then
  apache_include=${apache_dir}/src/include

  APACHE_INC="-I${apache_dir}/src/include"
  APACHE_INC="-I${apache_dir}/ssl/include $APACHE_INC"
  APACHE_INC="-I${apache_dir}/src/os/unix $APACHE_INC"
fi

if test -n "$apache" -a ! -r ${apache_include}/httpd.h; then
  AC_MSG_ERROR([Can't find Apache include directory ${apache_include}])
fi

#
# heuristics for finding the Apache bin directory
#
if test -n "${apache_bin}"; then
  a=b
elif test -x "${apxs}"; then
  apache_bin=`${apxs} -q SBINDIR`
  apache_exe="${apache_bin}/`${apxs} -q TARGET`"
elif test -n "${apache_dir}"; then
  apache_bin="${apache_dir}/bin"
fi

if test -n "${apache_exe}"; then
 a=b;
elif test -z "${apache_bin}"; then
 a=b;
elif test -x "${apache_bin}/httpd"; then
 apache_exe="${apache_bin}/httpd"   	
elif test -x "${apache_bin}/apache"; then
 apache_exe="${apache_bin}/apache"   	
elif test -x "${apache_bin}/httpd2"; then
 apache_exe="${apache_bin}/httpd2"
elif test -x "${apache_bin}/apache2"; then
 apache_exe="${apache_bin}/apache2"
fi

if test -n "${apache_exe}" -a ! -x "${apache_exe}"; then
  AC_MSG_ERROR([Can't find Apache binary in directory ${apache_exe}])
fi

#
# heuristics for finding the Apache module directory
#
if test -z "${apache_libexec}" -a -n "${apxs}"; then
  apache_libexec=`${apxs} -q LIBEXECDIR`
fi

if test -z "${apache_libexec}" -a -d "${apache_dir}/libexec"; then
  apache_libexec=${apache_dir}/libexec
fi

if test -z "${apache_libexec}" -a -d "${apache_dir}/modules"; then
  apache_libexec=${apache_dir}/modules
fi

if test -n "$apache" -a ! -d "${apache_libexec}"; then
  AC_MSG_ERROR([Can't find Apache module directory ${apache_libexec}])
fi

#
# Heuristics for finding the Apache configuration directory
#

if test -z "${apache_conf}" -a -n "${apxs}"; then
  apache_confdir=`${apxs} -q SYSCONFDIR`
  
  if test -r "${apache_confdir}"/httpd.conf; then
    apache_conf=${apache_confdir}/httpd.conf
  elif test -r "${apache_confdir}"/apache.conf; then
    apache_conf=${apache_confdir}/apache.conf
  elif test -r "${apache_confdir}"/httpsd.conf; then
    apache_conf=${apache_confdir}/httpsd.conf
  fi
fi

if test -z "${apache_conf}" -a -r "${apache_dir}/conf/httpd.conf"; then
  apache_conf=${apache_dir}/conf/httpd.conf
fi

if test -z "${apache_conf}" -a -r "${apache_dir}/etc/httpd.conf"; then
  apache_conf=${apache_dir}/etc/httpd.conf
fi

if test -n "$apache" -a ! -r "${apache_conf}"; then
  AC_MSG_ERROR([Can't find Apache module configuration ${apache_conf}])
fi

#
# check for apr
#
if test -x "${apxs}"; then
   apr_bin=`${apxs} -q APR_BINDIR 2> /dev/null`
   if test -x "${apr_bin}/apr-config"; then
     apr_inc=`"${apr_bin}/apr-config" --includes`
     APACHE_INC="${APACHE_INC} ${apr_inc}"
   elif test -x "${apr_bin}/apr-1-config"; then
     apr_inc=`"${apr_bin}/apr-1-config" --includes`
     APACHE_INC="${APACHE_INC} ${apr_inc}"
   fi
fi
	
#
# Apache CFLAGS
#

if test -z "$apache_cflags" -a -x "${apxs}"; then
   if test -x "${apr_bin}/apr-config"; then
     apache_cflags="$apache_cflags `${apr_bin}/apr-config --cppflags`"
     apache_cflags="$apache_cflags `${apr_bin}/apr-config --cflags`"
   elif test -x "${apr_bin}/apr-1-config"; then
     apache_cflags="$apache_cflags `${apr_bin}/apr-1-config --cppflags`"
     apache_cflags="$apache_cflags `${apr_bin}/apr-1-config --cflags`"
   else
     apache_cflags="`${apxs} -q CFLAGS`"
   fi
 fi
	
if test -z "$apache_cflags" -a -x "${apache_exe}"; then
   flags=`${apache_exe} -V | grep EAPI`
   if test -n "$flags"; then
     apache_cflags=-DEAPI
   fi
fi

if test -z "$apache_dir" -a -x "${apxs}"; then
   apache_dir=`${apxs} -q PREFIX`
fi

AC_SUBST(APACHE_INC)
AC_SUBST(apache_libexec)
AC_SUBST(apache_conf)
AC_SUBST(apache_dir)
AC_SUBST(apache_cflags)
#
# fill in compilation stuff
#
SO=so

is_gcc=`${CC} -v 2>&1 | grep gcc`
is_gnu_ld=`${LD} -v 2>&1 | grep GNU`

#
# Use apxs if it's available
#
if test -z "${LD_SHLIB}"; then
  if test -n "${apxs}"; then
    CFLAGS_SHLIB=`${apxs} -q CFLAGS_SHLIB`
    LD_SHLIB=`${apxs} -q LD_SHLIB`
    LDFLAGS_SHLIB=`${apxs} -q LDFLAGS_SHLIB`
    LIBS_SHLIB=`${apxs} -q LIBS_SHLIB`

    echo "Using shared library flags from ${apxs}"
  fi
fi
#
# --with-java-home
#
AC_ARG_WITH(java-home,
[  --with-java-home=DIR  java home
], [
JAVA_HOME=${withval}
])

if test -z "$JAVA_HOME"; then
  java=`which java 2>/dev/null`
  if test $? = "0"; then
    while test -h "$java"
    do
      head=`dirname $java`
      tail=`/bin/ls -l $java | awk '{ print $NF; }'`
      if test -f "$tail"; then
        java=$tail
      else
        java=$head/$tail
      fi
    done

    javabin=`dirname $java`
    JAVA_HOME=`cd $javabin/..; pwd`

    # we're in $JAVA_HOME/jre
    if test -f "$JAVA_HOME/lib/rt.jar"; then
      JAVA_HOME=`cd $JAVA_HOME/..; pwd`
    elif test -d "/usr/java"; then
      JAVA_HOME=/usr/java
    elif test -f "/System/Library/Frameworks/JavaVM.framework"; then
      JAVA_HOME="/System/Library/Frameworks/JavaVM.framework"
    fi
  elif test -d "/usr/java"; then
    JAVA_HOME=/usr/java
  elif test -f "/System/Library/Frameworks/JavaVM.framework"; then
    JAVA_HOME="/System/Library/Frameworks/JavaVM.framework"
  fi
fi

echo $ac_n "checking for JAVA_HOME... $JAVA_HOME"

if test ! -d "$JAVA_HOME"; then
  AC_MSG_ERROR([Can't find valid JAVA_HOME ${JAVA_HOME}])
fi

AC_SUBST(JAVA_HOME)
#
# Resin home
#
resin_home=`pwd`
AC_SUBST(resin_home)


#
# 64bit heuristics
#
echo -n "checking if Java is 64-bit... "

tmpname="/tmp/java$$.out"
	       	
$JAVA_HOME/bin/java -version 2> $tmpname
grep "64-Bit" $tmpname 1> /dev/null
if test "$?" = "0"; then
   b64_jni=true
fi

grep "amd64-64" $tmpname 1> /dev/null
if test "$?" = "0"; then
   b64_jni=true
fi

grep "x86_64" $tmpname 1> /dev/null
if test "$?" = "0"; then
   b64_jni=true
fi
               	
$JAVA_HOME/bin/sparcv9/java -version 2> $tmpname
grep "64-Bit" $tmpname 1> /dev/null
     
if test "$?" = "0"; then
   b64_jni=true
fi

$JAVA_HOME/bin/amd64/java -version 2> $tmpname
grep "64-Bit" $tmpname 1> /dev/null
     
if test "$?" = "0"; then
   b64_jni=true
fi

# Require user to use --enable-64bit if the version is optional
# in the javac  
#  
#$JAVA_HOME/bin/java -d64 -version 2> $tmpname
#grep "64-Bit" $tmpname 1> /dev/null
    
#if test "$?" = "0"; then
#   b64_jni=true
#fi

if test -n "$b64_jni"; then	
   echo "yes"
else   
   echo "no"
fi

rm -f $tmpname	
		    	  	
#
# --enable-64bit
#
AC_ARG_ENABLE(64bit,
[  --enable-64bit    Enable 64 bit],
[case "${enableval}" in
 yes) b64=true ;;
 no)  b64=""; b64_jni="" ;;
 *) AC_MSG_ERROR(bad value ${enableval} for --enable-64bit) ;;
 esac],[])

if test -n "${b64}"; then
   b64_jni=true
fi   

if test -n "${b64_jni}"; then        
   CFLAGS="$CFLAGS -DB64"
   LIBEXEC=libexec64
fi

#
# --enable-lfs
#
AC_ARG_ENABLE(lfs,
[  --enable-lfs            Enable large file source support],
[case "${enableval}" in
 yes) lfs=true ;;
 no)  lfs="";;
 *) AC_MSG_ERROR(bad value ${enableval} for --enable-lfs) ;;
 esac],[])

if test -n "${lfs}"; then
  CFLAGS_JNI="$CFLAGS_JNI -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
fi

#
# fill in based on known configurations
#
if test -z "${LD_SHLIB}"; then
  LD_SHLIB=${LD}	
  CFLAGS_SHLIB="-fpic"
  LDFLAGS_SHLIB="-shared"

  case "$target_os" in
    linux*)
	LD_SHLIB=${CC}
	
	if test -n "$b64"; then
  	  CFLAGS="$CFLAGS -m64 -fPIC"
	  LDFLAGS_SHLIB="-shared -fPIC"
	fi
	if test -n "$b64_jni"; then
  	  CFLAGS_JNI="$CFLAGS_JNI -m64 -fPIC"
	  LDFLAGS_SHLIB="-shared -fPIC"
   	fi
	;;
	
    *solaris*)
	if test -n "$is_gcc"; then
	    CFLAGS_SHLIB="-fPIC"
	    
	   if test -n "$b64"; then
  	     CFLAGS="$CFLAGS -m64"
	   fi
           if test -n "$b64_jni"; then
  	     CFLAGS_JNI="$CFLAGS_JNI -m64"
   	   fi
	else
	    CFLAGS_SHLIB="-KPIC"
	    
	   if test -n "$b64"; then
  	     CFLAGS="$CFLAGS -xarch=v9"
	   fi
	   if test -n "$b64_jni"; then
  	     CFLAGS_JNI="$CFLAGS_JNI -xarch=v9"
   	   fi
	fi

	if test -n "$is_gnu_ld"; then
	    LDFLAGS_SHLIB="-shared"
        else
	    LDFLAGS_SHLIB="-G -fPIC"
	fi
	;;

    darwin*)
        CFLAGS_SHLIB="-DSHARED_MODULE"
	LD_SHLIB=${CC}
 	LDFLAGS_SHLIB="-dynamiclib -undefined suppress -flat_namespace"
        if test -n "$b64"; then
  	  CFLAGS="$CFLAGS -arch x86_64"
  	  LDFLAGS_SHLIB="$LDFLAGS_SHLIB -arch x86_64"
        fi
	if test -n "$b64_jni"; then
  	  CFLAGS_JNI="$CFLAGS_JNI -arch x86_64"
  	  LDFLAGS_SHLIB="$LDFLAGS_SHLIB -arch x86_64"
   	fi
        ;;

    *freebsd*)
  	CFLAGS="$CFLAGS -fPIC"
        ;;

    *aix*)
	if test -z "$is_gcc"; then
	   CFLAGS_SHLIB="-bexpall"
	else
	    CFLAGS_SHLIB="-fpic"
	fi
	LDFLAGS_SHLIB=""
	;;

    *hpux*)
	if test -z "$is_gcc"; then
	    CFLAGS_SHLIB="+z"
	else
	    CFLAGS_SHLIB="-fpic"
	fi
	LDFLAGS_SHLIB="-b"
	;;
  esac

  case "$target_cpu" in
    x86_64)
           if test -z "$b64_jni"; then
  	     CFLAGS_JNI="$CFLAGS_JNI -m32"
  	     LDFLAGS_SHLIB="$LDFLAGS_SHLIB -melf_i386"
   	   fi
	;;
  esac	
fi

case "$target_os" in
  linux*)
        CFLAGS="$CFLAGS -DHAS_SOCK_TIMEOUT"
	;;
  darwin*)
        CFLAGS="$CFLAGS -DHAS_SOCK_TIMEOUT"
	;;
esac        

if test -z "$apache"; then
  a=b
elif test -r "${apache_include}/apr_thread_mutex.h" -o -n "${apr_inc}"; then
  echo "Using Apache 2.0 configuration ${apache_conf}"

  plugins="$plugins apache2"
elif test -n "${apache_include}/ap.h"; then
  echo "Using Apache 1.3 configuration ${apache_conf}"

  plugins="$plugins apache1"
else
  AC_MSG_ERROR([Can't find valid Apache directory ${apache_inc}])
fi

if test -n "$apache_cflags"; then
  echo "Using Apache CFLAGS: $apache_cflags"
fi

#
# Using Perl if it's available.
#
PERL=`which perl`
if test -z "${LD_SHLIB}"; then
  if test -z "${LD_SHLIB}" -a "x`$PERL -V:dlsrc 2>/dev/null | grep dlopen`" != "x"; then
    PCC="`$PERL -V:cc | cut -d\' -f2`"
    if test "${PCC}" = "${CC}"; then
      CFLAGS_SHLIB="`$PERL -V:cccdlflags | cut -d\' -f2`"
      LDFLAGS_SHLIB="`$PERL -V:lddlflags | cut -d\' -f2`"
      LD_SHLIB="`$PERL -V:ld | cut -d\' -f2`"
 
      has_clflags=1

      echo "Using shared library flags from Perl"
    fi
  fi
fi

#if test -z "${LD_SHLIB}"; then
#  AC_MSG_ERROR([Can't determine compilation flags.]);
#fi

#
# OS which can handle the Resin launcher
#
resin_pro_plugin=
if test -r "modules/c/src/resin/Makefile.in"; then
   resin_pro_plugin="resin"
fi
	
resin_ssl_plugin=
if test -r "modules/c/src/resinssl/Makefile.in"; then
   resin_ssl_plugin="resinssl"
fi

resin_plugin=

case "$target_cpu" in
  i?86)
	CPU=i386
	resin_plugin="$resin_pro_plugin $resin_ssl_plugin"
	CFLAGS_JNI="$CFLAGS_JNI -D_FILE_OFFSET_BITS=64"
	;;

  sparc*)
	if test -n "${b64_jni}"; then
  	  CPU=sparcv9
	else
  	  CPU=sparc
	fi
	resin_plugin="$resin_pro_plugin $resin_ssl_plugin"
	;;

  x86_64)
	CPU=$target_cpu
	resin_plugin="$resin_pro_plugin $resin_ssl_plugin"
	CFLAGS_JNI="$CFLAGS_JNI -D_FILE_OFFSET_BITS=64"
	;;
	
  *)
	CPU=$target_cpu
	;;
esac

case "$target_os" in
  linux*)
	jni_os=linux
        PROXY_LIBS="-lpthread -lc"
	;;

  *solaris*)
	jni_os=solaris
	CFLAGS="$CFLAGS -D__SOLARIS__"
	PROXY_LIBS='-lnsl -lsocket -lthread'
	;;

  *freebsd*)
	PROXY_LIBS='-lpthread'
        jni_os=freebsd        
        
	tmp=`ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libc_r`
	tmp=$tmp `ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libpthread`
	tmp=$tmp `ldd $JAVA_HOME/bin/java | sed 's/.*=>//' | grep -c libthr`

	case "$tmp" in
	100)
		PROXY_LIBS='-lc_r';
		;;
	010)
		PROXY_LIBS='-lpthread';
		;;
	001)
		PROXY_LIBS='-lthr';
		;;
	*)
		PROXY_LIBS='-lpthread'
		echo "Using -lpthread as default"
		;;
	esac	
	;;

  *darwin*)
	LD=gcc
	SO=jnilib
	resin_plugin="$resin_pro_plugin $resin_ssl_plugin"
	;;

  *hpux*)
	if test -r "$JAVA_HOME/include/hpux/jni_md.h"; then
	  jni_os=hpux
        else
	  jni_os=hp-ux
        fi
	;;

  *aix*)
        jni_os=aix
	;;
esac

AC_SUBST(CPU)
AC_SUBST(OS)
AC_SUBST(SO)
AC_SUBST(CFLAGS)
AC_SUBST(CFLAGS_SHLIB)
AC_SUBST(LD_SHLIB)
AC_SUBST(LDFLAGS_SHLIB)
AC_SUBST(LIBS_SHLIB)
AC_SUBST(PROXY_LIBS)
AC_SUBST(SSL_LIBS)

#
# --with-jni-include
#
AC_ARG_WITH(jni-include,
[  --with-jni-include="-Idir -Idir"  jni include string
], [
JNI_INCLUDE=${withval}
JNI="yes"
])

#
# --enable-jni
#
AC_ARG_ENABLE(jni,
[  --enable-jni    Turn on jni],
[case "${enableval}" in
 yes) JNI=true ;;
 no)  JNI="" ;;
 *) AC_MSG_ERROR(bad value ${enableval} for --enable-jni) ;;
 esac],[JNI=""])

if test -n "$JNI_INCLUDE"; then
  JNI=yes
elif test -r "$JAVA_HOME/include/jni_md.h"; then
  JNI_INCLUDE="-I$JAVA_HOME/include"
  JNI=yes
  echo "checking for JNI in $JAVA_HOME/include ... found"
elif test -r "$JAVA_HOME/include/$jni_os/jni_md.h"; then
  JNI_INCLUDE="-I$JAVA_HOME/include -I$JAVA_HOME/include/$jni_os"
  JNI=yes
  echo "checking for JNI in $JAVA_HOME/include/$jni_os ... found"
elif test -r "/System/Library/Frameworks/JavaVM.framework/Headers/jni_md.h"; then
  # Darwin
  echo "checking for JNI in /System/Library/Frameworks/JavaVM.framework/Headers ... found"
  JNI_INCLUDE="-I/System/Library/Frameworks/JavaVM.framework/Headers"
  JNI=yes
elif test -r "$JAVA_HOME/../Headers/jni_md.h"; then
  # Darwin
  echo "checking for JNI in $JAVA_HOME/../Headers ... found"
  JNI_INCLUDE="-I$JAVA_HOME/../Headers"
  JNI=yes
elif test -r "$JAVA_HOME/include/jni.h"; then
  JNI_INCLUDE="-I$JAVA_HOME/include"
  JNI=yes
  echo "checking for JNI in $JAVA_HOME/include ... found"
else
  JNI=""
  AC_MSG_WARN([Can't find JNI directory ${JAVA_HOME}/include/$jni_os])
fi

if test -r "$JAVA_HOME/include/jvmti.h"; then
  echo "Using JVMTI for class reloading"
  
  CFLAGS="$CFLAGS -DHAS_JVMTI"
elif test -r "$JAVA_HOME/../Headers/jvmti.h"; then
  echo "Using JVMTI for class reloading"
  
  CFLAGS="$CFLAGS -DHAS_JVMTI"
fi

if test -r "$JAVA_HOME/include/jvmdi.h"; then
  echo "Using JVMDI for class reloading"
  
  CFLAGS="$CFLAGS -DHAS_JVMDI"
elif test -r "$JAVA_HOME/../Headers/jvmdi.h"; then
  echo "Using JVMDI for class reloading"
  
  CFLAGS="$CFLAGS -DHAS_JVMDI"
fi
	
if test -n "$JNI"; then
  plugins="$plugins $resin_plugin resin_os"
else  
  echo "Can't JNI include files in JAVA_HOME: $JAVA_HOME"
fi

AC_SUBST(JNI)
AC_SUBST(JNI_INCLUDE)
	
#
# --enable-ssl
#
AC_ARG_ENABLE(ssl,
[  --enable-ssl    Turn on ssl],
[case "${enableval}" in
 yes) ENABLE_SSL=true ;;
 no)  ENABLE_SSL="false" ;;
 *) AC_MSG_ERROR(bad value ${enableval} for --enable-ssl) ;;
 esac],[ENABLE_SSL=""])

#
# --with-openssl
#
AC_ARG_WITH(openssl,
[  --with-openssl=DIR  Openssl directory
], [
OPENSSL=${withval}
OPENSSL_INCLUDE=${OPENSSL}/include	
OPENSSL_LIB=${OPENSSL}/lib	
])

#
# --with-openssl-include
#
AC_ARG_WITH(openssl-include,
[  --with-openssl-include=DIR  Openssl include directory
], [
OPENSSL_INCLUDE=${withval}

if test ! -r "${OPENSSL_INCLUDE}/openssl/ssl23.h"; then
  AC_MSG_ERROR([Can't find valid OpenSSL include ${OPENSSL_INCLUDE}])
fi
])

#
# --with-openssl-lib
#
AC_ARG_WITH(openssl-lib,
[  --with-openssl-lib=DIR  Openssl lib directory
], [
OPENSSL_LIB=${withval}

if test ! -r "${OPENSSL_LIB}/libssl.a" -a \
        ! -r "${OPENSSL_LIB}/libssl.dylib" -a \
	! -r "${OPENSSL_LIB}/libssl.so"; then
  AC_MSG_ERROR([Can't find valid OpenSSL library ${OPENSSL_LIB}])
fi
])

if test "${ENABLE_SSL}" = false; then	
  foo=bar
elif test -n "${OPENSSL_INCLUDE}"; then
  foo=bar
elif test -r ${OPENSSL}/include/openssl/ssl23.h; then
  OPENSSL_INCLUDE=${OPENSSL}/include
elif test -r /usr/include/openssl/ssl23.h; then
  OPENSSL_INCLUDE=/usr/include
elif test -r /usr/local/include/openssl/ssl23.h; then
  OPENSSL_INCLUDE=/usr/local/include
elif test -r /usr/local/ssl/include/openssl/ssl23.h; then
  OPENSSL_INCLUDE=/usr/local/ssl/include
fi

if test "${ENABLE_SSL}" = false; then	
  foo=bar
  
elif test -n "${OPENSSL_LIB}"; then
  foo=bar
  
elif test -n "${b64_jni}" -a -r /lib64/libcrypto.so; then
  OPENSSL_LIB=/lib64
elif test -n "${b64_jni}" -a -r /usr/lib64/libcrypto.so; then
  OPENSSL_LIB=/usr/lib64
  
elif test -r /lib/libcrypto.so; then
  OPENSSL_LIB=/lib
elif test -r /lib/libcrypto.dylib; then
  OPENSSL_LIB=/lib
  
elif test -r /usr/lib/libcrypto.so; then
  OPENSSL_LIB=/usr/lib
elif test -r /usr/lib/libcrypto.dylib; then
  OPENSSL_LIB=/usr/lib
  
elif test -r /usr/local/ssl/lib/libcrypto.so; then
  OPENSSL_LIB=/usr/local/ssl/lib
elif test -r /usr/local/ssl/lib/libcrypto.dylib; then
  OPENSSL_LIB=/usr/local/ssl/lib
elif test -r ${OPENSSL}/lib/libcrypto.a; then
  OPENSSL_LIB=${OPENSSL}/lib
elif test -r /usr/local/ssl/lib/libcrypto.a; then
  OPENSSL_LIB=/usr/local/ssl/lib
elif test -r /usr/local/lib/libssl.a; then
  OPENSSL_LIB=/usr/local/lib
elif test -r /usr/lib/libssl.a; then
  OPENSSL_LIB=/usr/lib
fi

if test -z "${OPENSSL_INCLUDE}"; then	
  foo=bar
elif test -r "${OPENSSL_LIB}/libssl.so"; then	
  SSL_LIBS="${SSL_LIBS} -lssl"
elif test -r "${OPENSSL_LIB}/libssl.dylib"; then	
  SSL_LIBS="${SSL_LIBS} -lssl"
elif test -r "${OPENSSL_LIB}/libssl3.so"; then	
  SSL_LIBS="${SSL_LIBS} -lssl3"
elif test -r "${OPENSSL_LIB}/libssl3.dylib"; then	
  SSL_LIBS="${SSL_LIBS} -lssl3"
elif test -r "${OPENSSL_LIB}/libssl.a"; then	
  SSL_LIBS="${SSL_LIBS} ${OPENSSL_LIB}/libssl.a"
elif test -r "${OPENSSL_LIB}/libssl3.a"; then	
  SSL_LIBS="${SSL_LIBS} ${OPENSSL_LIB}/libssl3.a"
else
  # probably an error
  SSL_LIBS="${SSL_LIBS} -lssl"
fi

if test -z "${OPENSSL_INCLUDE}"; then	
  foo=bar
elif test -r "${OPENSSL_LIB}/libcrypto.so"; then	
  SSL_LIBS="${SSL_LIBS} -lcrypto"
elif test -r "${OPENSSL_LIB}/libcrypto.dylib"; then	
  SSL_LIBS="${SSL_LIBS} -lcrypto"
elif test -r "${OPENSSL_LIB}/libcrypto.a"; then	
  SSL_LIBS="${SSL_LIBS} ${OPENSSL_LIB}/libcrypto.a"
else
  # probably an error
  SSL_LIBS="${SSL_LIBS} -lcrypto"
fi

SSL_OBJ=ssl_stub.o

if test "${ENABLE_SSL}" = false; then	
  echo "Openssl is not enabled"
elif test -z "${OPENSSL_INCLUDE}"; then
  echo "Openssl library was not found"
#elif test ! -r "${OPENSSL_LIB}/libcrypto.so" -a \
#          ! -r "${OPENSSL_LIB}/libcrypto.dylib" -a \
#          ! -r "${OPENSSL_LIB}/libcrypto.a" ; then
#  AC_MSG_ERROR([Can't find valid OpenSSL library in ${OPENSSL_LIB}])
elif test ! -r "${OPENSSL_INCLUDE}/openssl/ssl23.h"; then
  AC_MSG_ERROR([Can't find valid OpenSSL include in ${OPENSSL_INCLUDE}])
else
  echo "Using openssl include in ... ${OPENSSL_INCLUDE}"
  echo "Using openssl lib in ... ${OPENSSL_LIB}"
  echo "Using openssl libraries in ... ${SSL_LIBS}"

  if test -x "${apache_dir}/bin/httpd"; then
    apache_ssl=`${apache_dir}/bin/httpd -l 2>&1 | grep ssl`
    if test -n "$apache_ssl"; then
      CFLAGS="$CFLAGS -DOPENSSL"
      echo "Enabling ssl for mod_caucho" 
    fi
  elif test -x "${apache_dir}/bin/httpd2"; then
    apache_ssl=`${apache_dir}/bin/httpd2 -l 2>&1 | grep ssl`
    if test -n "$apache_ssl"; then
      CFLAGS="$CFLAGS -DOPENSSL"
      echo "Enabling ssl for mod_caucho" 
    fi
  fi

  if test -r "${OPENSSL_INCLUDE}/openssl/engine.h"; then
    CFLAGS_OPENSSL="$OPENSSL_CFLAGS -DSSL_ENGINE"
  fi

  if test -n "${OPENSSL_INCLUDE}"; then
    INCLUDES="$INCLUDES -I${OPENSSL_INCLUDE}"
  fi
  SSL_OBJ=ssl.o
  if test -n "${OPENSSL_LIB}"; then
    LDFLAGS_SHLIB="${LDFLAGS_SHLIB} -L${OPENSSL_LIB}"
  fi
  # PROXY_LIBS="$PROXY_LIBS ${OPENSSL_LIB}/libssl.a ${OPENSSL_LIB}/libcrypto.a"
fi

if test -d /usr/kerberos/include; then
   INCLUDES="$INCLUDES -I/usr/kerberos/include"
fi

#
# test the open ssl
#  		
if test -n "${OPENSSL_LIB}"; then	
cat >conftest.$ac_ext <<_ACEOF
#include <openssl/ssl.h>
#include <openssl/rsa.h>       
#include <openssl/err.h>

int main(int argc, char **argv)
{
  SSLeay_add_ssl_algorithms();
  SSL_load_error_strings();
  
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
    if (0)
      ERR_print_errors_cb(0, 0);
#endif

  return 0;
}
_ACEOF

${CC} -o conftest ${CFLAGS_OPENSSL} ${CFLAGS} ${INCLUDES} conftest.$ac_ext -L${OPENSSL_LIB} ${SSL_LIBS} ${PROXY_LIBS} 1>/dev/null 2>/dev/null

if test "$?" != 0; then
  ${CC} -o conftest ${CFLAGS_OPENSSL} ${CFLAGS} ${INCLUDES} conftest.$ac_ext -L${OPENSSL_LIB} ${SSL_LIBS} ${PROXY_LIBS}

  AC_MSG_WARN(Can't compile SSL.  Check compilation flags: ${CC} ${CFLAGS_OPENSSL} ${CFLAGS} ${INCLUDES} -L${OPENSSL_LIB} ${SSL_LIBS} ${PROXY_LIBS})
  
  resin_ssl_plugin=""
else
  ./conftest

  if test "$?" != 0; then
    AC_MSG_WARN(Can't execute SSL.  Check that load version in the library path: ${LD_LIBRARY_PATH} matches the expected version.)
  fi
fi  
	
rm -f conftest conftest.$ac_ext
fi   

AC_SUBST(INCLUDES)
AC_SUBST(CFLAGS_OPENSSL)
AC_SUBST(CFLAGS_JNI)
AC_SUBST(SSL_OBJ)

PERL="perl"
#
# --with-perl
#
AC_ARG_WITH(perl,
[  --with-perl=DIR  Perl binary location
], [
PERL=${withval}
])

AC_SUBST(PERL)

#
# --enable-debug
#
AC_ARG_ENABLE(debug,
[  --enable-debug    Turn on debugging],
[case "${enableval}" in
 yes) debug=true ;;
 no)  debug=false ;;
 *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
 esac],[debug=false])

if test "$debug" = true; then
  CFLAGS="$CFLAGS -DDEBUG -Wall"
  HARDCORE_CFLAGS="$HARDCORE_CFLAGS -DDEBUG"
fi

AC_OUTPUT([
Makefile
modules/c/src/Makefile
modules/c/src/common/Makefile
modules/c/src/apache1/Makefile
modules/c/src/apache2/Makefile
modules/c/src/resin_os/Makefile
contrib/init.resin
], [])

if test -n "${resin_pro_plugin}"; then
  AC_OUTPUT([
    modules/c/src/resin/Makefile
    modules/c/src/resinssl/Makefile
  ])
fi