libraries.m4 revision 945:584dc2e95e04
1#
2# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.  Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26AC_DEFUN_ONCE([LIB_SETUP_INIT],
27[
28        
29###############################################################################
30#
31# OS specific settings that we never will need to probe.
32#
33if test "x$OPENJDK_TARGET_OS" = xlinux; then
34    AC_MSG_CHECKING([what is not needed on Linux?])
35    PULSE_NOT_NEEDED=yes
36    AC_MSG_RESULT([pulse])
37fi
38
39if test "x$OPENJDK_TARGET_OS" = xsolaris; then
40    AC_MSG_CHECKING([what is not needed on Solaris?])
41    ALSA_NOT_NEEDED=yes
42    PULSE_NOT_NEEDED=yes
43    AC_MSG_RESULT([alsa pulse])
44fi
45
46if test "x$OPENJDK_TARGET_OS" = xaix; then
47    AC_MSG_CHECKING([what is not needed on AIX?])
48    ALSA_NOT_NEEDED=yes
49    PULSE_NOT_NEEDED=yes
50    AC_MSG_RESULT([alsa pulse])
51fi
52
53
54if test "x$OPENJDK_TARGET_OS" = xwindows; then
55    AC_MSG_CHECKING([what is not needed on Windows?])
56    CUPS_NOT_NEEDED=yes    
57    ALSA_NOT_NEEDED=yes
58    PULSE_NOT_NEEDED=yes
59    X11_NOT_NEEDED=yes
60    AC_MSG_RESULT([alsa cups pulse x11])
61fi
62
63if test "x$OPENJDK_TARGET_OS" = xmacosx; then
64    AC_MSG_CHECKING([what is not needed on MacOSX?])
65    ALSA_NOT_NEEDED=yes
66    PULSE_NOT_NEEDED=yes
67    X11_NOT_NEEDED=yes
68    FREETYPE2_NOT_NEEDED=yes    
69    # If the java runtime framework is disabled, then we need X11.
70    # This will be adjusted below.
71    AC_MSG_RESULT([alsa pulse x11])
72fi
73
74if test "x$OPENJDK_TARGET_OS" = xbsd; then
75    AC_MSG_CHECKING([what is not needed on bsd?])
76    ALSA_NOT_NEEDED=yes
77    AC_MSG_RESULT([alsa])    
78fi
79
80if test "x$OPENJDK" = "xfalse"; then
81    FREETYPE2_NOT_NEEDED=yes
82fi
83
84if test "x$SUPPORT_HEADFUL" = xno; then
85    X11_NOT_NEEDED=yes
86fi
87
88###############################################################################
89#
90# Check for MacOSX support for OpenJDK. If this exists, try to build a JVM
91# that uses this API. 
92#
93AC_ARG_ENABLE([macosx-runtime-support], [AS_HELP_STRING([--disable-macosx-runtime-support],
94	[disable the use of MacOSX Java runtime support framework @<:@enabled@:>@])],
95	[MACOSX_RUNTIME_SUPPORT="${enableval}"],[MACOSX_RUNTIME_SUPPORT="no"])
96
97USE_MACOSX_RUNTIME_SUPPORT=no
98AC_MSG_CHECKING([for explicit Java runtime support in the OS])
99if test -f /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Headers/JavaRuntimeSupport.h; then
100    if test "x$MACOSX_RUNTIME_SUPPORT" != xno; then
101        MACOSX_RUNTIME_SUPPORT=yes
102        USE_MACOSX_RUNTIME_SUPPORT=yes
103        AC_MSG_RESULT([yes, does not need alsa freetype2 pulse and X11])
104    else
105        AC_MSG_RESULT([yes, but explicitly disabled.])
106    fi
107else
108    AC_MSG_RESULT([no])
109fi
110
111if test "x$OPENJDK_TARGET_OS" = xmacosx && test "x$USE_MACOSX_RUNTIME_SUPPORT" = xno; then
112    AC_MSG_CHECKING([what is not needed on an X11 build on MacOSX?])
113    X11_NOT_NEEDED=
114    FREETYPE2_NOT_NEEDED=
115    AC_MSG_RESULT([alsa pulse])
116fi
117])
118
119AC_DEFUN_ONCE([LIB_SETUP_X11],
120[
121
122###############################################################################
123#
124# Check for X Windows
125#
126
127# Check if the user has specified sysroot, but not --x-includes or --x-libraries.
128# Make a simple check for the libraries at the sysroot, and setup --x-includes and
129# --x-libraries for the sysroot, if that seems to be correct.
130if test "x$SYS_ROOT" != "x/"; then
131  if test "x$x_includes" = xNONE; then
132    if test -f "$SYS_ROOT/usr/X11R6/include/X11/Xlib.h"; then
133      x_includes="$SYS_ROOT/usr/X11R6/include"
134    elif test -f "$SYS_ROOT/usr/include/X11/Xlib.h"; then
135      x_includes="$SYS_ROOT/usr/include"
136    fi
137  fi
138  if test "x$x_libraries" = xNONE; then
139    if test -f "$SYS_ROOT/usr/X11R6/lib/libX11.so"; then
140      x_libraries="$SYS_ROOT/usr/X11R6/lib"
141    elif test "$SYS_ROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
142      x_libraries="$SYS_ROOT/usr/lib64"
143    elif test -f "$SYS_ROOT/usr/lib/libX11.so"; then
144      x_libraries="$SYS_ROOT/usr/lib"
145    fi
146  fi
147fi
148
149# Now let autoconf do it's magic
150AC_PATH_X
151AC_PATH_XTRA
152
153# AC_PATH_XTRA creates X_LIBS and sometimes adds -R flags. When cross compiling
154# this doesn't make sense so we remove it.
155if test "x$COMPILE_TYPE" = xcross; then
156  X_LIBS=`$ECHO $X_LIBS | $SED 's/-R \{0,1\}[[^ ]]*//g'`
157fi
158
159if test "x$no_x" = xyes && test "x$X11_NOT_NEEDED" != xyes; then 
160    HELP_MSG_MISSING_DEPENDENCY([x11])
161    AC_MSG_ERROR([Could not find X11 libraries. $HELP_MSG])
162fi
163
164# Some of the old makefiles require a setting of OPENWIN_HOME
165# Since the X11R6 directory has disappeared on later Linuxes,
166# we need to probe for it.
167if test "x$OPENJDK_TARGET_OS" = xlinux; then
168    if test -d "$SYS_ROOT/usr/X11R6"; then
169        OPENWIN_HOME="$SYS_ROOT/usr/X11R6"
170    elif test -d "$SYS_ROOT/usr/include/X11"; then
171        OPENWIN_HOME="$SYS_ROOT/usr"
172    fi
173fi
174if test "x$OPENJDK_TARGET_OS" = xsolaris; then
175    OPENWIN_HOME="/usr/openwin"
176fi
177AC_SUBST(OPENWIN_HOME)
178
179
180#
181# Weird Sol10 something check...TODO change to try compile
182#
183if test "x${OPENJDK_TARGET_OS}" = xsolaris; then
184  if test "`uname -r`" = "5.10"; then
185     if test "`${EGREP} -c XLinearGradient ${OPENWIN_HOME}/share/include/X11/extensions/Xrender.h`" = "0"; then
186     	X_CFLAGS="${X_CFLAGS} -DSOLARIS10_NO_XRENDER_STRUCTS"
187     fi
188  fi
189fi
190
191AC_LANG_PUSH(C)
192OLD_CFLAGS="$CFLAGS"
193CFLAGS="$CFLAGS $X_CFLAGS"
194
195# Need to include Xlib.h and Xutil.h to avoid "present but cannot be compiled" warnings on Solaris 10
196AC_CHECK_HEADERS([X11/extensions/shape.h X11/extensions/Xrender.h X11/extensions/XTest.h X11/Intrinsic.h],
197                 [X11_A_OK=yes],
198                 [X11_A_OK=no; break],
199                 [ # include <X11/Xlib.h>
200                   # include <X11/Xutil.h>
201                 ])
202
203CFLAGS="$OLD_CFLAGS"
204AC_LANG_POP(C)
205
206if test "x$X11_A_OK" = xno && test "x$X11_NOT_NEEDED" != xyes; then 
207    HELP_MSG_MISSING_DEPENDENCY([x11])
208    AC_MSG_ERROR([Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). $HELP_MSG])
209fi
210
211AC_SUBST(X_CFLAGS)
212AC_SUBST(X_LIBS)
213])
214
215AC_DEFUN_ONCE([LIB_SETUP_CUPS],
216[
217
218###############################################################################
219#
220# The common unix printing system cups is used to print from java.
221#
222AC_ARG_WITH(cups, [AS_HELP_STRING([--with-cups],
223    [specify prefix directory for the cups package
224	 (expecting the headers under PATH/include)])])
225AC_ARG_WITH(cups-include, [AS_HELP_STRING([--with-cups-include],
226	[specify directory for the cups include files])])
227
228if test "x$CUPS_NOT_NEEDED" = xyes; then
229	if test "x${with_cups}" != x || test "x${with_cups_include}" != x; then
230		AC_MSG_WARN([cups not used, so --with-cups is ignored])
231	fi
232	CUPS_CFLAGS=
233else
234	CUPS_FOUND=no
235
236	if test "x${with_cups}" = xno || test "x${with_cups_include}" = xno; then
237	    AC_MSG_ERROR([It is not possible to disable the use of cups. Remove the --without-cups option.])
238	fi
239
240	if test "x${with_cups}" != x; then
241	    CUPS_CFLAGS="-I${with_cups}/include"
242	    CUPS_FOUND=yes
243	fi
244	if test "x${with_cups_include}" != x; then
245	    CUPS_CFLAGS="-I${with_cups_include}"
246	    CUPS_FOUND=yes
247	fi
248	if test "x$CUPS_FOUND" = xno; then
249	    BDEPS_CHECK_MODULE(CUPS, cups, xxx, [CUPS_FOUND=yes])
250	fi
251	if test "x$CUPS_FOUND" = xno; then
252	    # Are the cups headers installed in the default /usr/include location?
253	    AC_CHECK_HEADERS([cups/cups.h cups/ppd.h],
254	                     [CUPS_FOUND=yes
255	                      CUPS_CFLAGS=
256	                      DEFAULT_CUPS=yes])
257	fi
258	if test "x$CUPS_FOUND" = xno; then
259	    # Getting nervous now? Lets poke around for standard Solaris third-party
260	    # package installation locations.
261	    AC_MSG_CHECKING([for cups headers])
262	    if test -s /opt/sfw/cups/include/cups/cups.h; then
263	       # An SFW package seems to be installed!
264	       CUPS_FOUND=yes
265	       CUPS_CFLAGS="-I/opt/sfw/cups/include"
266	    elif test -s /opt/csw/include/cups/cups.h; then
267	       # A CSW package seems to be installed!
268	       CUPS_FOUND=yes
269	       CUPS_CFLAGS="-I/opt/csw/include"
270	    fi
271	    AC_MSG_RESULT([$CUPS_FOUND])
272	fi
273	if test "x$CUPS_FOUND" = xno; then 
274	    HELP_MSG_MISSING_DEPENDENCY([cups])
275	    AC_MSG_ERROR([Could not find cups! $HELP_MSG ])
276	fi
277fi
278
279AC_SUBST(CUPS_CFLAGS)
280
281])
282
283AC_DEFUN_ONCE([LIB_SETUP_FREETYPE],
284[
285
286###############################################################################
287#
288# The ubiquitous freetype2 library is used to render fonts.
289#
290AC_ARG_WITH(freetype, [AS_HELP_STRING([--with-freetype],
291	[specify prefix directory for the freetype2 package
292     (expecting the libraries under PATH/lib and the headers under PATH/include)])])
293
294# If we are using the OS installed system lib for freetype, then we do not need to copy it to the build tree
295USING_SYSTEM_FT_LIB=false
296
297if test "x$FREETYPE2_NOT_NEEDED" = xyes; then
298	if test "x$with_freetype" != x || test "x$with_freetype_include" != x || test "x$with_freetype_lib" != x; then
299		AC_MSG_WARN([freetype not used, so --with-freetype is ignored])
300	fi
301	FREETYPE2_CFLAGS=
302	FREETYPE2_LIBS=
303        FREETYPE2_LIB_PATH=
304else
305	FREETYPE2_FOUND=no
306
307	if test "x$with_freetype" != x; then
308            BASIC_FIXUP_PATH(with_freetype)
309	    FREETYPE2_LIBS="-L$with_freetype/lib -lfreetype"
310            FREETYPE2_LIB_PATH="$with_freetype/lib"
311            if test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$OPENJDK_TARGET_CPU" = xx86_64 && test -d "$with_freetype/lib/amd64"; then
312                FREETYPE2_LIBS="-L$with_freetype/lib/amd64 -lfreetype"
313                FREETYPE2_LIB_PATH="$with_freetype/lib/amd64"
314            fi
315            if test "x$OPENJDK_TARGET_OS" = xwindows; then
316                FREETYPE2_LIBS="$with_freetype/lib/freetype.lib"
317            fi
318	    FREETYPE2_CFLAGS="-I$with_freetype/include"
319            if test -s $with_freetype/include/ft2build.h && test -d $with_freetype/include/freetype2/freetype; then
320                FREETYPE2_CFLAGS="-I$with_freetype/include/freetype2 -I$with_freetype/include"
321            fi
322 	    FREETYPE2_FOUND=yes
323   	    if test "x$FREETYPE2_FOUND" = xyes; then
324	        # Verify that the directories exist 
325                if ! test -d "$with_freetype/lib" || ! test -d "$with_freetype/include"; then
326		   AC_MSG_ERROR([Could not find the expected directories $with_freetype/lib and $with_freetype/include])
327		fi
328	        # List the contents of the lib.
329		FREETYPELIB=`ls $with_freetype/lib/libfreetype.so $with_freetype/lib/freetype.dll 2> /dev/null`
330                if test "x$FREETYPELIB" = x; then
331		   AC_MSG_ERROR([Could not find libfreetype.so nor freetype.dll in $with_freetype/lib])
332		fi
333	        # Check one h-file
334                if ! test -s "$with_freetype/include/ft2build.h"; then
335		   AC_MSG_ERROR([Could not find $with_freetype/include/ft2build.h])
336		fi
337            fi
338        fi
339	if test "x$FREETYPE2_FOUND" = xno; then
340	    BDEPS_CHECK_MODULE(FREETYPE2, freetype2, xxx, [FREETYPE2_FOUND=yes], [FREETYPE2_FOUND=no])
341            USING_SYSTEM_FT_LIB=true
342	fi
343	if test "x$FREETYPE2_FOUND" = xno && test "x$OPENJDK_TARGET_OS" = xwindows; then
344            FREETYPELOCATION="$PROGRAMFILES/GnuWin32"
345            BASIC_FIXUP_PATH(FREETYPELOCATION)
346	    AC_MSG_CHECKING([for freetype in some standard windows locations])
347	    if test -s "$FREETYPELOCATION/include/ft2build.h" && test -d "$FREETYPELOCATION/include/freetype2/freetype"; then
348	        FREETYPE2_CFLAGS="-I$FREETYPELOCATION/include/freetype2 -I$FREETYPELOCATION/include"
349	        FREETYPE2_LIBS="$FREETYPELOCATION/lib/freetype.lib"
350 	        FREETYPE2_LIB_PATH="$FREETYPELOCATION/lib"
351                if ! test -s "$FREETYPE2_LIBS"; then
352		   AC_MSG_ERROR([Could not find $FREETYPE2_LIBS])
353		fi
354                if ! test -s "$FREETYPE2_LIB_PATH/freetype.dll"; then
355		   AC_MSG_ERROR([Could not find $FREETYPE2_LIB_PATH/freetype.dll])
356		fi
357                USING_SYSTEM_FT_LIB=true
358                FREETYPE2_FOUND=yes
359	    fi
360	    AC_MSG_RESULT([$FREETYPE2_FOUND])         
361        fi
362	if test "x$FREETYPE2_FOUND" = xno; then
363	    PKG_CHECK_MODULES(FREETYPE2, freetype2, [FREETYPE2_FOUND=yes], [FREETYPE2_FOUND=no])
364            # On solaris, pkg_check adds -lz to freetype libs, which isn't necessary for us.
365            FREETYPE2_LIBS=`$ECHO $FREETYPE2_LIBS | $SED 's/-lz//g'` 
366            USING_SYSTEM_FT_LIB=true
367            # 64-bit libs for Solaris x86 are installed in the amd64 subdirectory, change lib to lib/amd64
368            if test "x$FREETYPE2_FOUND" = xyes && test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$OPENJDK_TARGET_CPU" = xx86_64; then
369              FREETYPE2_LIBS=`$ECHO $FREETYPE2_LIBS | $SED 's?/lib?/lib/amd64?g'`
370            fi
371	fi
372	if test "x$FREETYPE2_FOUND" = xno; then
373	    AC_MSG_CHECKING([for freetype in some standard locations])
374	
375	    if test -s $SYS_ROOT/usr/X11/include/ft2build.h && test -d $SYS_ROOT/usr/X11/include/freetype2/freetype; then
376	        DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/X11/include/freetype2 -I$SYS_ROOT/usr/X11/include"
377	        DEFAULT_FREETYPE_LIBS="-L$SYS_ROOT/usr/X11/lib -lfreetype"
378	    fi
379	    if test -s $SYS_ROOT/usr/include/ft2build.h && test -d $SYS_ROOT/usr/include/freetype2/freetype; then
380	        DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/include/freetype2"
381	        DEFAULT_FREETYPE_LIBS="-lfreetype"
382	    fi
383	
384	    PREV_CXXCFLAGS="$CXXFLAGS"
385	    PREV_LDFLAGS="$LDFLAGS"
386	    CXXFLAGS="$CXXFLAGS $DEFAULT_FREETYPE_CFLAGS"
387	    LDFLAGS="$LDFLAGS $DEFAULT_FREETYPE_LIBS"
388	    AC_LINK_IFELSE([AC_LANG_SOURCE([[#include<ft2build.h>
389	                    #include FT_FREETYPE_H 
390	                   int main() { return 0; }
391	                  ]])],
392	                  [
393	                      # Yes, the default cflags and libs did the trick.
394	                      FREETYPE2_FOUND=yes
395	                      FREETYPE2_CFLAGS="$DEFAULT_FREETYPE_CFLAGS"
396	                      FREETYPE2_LIBS="$DEFAULT_FREETYPE_LIBS"
397	                  ],
398	                  [
399	                      FREETYPE2_FOUND=no
400	                  ])
401            CXXCFLAGS="$PREV_CXXFLAGS"
402	    LDFLAGS="$PREV_LDFLAGS"
403	    AC_MSG_RESULT([$FREETYPE2_FOUND])
404            USING_SYSTEM_FT_LIB=true
405	fi
406	if test "x$FREETYPE2_FOUND" = xno; then
407		HELP_MSG_MISSING_DEPENDENCY([freetype2])
408		AC_MSG_ERROR([Could not find freetype2! $HELP_MSG ])
409	fi
410
411        if test "x$OPENJDK_TARGET_OS" != xwindows; then
412            # AC_CHECK_LIB does not support use of cl.exe
413            PREV_LDFLAGS="$LDFLAGS"
414            LDFLAGS="$FREETYPE2_LIBS"
415            AC_CHECK_LIB(freetype, FT_Init_FreeType, 
416                         FREETYPE2_FOUND=true, 
417                         AC_MSG_ERROR([Could not find freetype2! $HELP_MSG ]))
418            LDFLAGS="$PREV_LDFLAGS"
419        fi
420fi
421
422AC_SUBST(USING_SYSTEM_FT_LIB)
423AC_SUBST(FREETYPE2_LIB_PATH)
424AC_SUBST(FREETYPE2_CFLAGS)
425AC_SUBST(FREETYPE2_LIBS)
426
427])
428
429AC_DEFUN_ONCE([LIB_SETUP_ALSA],
430[
431
432###############################################################################
433#
434# Check for alsa headers and libraries. Used on Linux/GNU systems.
435#
436AC_ARG_WITH(alsa, [AS_HELP_STRING([--with-alsa],
437	[specify prefix directory for the alsa package
438	 (expecting the libraries under PATH/lib and the headers under PATH/include)])])
439AC_ARG_WITH(alsa-include, [AS_HELP_STRING([--with-alsa-include],
440	[specify directory for the alsa include files])])
441AC_ARG_WITH(alsa-lib, [AS_HELP_STRING([--with-alsa-lib],
442	[specify directory for the alsa library])])
443
444if test "x$ALSA_NOT_NEEDED" = xyes; then
445	if test "x${with_alsa}" != x || test "x${with_alsa_include}" != x || test "x${with_alsa_lib}" != x; then
446		AC_MSG_WARN([alsa not used, so --with-alsa is ignored])
447	fi
448	ALSA_CFLAGS=
449	ALSA_LIBS=
450else
451	ALSA_FOUND=no
452
453	if test "x${with_alsa}" = xno || test "x${with_alsa_include}" = xno || test "x${with_alsa_lib}" = xno; then
454	    AC_MSG_ERROR([It is not possible to disable the use of alsa. Remove the --without-alsa option.])
455	fi
456
457	if test "x${with_alsa}" != x; then
458	    ALSA_LIBS="-L${with_alsa}/lib -lalsa"
459	    ALSA_CFLAGS="-I${with_alsa}/include"
460	    ALSA_FOUND=yes
461	fi
462	if test "x${with_alsa_include}" != x; then
463	    ALSA_CFLAGS="-I${with_alsa_include}"
464	    ALSA_FOUND=yes
465	fi
466	if test "x${with_alsa_lib}" != x; then
467	    ALSA_LIBS="-L${with_alsa_lib} -lalsa"
468	    ALSA_FOUND=yes
469	fi
470	if test "x$ALSA_FOUND" = xno; then
471	    BDEPS_CHECK_MODULE(ALSA, alsa, xxx, [ALSA_FOUND=yes], [ALSA_FOUND=no])
472	fi
473	if test "x$ALSA_FOUND" = xno; then
474	    PKG_CHECK_MODULES(ALSA, alsa, [ALSA_FOUND=yes], [ALSA_FOUND=no])
475	fi
476	if test "x$ALSA_FOUND" = xno; then
477	    AC_CHECK_HEADERS([alsa/asoundlib.h],
478	                     [ALSA_FOUND=yes
479	                      ALSA_CFLAGS=-Iignoreme
480	                      ALSA_LIBS=-lasound
481	                      DEFAULT_ALSA=yes],
482	                     [ALSA_FOUND=no])
483	fi
484	if test "x$ALSA_FOUND" = xno; then 
485	    HELP_MSG_MISSING_DEPENDENCY([alsa])
486	    AC_MSG_ERROR([Could not find alsa! $HELP_MSG ])
487	fi    
488fi
489
490AC_SUBST(ALSA_CFLAGS)
491AC_SUBST(ALSA_LIBS)
492
493])
494
495AC_DEFUN_ONCE([LIB_SETUP_MISC_LIBS],
496[
497
498###############################################################################
499#
500# Check for the jpeg library
501#
502
503USE_EXTERNAL_LIBJPEG=true
504AC_CHECK_LIB(jpeg, main, [],
505             [ USE_EXTERNAL_LIBJPEG=false
506               AC_MSG_NOTICE([Will use jpeg decoder bundled with the OpenJDK source])
507             ])
508AC_SUBST(USE_EXTERNAL_LIBJPEG)
509        
510###############################################################################
511#
512# Check for the gif library
513#
514
515AC_ARG_WITH(giflib, [AS_HELP_STRING([--with-giflib],
516	[use giflib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
517
518
519AC_MSG_CHECKING([for which giflib to use])
520
521# default is bundled
522DEFAULT_GIFLIB=bundled
523
524#
525# if user didn't specify, use DEFAULT_GIFLIB
526#
527if test "x${with_giflib}" = "x"; then
528    with_giflib=${DEFAULT_GIFLIB}
529fi
530
531AC_MSG_RESULT(${with_giflib})
532
533if test "x${with_giflib}" = "xbundled"; then
534    USE_EXTERNAL_LIBGIF=false
535elif test "x${with_giflib}" = "xsystem"; then
536    AC_CHECK_HEADER(gif_lib.h, [],
537             [ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])])
538    AC_CHECK_LIB(gif, DGifGetCode, [],
539             [ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])])
540
541    USE_EXTERNAL_LIBGIF=true
542else
543    AC_MSG_ERROR([Invalid value of --with-giflib: ${with_giflib}, use 'system' or 'bundled'])
544fi
545AC_SUBST(USE_EXTERNAL_LIBGIF)
546
547###############################################################################
548#
549# Check for the zlib library
550#
551
552AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib],
553	[use zlib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
554
555AC_CHECK_LIB(z, compress,
556             [ ZLIB_FOUND=yes ],
557             [ ZLIB_FOUND=no ])
558
559AC_MSG_CHECKING([for which zlib to use])
560
561DEFAULT_ZLIB=bundled
562if test "x$OPENJDK_TARGET_OS" = xmacosx; then
563#
564# On macosx default is system...on others default is 
565#
566    DEFAULT_ZLIB=system
567fi
568
569if test "x${ZLIB_FOUND}" != "xyes"; then
570#
571# If we don't find any system...set default to bundled
572#
573    DEFAULT_ZLIB=bundled
574fi
575
576#
577# If user didn't specify, use DEFAULT_ZLIB
578#
579if test "x${with_zlib}" = "x"; then
580    with_zlib=${DEFAULT_ZLIB}
581fi
582
583if test "x${with_zlib}" = "xbundled"; then
584    USE_EXTERNAL_LIBZ=false
585    AC_MSG_RESULT([bundled])
586elif test "x${with_zlib}" = "xsystem"; then
587    if test "x${ZLIB_FOUND}" = "xyes"; then
588        USE_EXTERNAL_LIBZ=true
589        AC_MSG_RESULT([system])
590    else
591        AC_MSG_RESULT([system not found])
592        AC_MSG_ERROR([--with-zlib=system specified, but no zlib found!])  
593    fi
594else
595    AC_MSG_ERROR([Invalid value for --with-zlib: ${with_zlib}, use 'system' or 'bundled'])  
596fi
597
598AC_SUBST(USE_EXTERNAL_LIBZ)
599
600###############################################################################
601LIBZIP_CAN_USE_MMAP=true
602
603AC_SUBST(LIBZIP_CAN_USE_MMAP)
604
605###############################################################################
606#
607# Check if altzone exists in time.h
608#
609
610AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [return (int)altzone;])],
611            [has_altzone=yes],
612            [has_altzone=no])
613if test "x$has_altzone" = xyes; then
614    AC_DEFINE([HAVE_ALTZONE], 1, [Define if you have the external 'altzone' variable in time.h])
615fi
616
617###############################################################################
618#
619# Check the maths library
620#
621
622AC_CHECK_LIB(m, cos, [],
623             [ 
624                  AC_MSG_NOTICE([Maths library was not found])
625             ])
626AC_SUBST(LIBM)
627
628###############################################################################
629#
630# Check for libdl.so
631
632save_LIBS="$LIBS"
633LIBS=""
634AC_CHECK_LIB(dl,dlopen)
635LIBDL="$LIBS"
636AC_SUBST(LIBDL)
637LIBS="$save_LIBS"
638
639])
640
641AC_DEFUN_ONCE([LIB_SETUP_STATIC_LINK_LIBSTDCPP],
642[
643###############################################################################
644#
645# statically link libstdc++ before C++ ABI is stablized on Linux unless 
646# dynamic build is configured on command line.
647#
648AC_ARG_WITH([stdc++lib], [AS_HELP_STRING([--with-stdc++lib=<static>,<dynamic>,<default>],
649  [force linking of the C++ runtime on Linux to either static or dynamic, default is static with dynamic as fallback])],
650  [
651    if test "x$with_stdc__lib" != xdynamic && test "x$with_stdc__lib" != xstatic \
652        && test "x$with_stdc__lib" != xdefault; then
653      AC_MSG_ERROR([Bad parameter value --with-stdc++lib=$with_stdc__lib!])
654    fi
655  ],
656  [with_stdc__lib=default]
657)
658
659if test "x$OPENJDK_TARGET_OS" = xlinux; then
660    # Test if -lstdc++ works.
661    AC_MSG_CHECKING([if dynamic link of stdc++ is possible])
662    AC_LANG_PUSH(C++)
663    OLD_CXXFLAGS="$CXXFLAGS"
664    CXXFLAGS="$CXXFLAGS -lstdc++"
665    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
666            [has_dynamic_libstdcxx=yes],
667            [has_dynamic_libstdcxx=no])
668    CXXFLAGS="$OLD_CXXFLAGS"
669    AC_LANG_POP(C++)
670    AC_MSG_RESULT([$has_dynamic_libstdcxx])
671
672    # Test if stdc++ can be linked statically.
673    AC_MSG_CHECKING([if static link of stdc++ is possible])
674    STATIC_STDCXX_FLAGS="-Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic"
675    AC_LANG_PUSH(C++)
676    OLD_LIBS="$LIBS"
677    OLD_CXX="$CXX"
678    LIBS="$STATIC_STDCXX_FLAGS"
679    CXX="$CC"                       
680    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
681            [has_static_libstdcxx=yes],
682            [has_static_libstdcxx=no])
683    LIBS="$OLD_LIBS"
684    CXX="$OLD_CXX"
685    AC_LANG_POP(C++)
686    AC_MSG_RESULT([$has_static_libstdcxx])
687
688    if test "x$has_static_libstdcxx" = xno && test "x$has_dynamic_libstdcxx" = xno; then
689        AC_MSG_ERROR([Cannot link to stdc++, neither dynamically nor statically!])
690    fi
691
692    if test "x$with_stdc__lib" = xstatic && test "x$has_static_libstdcxx" = xno; then
693        AC_MSG_ERROR([Static linking of libstdc++ was not possible!])
694    fi
695
696    if test "x$with_stdc__lib" = xdynamic && test "x$has_dynamic_libstdcxx" = xno; then
697        AC_MSG_ERROR([Dynamic linking of libstdc++ was not possible!])
698    fi
699
700    AC_MSG_CHECKING([how to link with libstdc++])
701    # If dynamic was requested, it's available since it would fail above otherwise.
702    # If dynamic wasn't requested, go with static unless it isn't available.
703    if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
704        LIBCXX="$LIBCXX -lstdc++"
705        LDCXX="$CXX"
706        STATIC_CXX_SETTING="STATIC_CXX=false"
707        AC_MSG_RESULT([dynamic])
708    else
709        LIBCXX="$LIBCXX $STATIC_STDCXX_FLAGS"
710        LDCXX="$CC"
711        STATIC_CXX_SETTING="STATIC_CXX=true"
712        AC_MSG_RESULT([static])
713    fi
714fi
715AC_SUBST(STATIC_CXX_SETTING)
716
717if test "x$JVM_VARIANT_ZERO" = xtrue || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
718    # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS
719    PKG_CHECK_MODULES([LIBFFI], [libffi])
720
721fi
722
723if test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
724    AC_CHECK_PROG([LLVM_CONFIG], [llvm-config], [llvm-config])
725
726    if test "x$LLVM_CONFIG" != xllvm-config; then
727        AC_MSG_ERROR([llvm-config not found in $PATH.])
728    fi
729
730    llvm_components="jit mcjit engine nativecodegen native"
731    unset LLVM_CFLAGS
732    for flag in $("$LLVM_CONFIG" --cxxflags); do
733      if echo "${flag}" | grep -q '^-@<:@ID@:>@'; then
734        if test "${flag}" != "-D_DEBUG" ; then
735          if test "${LLVM_CFLAGS}" != "" ; then
736            LLVM_CFLAGS="${LLVM_CFLAGS} "
737          fi
738          LLVM_CFLAGS="${LLVM_CFLAGS}${flag}"
739        fi
740      fi
741    done
742    llvm_version=$("${LLVM_CONFIG}" --version | sed 's/\.//; s/svn.*//')
743    LLVM_CFLAGS="${LLVM_CFLAGS} -DSHARK_LLVM_VERSION=${llvm_version}"
744
745    unset LLVM_LDFLAGS
746    for flag in $("${LLVM_CONFIG}" --ldflags); do
747      if echo "${flag}" | grep -q '^-L'; then
748        if test "${LLVM_LDFLAGS}" != ""; then
749          LLVM_LDFLAGS="${LLVM_LDFLAGS} "
750        fi
751        LLVM_LDFLAGS="${LLVM_LDFLAGS}${flag}"
752      fi
753    done
754
755    unset LLVM_LIBS
756    for flag in $("${LLVM_CONFIG}" --libs ${llvm_components}); do
757      if echo "${flag}" | grep -q '^-l'; then
758        if test "${LLVM_LIBS}" != ""; then
759          LLVM_LIBS="${LLVM_LIBS} "
760        fi
761        LLVM_LIBS="${LLVM_LIBS}${flag}"
762      fi
763    done
764
765    AC_SUBST(LLVM_CFLAGS)
766    AC_SUBST(LLVM_LDFLAGS)
767    AC_SUBST(LLVM_LIBS)
768fi
769
770# libCrun is the c++ runtime-library with SunStudio (roughly the equivalent of gcc's libstdc++.so)
771if test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$LIBCXX" = x; then
772    LIBCXX="/usr/lib${OPENJDK_TARGET_CPU_ISADIR}/libCrun.so.1"
773fi
774
775# TODO better (platform agnostic) test
776if test "x$OPENJDK_TARGET_OS" = xmacosx && test "x$LIBCXX" = x && test "x$GCC" = xyes; then
777    LIBCXX="-lstdc++"
778fi
779
780AC_SUBST(LIBCXX)
781
782])
783