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