libraries.m4 revision 1236:bebfcf0b68ea
1234370Sjasone#
2234370Sjasone# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3234370Sjasone# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4234370Sjasone#
5234370Sjasone# This code is free software; you can redistribute it and/or modify it
6286866Sjasone# under the terms of the GNU General Public License version 2 only, as
7286866Sjasone# published by the Free Software Foundation.  Oracle designates this
8234370Sjasone# particular file as subject to the "Classpath" exception as provided
9234370Sjasone# by Oracle in the LICENSE file that accompanied this code.
10234370Sjasone#
11262521Sjasone# This code is distributed in the hope that it will be useful, but WITHOUT
12262521Sjasone# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13262521Sjasone# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14262521Sjasone# version 2 for more details (a copy is included in the LICENSE file that
15262521Sjasone# accompanied this code).
16234543Sjasone#
17234370Sjasone# You should have received a copy of the GNU General Public License version
18234370Sjasone# 2 along with this work; if not, write to the Free Software Foundation,
19234370Sjasone# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20234370Sjasone#
21234370Sjasone# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22234370Sjasone# or visit www.oracle.com if you need additional information or have any
23234370Sjasone# questions.
24234370Sjasone#
25234370Sjasone
26234370SjasoneAC_DEFUN_ONCE([LIB_SETUP_INIT],
27234370Sjasone[
28234370Sjasone
29234370Sjasone  ###############################################################################
30234370Sjasone  #
31234370Sjasone  # OS specific settings that we never will need to probe.
32234370Sjasone  #
33234370Sjasone  if test "x$OPENJDK_TARGET_OS" = xlinux; then
34234370Sjasone    AC_MSG_CHECKING([what is not needed on Linux?])
35234370Sjasone    PULSE_NOT_NEEDED=yes
36286866Sjasone    AC_MSG_RESULT([pulse])
37234370Sjasone  fi
38234370Sjasone
39234370Sjasone  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
40234370Sjasone    AC_MSG_CHECKING([what is not needed on Solaris?])
41235238Sjasone    ALSA_NOT_NEEDED=yes
42286866Sjasone    PULSE_NOT_NEEDED=yes
43286866Sjasone    AC_MSG_RESULT([alsa pulse])
44286866Sjasone  fi
45286866Sjasone
46286866Sjasone  if test "x$OPENJDK_TARGET_OS" = xaix; then
47286866Sjasone    AC_MSG_CHECKING([what is not needed on AIX?])
48235238Sjasone    ALSA_NOT_NEEDED=yes
49235238Sjasone    PULSE_NOT_NEEDED=yes
50235238Sjasone    AC_MSG_RESULT([alsa pulse])
51235238Sjasone  fi
52235238Sjasone
53235238Sjasone
54235238Sjasone  if test "x$OPENJDK_TARGET_OS" = xwindows; then
55234370Sjasone    AC_MSG_CHECKING([what is not needed on Windows?])
56234370Sjasone    CUPS_NOT_NEEDED=yes
57234370Sjasone    ALSA_NOT_NEEDED=yes
58234370Sjasone    PULSE_NOT_NEEDED=yes
59234370Sjasone    X11_NOT_NEEDED=yes
60234370Sjasone    AC_MSG_RESULT([alsa cups pulse x11])
61234370Sjasone  fi
62234370Sjasone
63234370Sjasone  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
64234370Sjasone    AC_MSG_CHECKING([what is not needed on MacOSX?])
65234370Sjasone    ALSA_NOT_NEEDED=yes
66234370Sjasone    PULSE_NOT_NEEDED=yes
67234370Sjasone    X11_NOT_NEEDED=yes
68234370Sjasone    AC_MSG_RESULT([alsa pulse x11])
69234370Sjasone  fi
70234370Sjasone
71234370Sjasone  if test "x$OPENJDK_TARGET_OS" = xbsd; then
72234370Sjasone    AC_MSG_CHECKING([what is not needed on bsd?])
73234370Sjasone    ALSA_NOT_NEEDED=yes
74286866Sjasone    AC_MSG_RESULT([alsa])
75286866Sjasone  fi
76286866Sjasone
77234370Sjasone  if test "x$OPENJDK" = "xfalse"; then
78234370Sjasone    FREETYPE_NOT_NEEDED=yes
79234370Sjasone  fi
80234370Sjasone
81286866Sjasone  if test "x$SUPPORT_HEADFUL" = xno; then
82286866Sjasone    X11_NOT_NEEDED=yes
83286866Sjasone  fi
84286866Sjasone])
85286866Sjasone
86286866SjasoneAC_DEFUN_ONCE([LIB_SETUP_X11],
87234370Sjasone[
88286866Sjasone
89286866Sjasone  ###############################################################################
90286866Sjasone  #
91234370Sjasone  # Check for X Windows
92234370Sjasone  #
93288090Sjasone
94288090Sjasone  if test "x$X11_NOT_NEEDED" = xyes; then
95234370Sjasone    if test "x${with_x}" != x; then
96286866Sjasone      AC_MSG_WARN([X11 is not used, so --with-x is ignored])
97288090Sjasone    fi
98234370Sjasone    X_CFLAGS=
99286866Sjasone    X_LIBS=
100286866Sjasone  else
101286866Sjasone    # Check if the user has specified sysroot, but not --x-includes or --x-libraries.
102286866Sjasone    # Make a simple check for the libraries at the sysroot, and setup --x-includes and
103286866Sjasone    # --x-libraries for the sysroot, if that seems to be correct.
104286866Sjasone    if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
105234370Sjasone      if test "x$SYSROOT" != "x"; then
106286866Sjasone        if test "x$x_includes" = xNONE; then
107286866Sjasone          if test -f "$SYSROOT/usr/X11R6/include/X11/Xlib.h"; then
108286866Sjasone            x_includes="$SYSROOT/usr/X11R6/include"
109286866Sjasone          elif test -f "$SYSROOT/usr/include/X11/Xlib.h"; then
110286866Sjasone            x_includes="$SYSROOT/usr/include"
111286866Sjasone          fi
112286866Sjasone        fi
113286866Sjasone        if test "x$x_libraries" = xNONE; then
114286866Sjasone          if test -f "$SYSROOT/usr/X11R6/lib/libX11.so"; then
115286866Sjasone            x_libraries="$SYSROOT/usr/X11R6/lib"
116286866Sjasone          elif test "$SYSROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
117234370Sjasone            x_libraries="$SYSROOT/usr/lib64"
118286866Sjasone          elif test -f "$SYSROOT/usr/lib/libX11.so"; then
119234370Sjasone            x_libraries="$SYSROOT/usr/lib"
120286866Sjasone          fi
121286866Sjasone        fi
122286866Sjasone      fi
123286866Sjasone    fi
124286866Sjasone
125286866Sjasone    # Now let autoconf do it's magic
126286866Sjasone    AC_PATH_X
127286866Sjasone    AC_PATH_XTRA
128286866Sjasone
129286866Sjasone    # AC_PATH_XTRA creates X_LIBS and sometimes adds -R flags. When cross compiling
130286866Sjasone    # this doesn't make sense so we remove it.
131286866Sjasone    if test "x$COMPILE_TYPE" = xcross; then
132286866Sjasone      X_LIBS=`$ECHO $X_LIBS | $SED 's/-R \{0,1\}[[^ ]]*//g'`
133286866Sjasone    fi
134286866Sjasone
135286866Sjasone    if test "x$no_x" = xyes; then
136286866Sjasone      HELP_MSG_MISSING_DEPENDENCY([x11])
137234370Sjasone      AC_MSG_ERROR([Could not find X11 libraries. $HELP_MSG])
138286866Sjasone    fi
139234370Sjasone
140286866Sjasone    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
141286866Sjasone      OPENWIN_HOME="/usr/openwin"
142234370Sjasone      X_CFLAGS="-I$SYSROOT$OPENWIN_HOME/include -I$SYSROOT$OPENWIN_HOME/include/X11/extensions"
143234370Sjasone      X_LIBS="-L$SYSROOT$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
144235238Sjasone          -L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
145286866Sjasone          -R$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
146235238Sjasone          -R$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR"
147286866Sjasone    fi
148286866Sjasone
149286866Sjasone    AC_LANG_PUSH(C)
150286866Sjasone    OLD_CFLAGS="$CFLAGS"
151235238Sjasone    CFLAGS="$CFLAGS $SYSROOT_CFLAGS $X_CFLAGS"
152286866Sjasone
153235238Sjasone    # Need to include Xlib.h and Xutil.h to avoid "present but cannot be compiled" warnings on Solaris 10
154235238Sjasone    AC_CHECK_HEADERS([X11/extensions/shape.h X11/extensions/Xrender.h X11/extensions/XTest.h X11/Intrinsic.h],
155235238Sjasone        [X11_HEADERS_OK=yes],
156286866Sjasone        [X11_HEADERS_OK=no; break],
157286866Sjasone        [
158286866Sjasone          # include <X11/Xlib.h>
159286866Sjasone          # include <X11/Xutil.h>
160286866Sjasone        ]
161286866Sjasone    )
162286866Sjasone
163286866Sjasone    if test "x$X11_HEADERS_OK" = xno; then
164286866Sjasone      HELP_MSG_MISSING_DEPENDENCY([x11])
165234370Sjasone      AC_MSG_ERROR([Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). $HELP_MSG])
166234370Sjasone    fi
167234370Sjasone
168286866Sjasone    # If XLinearGradient isn't available in Xrender.h, signal that it needs to be
169286866Sjasone    # defined in libawt_xawt.
170234370Sjasone    AC_MSG_CHECKING([if XlinearGradient is defined in Xrender.h])
171286866Sjasone    AC_COMPILE_IFELSE(
172286866Sjasone        [AC_LANG_PROGRAM([[#include <X11/extensions/Xrender.h>]],
173286866Sjasone            [[XLinearGradient x;]])],
174286866Sjasone        [AC_MSG_RESULT([yes])],
175286866Sjasone        [AC_MSG_RESULT([no])
176286866Sjasone         X_CFLAGS="$X_CFLAGS -DSOLARIS10_NO_XRENDER_STRUCTS"])
177286866Sjasone
178286866Sjasone    CFLAGS="$OLD_CFLAGS"
179286866Sjasone    AC_LANG_POP(C)
180286866Sjasone  fi # X11_NOT_NEEDED
181286866Sjasone
182234370Sjasone  AC_SUBST(X_CFLAGS)
183286866Sjasone  AC_SUBST(X_LIBS)
184286866Sjasone])
185234370Sjasone
186286866SjasoneAC_DEFUN_ONCE([LIB_SETUP_CUPS],
187261071Sjasone[
188286866Sjasone
189286866Sjasone  ###############################################################################
190234370Sjasone  #
191286866Sjasone  # The common unix printing system cups is used to print from java.
192286866Sjasone  #
193286866Sjasone  AC_ARG_WITH(cups, [AS_HELP_STRING([--with-cups],
194286866Sjasone      [specify prefix directory for the cups package
195286866Sjasone      (expecting the headers under PATH/include)])])
196234370Sjasone  AC_ARG_WITH(cups-include, [AS_HELP_STRING([--with-cups-include],
197286866Sjasone      [specify directory for the cups include files])])
198286866Sjasone
199286866Sjasone  if test "x$CUPS_NOT_NEEDED" = xyes; then
200234370Sjasone    if test "x${with_cups}" != x || test "x${with_cups_include}" != x; then
201286866Sjasone      AC_MSG_WARN([cups not used, so --with-cups is ignored])
202234370Sjasone    fi
203286866Sjasone    CUPS_CFLAGS=
204286866Sjasone  else
205286866Sjasone    CUPS_FOUND=no
206286866Sjasone
207286866Sjasone    if test "x${with_cups}" = xno || test "x${with_cups_include}" = xno; then
208286866Sjasone      AC_MSG_ERROR([It is not possible to disable the use of cups. Remove the --without-cups option.])
209286866Sjasone    fi
210234370Sjasone
211234370Sjasone    if test "x${with_cups}" != x; then
212234370Sjasone      CUPS_CFLAGS="-I${with_cups}/include"
213286866Sjasone      CUPS_FOUND=yes
214235238Sjasone    fi
215235238Sjasone    if test "x${with_cups_include}" != x; then
216235238Sjasone      CUPS_CFLAGS="-I${with_cups_include}"
217235238Sjasone      CUPS_FOUND=yes
218235238Sjasone    fi
219286866Sjasone    if test "x$CUPS_FOUND" = xno; then
220286866Sjasone      BDEPS_CHECK_MODULE(CUPS, cups, xxx, [CUPS_FOUND=yes])
221286866Sjasone    fi
222286866Sjasone    if test "x$CUPS_FOUND" = xno; then
223286866Sjasone      # Are the cups headers installed in the default /usr/include location?
224286866Sjasone      AC_CHECK_HEADERS([cups/cups.h cups/ppd.h],
225286866Sjasone          [
226286866Sjasone            CUPS_FOUND=yes
227286866Sjasone            CUPS_CFLAGS=
228286866Sjasone            DEFAULT_CUPS=yes
229286866Sjasone          ]
230286866Sjasone      )
231286866Sjasone    fi
232286866Sjasone    if test "x$CUPS_FOUND" = xno; then
233286866Sjasone      # Getting nervous now? Lets poke around for standard Solaris third-party
234286866Sjasone      # package installation locations.
235286866Sjasone      AC_MSG_CHECKING([for cups headers])
236286866Sjasone      if test -s $SYSROOT/opt/sfw/cups/include/cups/cups.h; then
237286866Sjasone        # An SFW package seems to be installed!
238286866Sjasone        CUPS_FOUND=yes
239234370Sjasone        CUPS_CFLAGS="-I$SYSROOT/opt/sfw/cups/include"
240286866Sjasone      elif test -s $SYSROOT/opt/csw/include/cups/cups.h; then
241234370Sjasone        # A CSW package seems to be installed!
242234370Sjasone        CUPS_FOUND=yes
243234370Sjasone        CUPS_CFLAGS="-I$SYSROOT/opt/csw/include"
244234370Sjasone      fi
245234370Sjasone      AC_MSG_RESULT([$CUPS_FOUND])
246234370Sjasone    fi
247234370Sjasone    if test "x$CUPS_FOUND" = xno; then
248286866Sjasone      HELP_MSG_MISSING_DEPENDENCY([cups])
249234370Sjasone      AC_MSG_ERROR([Could not find cups! $HELP_MSG ])
250234370Sjasone    fi
251234370Sjasone  fi
252234543Sjasone
253234370Sjasone  AC_SUBST(CUPS_CFLAGS)
254234370Sjasone
255261071Sjasone])
256261071Sjasone
257261071SjasoneAC_DEFUN([LIB_BUILD_FREETYPE],
258261071Sjasone[
259261071Sjasone  FREETYPE_SRC_PATH="$1"
260261071Sjasone  BUILD_FREETYPE=yes
261234370Sjasone
262286866Sjasone  # Check if the freetype sources are acessible..
263286866Sjasone  if ! test -d $FREETYPE_SRC_PATH; then
264286866Sjasone    AC_MSG_WARN([--with-freetype-src specified, but can't find path "$FREETYPE_SRC_PATH" - ignoring --with-freetype-src])
265286866Sjasone    BUILD_FREETYPE=no
266286866Sjasone  fi
267286866Sjasone  # ..and contain a vc2010 project file
268234370Sjasone  vcxproj_path="$FREETYPE_SRC_PATH/builds/windows/vc2010/freetype.vcxproj"
269234370Sjasone  if test "x$BUILD_FREETYPE" = xyes && ! test -s $vcxproj_path; then
270234370Sjasone    AC_MSG_WARN([Can't find project file $vcxproj_path (you may try a newer freetype version) - ignoring --with-freetype-src])
271234370Sjasone    BUILD_FREETYPE=no
272234370Sjasone  fi
273234370Sjasone  # Now check if configure found a version of 'msbuild.exe'
274234370Sjasone  if test "x$BUILD_FREETYPE" = xyes && test "x$MSBUILD" == x ; then
275234370Sjasone    AC_MSG_WARN([Can not find an msbuild.exe executable (you may try to install .NET 4.0) - ignoring --with-freetype-src])
276234370Sjasone    BUILD_FREETYPE=no
277234370Sjasone  fi
278286866Sjasone
279286866Sjasone  # Ready to go..
280234370Sjasone  if test "x$BUILD_FREETYPE" = xyes; then
281286866Sjasone
282234370Sjasone    # msbuild requires trailing slashes for output directories
283286866Sjasone    freetype_lib_path="$FREETYPE_SRC_PATH/lib$OPENJDK_TARGET_CPU_BITS/"
284299587Sjasone    freetype_lib_path_unix="$freetype_lib_path"
285286866Sjasone    freetype_obj_path="$FREETYPE_SRC_PATH/obj$OPENJDK_TARGET_CPU_BITS/"
286286866Sjasone    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(vcxproj_path)
287234370Sjasone    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(freetype_lib_path)
288286866Sjasone    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(freetype_obj_path)
289286866Sjasone    if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
290261071Sjasone      freetype_platform=x64
291286866Sjasone    else
292261071Sjasone      freetype_platform=win32
293286866Sjasone    fi
294261071Sjasone
295261071Sjasone    # The original freetype project file is for VS 2010 (i.e. 'v100'),
296299587Sjasone    # so we have to adapt the toolset if building with any other toolsed (i.e. SDK).
297286866Sjasone    # Currently 'PLATFORM_TOOLSET' is set in 'TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT'/
298261071Sjasone    # 'TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT' in toolchain_windows.m4
299299587Sjasone    AC_MSG_NOTICE([Trying to compile freetype sources with PlatformToolset=$PLATFORM_TOOLSET to $freetype_lib_path_unix ...])
300299587Sjasone
301299587Sjasone    # First we try to build the freetype.dll
302299587Sjasone    $ECHO -e "@echo off\n"\
303286866Sjasone	     "$MSBUILD $vcxproj_path "\
304299587Sjasone		       "/p:PlatformToolset=$PLATFORM_TOOLSET "\
305286866Sjasone		       "/p:Configuration=\"Release Multithreaded\" "\
306299587Sjasone		       "/p:Platform=$freetype_platform "\
307299587Sjasone		       "/p:ConfigurationType=DynamicLibrary "\
308299587Sjasone		       "/p:TargetName=freetype "\
309286866Sjasone		       "/p:OutDir=\"$freetype_lib_path\" "\
310299587Sjasone		       "/p:IntDir=\"$freetype_obj_path\" > freetype.log" > freetype.bat
311299587Sjasone    cmd /c freetype.bat
312299587Sjasone
313299587Sjasone    if test -s "$freetype_lib_path_unix/freetype.dll"; then
314299587Sjasone      # If that succeeds we also build freetype.lib
315299587Sjasone      $ECHO -e "@echo off\n"\
316234370Sjasone	       "$MSBUILD $vcxproj_path "\
317234370Sjasone			 "/p:PlatformToolset=$PLATFORM_TOOLSET "\
318299587Sjasone			 "/p:Configuration=\"Release Multithreaded\" "\
319299587Sjasone			 "/p:Platform=$freetype_platform "\
320299587Sjasone			 "/p:ConfigurationType=StaticLibrary "\
321299587Sjasone			 "/p:TargetName=freetype "\
322299587Sjasone			 "/p:OutDir=\"$freetype_lib_path\" "\
323286866Sjasone			 "/p:IntDir=\"$freetype_obj_path\" >> freetype.log" > freetype.bat
324234370Sjasone      cmd /c freetype.bat
325234370Sjasone
326234370Sjasone      if test -s "$freetype_lib_path_unix/freetype.lib"; then
327234370Sjasone	# Once we build both, lib and dll, set freetype lib and include path appropriately
328234370Sjasone	POTENTIAL_FREETYPE_INCLUDE_PATH="$FREETYPE_SRC_PATH/include"
329234370Sjasone	POTENTIAL_FREETYPE_LIB_PATH="$freetype_lib_path_unix"
330286866Sjasone	AC_MSG_NOTICE([Compiling freetype sources succeeded! (see freetype.log for build results)])
331286866Sjasone      else
332286866Sjasone	BUILD_FREETYPE=no
333299587Sjasone      fi
334299587Sjasone    else
335299587Sjasone      BUILD_FREETYPE=no
336299587Sjasone    fi
337299587Sjasone  fi
338286866Sjasone])
339286866Sjasone
340288090SjasoneAC_DEFUN([LIB_CHECK_POTENTIAL_FREETYPE],
341288090Sjasone[
342299587Sjasone  POTENTIAL_FREETYPE_INCLUDE_PATH="$1"
343288090Sjasone  POTENTIAL_FREETYPE_LIB_PATH="$2"
344286866Sjasone  METHOD="$3"
345288090Sjasone
346288090Sjasone  # Let's start with an optimistic view of the world :-)
347286866Sjasone  FOUND_FREETYPE=yes
348234370Sjasone
349234370Sjasone  # First look for the canonical freetype main include file ft2build.h.
350234370Sjasone  if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
351286866Sjasone    # Oh no! Let's try in the freetype2 directory. This is needed at least at Mac OS X Yosemite.
352286866Sjasone    POTENTIAL_FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH/freetype2"
353235238Sjasone    if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
354235238Sjasone      # Fail.
355286866Sjasone      FOUND_FREETYPE=no
356286866Sjasone    fi
357286866Sjasone  fi
358286866Sjasone
359286866Sjasone  if test "x$FOUND_FREETYPE" = xyes; then
360286866Sjasone    # Include file found, let's continue the sanity check.
361286866Sjasone    AC_MSG_NOTICE([Found freetype include files at $POTENTIAL_FREETYPE_INCLUDE_PATH using $METHOD])
362235238Sjasone
363235238Sjasone    # Reset to default value
364286866Sjasone    FREETYPE_BASE_NAME=freetype
365286866Sjasone    FREETYPE_LIB_NAME="${LIBRARY_PREFIX}${FREETYPE_BASE_NAME}${SHARED_LIBRARY_SUFFIX}"
366234370Sjasone    if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME"; then
367286866Sjasone      if test "x$OPENJDK_TARGET_OS" = xmacosx \
368261071Sjasone          && test -s "$POTENTIAL_FREETYPE_LIB_PATH/${LIBRARY_PREFIX}freetype.6${SHARED_LIBRARY_SUFFIX}"; then
369286866Sjasone        # On Mac OS X Yosemite, the symlink from libfreetype.dylib to libfreetype.6.dylib disappeared. Check
370286866Sjasone        # for the .6 version explicitly.
371286866Sjasone        FREETYPE_BASE_NAME=freetype.6
372261071Sjasone        FREETYPE_LIB_NAME="${LIBRARY_PREFIX}${FREETYPE_BASE_NAME}${SHARED_LIBRARY_SUFFIX}"
373286866Sjasone        AC_MSG_NOTICE([Compensating for missing symlink by using version 6 explicitly])
374286866Sjasone      else
375234370Sjasone        AC_MSG_NOTICE([Could not find $POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME. Ignoring location.])
376286866Sjasone        FOUND_FREETYPE=no
377286866Sjasone      fi
378286866Sjasone    else
379286866Sjasone      if test "x$OPENJDK_TARGET_OS" = xwindows; then
380286866Sjasone        # On Windows, we will need both .lib and .dll file.
381234370Sjasone        if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/${FREETYPE_BASE_NAME}.lib"; then
382234370Sjasone          AC_MSG_NOTICE([Could not find $POTENTIAL_FREETYPE_LIB_PATH/${FREETYPE_BASE_NAME}.lib. Ignoring location.])
383286866Sjasone          FOUND_FREETYPE=no
384286866Sjasone        fi
385286866Sjasone      elif test "x$OPENJDK_TARGET_OS" = xsolaris \
386286866Sjasone          && test -s "$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR/$FREETYPE_LIB_NAME"; then
387299587Sjasone        # Found lib in isa dir, use that instead.
388286866Sjasone        POTENTIAL_FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR"
389286866Sjasone        AC_MSG_NOTICE([Rewriting to use $POTENTIAL_FREETYPE_LIB_PATH instead])
390286866Sjasone      fi
391286866Sjasone    fi
392286866Sjasone  fi
393286866Sjasone
394286866Sjasone  if test "x$FOUND_FREETYPE" = xyes; then
395286866Sjasone    BASIC_FIXUP_PATH(POTENTIAL_FREETYPE_INCLUDE_PATH)
396286866Sjasone    BASIC_FIXUP_PATH(POTENTIAL_FREETYPE_LIB_PATH)
397286866Sjasone
398234370Sjasone    FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH"
399234370Sjasone    AC_MSG_CHECKING([for freetype includes])
400286866Sjasone    AC_MSG_RESULT([$FREETYPE_INCLUDE_PATH])
401299587Sjasone    FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH"
402234370Sjasone    AC_MSG_CHECKING([for freetype libraries])
403234370Sjasone    AC_MSG_RESULT([$FREETYPE_LIB_PATH])
404234370Sjasone  fi
405234370Sjasone])
406234370Sjasone
407299587SjasoneAC_DEFUN_ONCE([LIB_SETUP_FREETYPE],
408234370Sjasone[
409234370Sjasone
410286866Sjasone  ###############################################################################
411299587Sjasone  #
412234370Sjasone  # The ubiquitous freetype library is used to render fonts.
413234370Sjasone  #
414234370Sjasone  AC_ARG_WITH(freetype, [AS_HELP_STRING([--with-freetype],
415234370Sjasone      [specify prefix directory for the freetype package
416234370Sjasone      (expecting the libraries under PATH/lib and the headers under PATH/include)])])
417299587Sjasone  AC_ARG_WITH(freetype-include, [AS_HELP_STRING([--with-freetype-include],
418234370Sjasone      [specify directory for the freetype include files])])
419234370Sjasone  AC_ARG_WITH(freetype-lib, [AS_HELP_STRING([--with-freetype-lib],
420288090Sjasone      [specify directory for the freetype library])])
421299587Sjasone  AC_ARG_WITH(freetype-src, [AS_HELP_STRING([--with-freetype-src],
422288090Sjasone      [specify directory with freetype sources to automatically build the library (experimental, Windows-only)])])
423288090Sjasone  AC_ARG_ENABLE(freetype-bundling, [AS_HELP_STRING([--disable-freetype-bundling],
424288090Sjasone      [disable bundling of the freetype library with the build result @<:@enabled on Windows or when using --with-freetype, disabled otherwise@:>@])])
425288090Sjasone
426288090Sjasone  # Need to specify explicitly since it needs to be overridden on some versions of macosx
427288090Sjasone  FREETYPE_BASE_NAME=freetype
428299587Sjasone  FREETYPE_CFLAGS=
429288090Sjasone  FREETYPE_LIBS=
430288090Sjasone  FREETYPE_BUNDLE_LIB_PATH=
431286866Sjasone
432286866Sjasone  if test "x$FREETYPE_NOT_NEEDED" = xyes; then
433286866Sjasone    if test "x$with_freetype" != x || test "x$with_freetype_include" != x || test "x$with_freetype_lib" != x || test "x$with_freetype_src" != x; then
434234370Sjasone      AC_MSG_WARN([freetype not used, so --with-freetype is ignored])
435286866Sjasone    fi
436234370Sjasone    if test "x$enable_freetype_bundling" != x; then
437234370Sjasone      AC_MSG_WARN([freetype not used, so --enable-freetype-bundling is ignored])
438234370Sjasone    fi
439286866Sjasone  else
440296221Sjasone    # freetype is needed to build; go get it!
441286866Sjasone
442286866Sjasone    BUNDLE_FREETYPE="$enable_freetype_bundling"
443286866Sjasone
444286866Sjasone    if  test "x$with_freetype_src" != x; then
445286866Sjasone      if test "x$OPENJDK_TARGET_OS" = xwindows; then
446296221Sjasone        # Try to build freetype if --with-freetype-src was given on Windows
447235238Sjasone        LIB_BUILD_FREETYPE([$with_freetype_src])
448234370Sjasone        if test "x$BUILD_FREETYPE" = xyes; then
449296221Sjasone          # Okay, we built it. Check that it works.
450286866Sjasone          LIB_CHECK_POTENTIAL_FREETYPE($POTENTIAL_FREETYPE_INCLUDE_PATH, $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype-src])
451286866Sjasone          if test "x$FOUND_FREETYPE" != xyes; then
452286866Sjasone            AC_MSG_ERROR([Can not use the built freetype at location given by --with-freetype-src])
453286866Sjasone          fi
454234370Sjasone        else
455286866Sjasone          AC_MSG_NOTICE([User specified --with-freetype-src but building freetype failed. (see freetype.log for build results)])
456286866Sjasone          AC_MSG_ERROR([Consider building freetype manually and using --with-freetype instead.])
457286866Sjasone        fi
458234370Sjasone      else
459234370Sjasone        AC_MSG_WARN([--with-freetype-src is currently only supported on Windows - ignoring])
460234370Sjasone      fi
461286866Sjasone    fi
462288090Sjasone
463234370Sjasone    if test "x$with_freetype" != x || test "x$with_freetype_include" != x || test "x$with_freetype_lib" != x; then
464286866Sjasone      # User has specified settings
465286866Sjasone
466286866Sjasone      if test "x$BUNDLE_FREETYPE" = x; then
467234370Sjasone        # If not specified, default is to bundle freetype
468286866Sjasone        BUNDLE_FREETYPE=yes
469286866Sjasone      fi
470288090Sjasone
471288090Sjasone      if test "x$with_freetype" != x; then
472286866Sjasone        POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype/include"
473286866Sjasone        POTENTIAL_FREETYPE_LIB_PATH="$with_freetype/lib"
474286866Sjasone      fi
475286866Sjasone
476286866Sjasone      # Allow --with-freetype-lib and --with-freetype-include to override
477286866Sjasone      if test "x$with_freetype_include" != x; then
478286866Sjasone        POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype_include"
479286866Sjasone      fi
480286866Sjasone      if test "x$with_freetype_lib" != x; then
481286866Sjasone        POTENTIAL_FREETYPE_LIB_PATH="$with_freetype_lib"
482286866Sjasone      fi
483299587Sjasone
484286866Sjasone      if test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" != x && test "x$POTENTIAL_FREETYPE_LIB_PATH" != x; then
485286866Sjasone        # Okay, we got it. Check that it works.
486234370Sjasone        LIB_CHECK_POTENTIAL_FREETYPE($POTENTIAL_FREETYPE_INCLUDE_PATH, $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype])
487234370Sjasone        if test "x$FOUND_FREETYPE" != xyes; then
488299587Sjasone          AC_MSG_ERROR([Can not find or use freetype at location given by --with-freetype])
489234370Sjasone        fi
490286866Sjasone      else
491299587Sjasone        # User specified only one of lib or include. This is an error.
492286866Sjasone        if test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" = x ; then
493299587Sjasone          AC_MSG_NOTICE([User specified --with-freetype-lib but not --with-freetype-include])
494234370Sjasone          AC_MSG_ERROR([Need both freetype lib and include paths. Consider using --with-freetype instead.])
495234370Sjasone        else
496286866Sjasone          AC_MSG_NOTICE([User specified --with-freetype-include but not --with-freetype-lib])
497286866Sjasone          AC_MSG_ERROR([Need both freetype lib and include paths. Consider using --with-freetype instead.])
498288090Sjasone        fi
499288090Sjasone      fi
500234370Sjasone    else
501288090Sjasone      # User did not specify settings, but we need freetype. Try to locate it.
502234370Sjasone
503234370Sjasone      if test "x$BUNDLE_FREETYPE" = x; then
504286866Sjasone        # If not specified, default is to bundle freetype only on windows
505234370Sjasone        if test "x$OPENJDK_TARGET_OS" = xwindows; then
506288090Sjasone          BUNDLE_FREETYPE=yes
507299587Sjasone        else
508286866Sjasone          BUNDLE_FREETYPE=no
509234370Sjasone        fi
510288090Sjasone      fi
511286866Sjasone
512286866Sjasone      if test "x$FOUND_FREETYPE" != xyes; then
513286866Sjasone        # Check builddeps
514286866Sjasone        BDEPS_CHECK_MODULE(FREETYPE, freetype2, xxx, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
515234370Sjasone        # BDEPS_CHECK_MODULE will set FREETYPE_CFLAGS and _LIBS, but we don't get a lib path for bundling.
516301718Sjasone        if test "x$FOUND_FREETYPE" = xyes; then
517286866Sjasone          if test "x$BUNDLE_FREETYPE" = xyes; then
518234370Sjasone            AC_MSG_NOTICE([Found freetype using builddeps, but ignoring since we can not bundle that])
519286866Sjasone            FOUND_FREETYPE=no
520234370Sjasone          else
521288090Sjasone            AC_MSG_CHECKING([for freetype])
522288090Sjasone            AC_MSG_RESULT([yes (using builddeps)])
523288090Sjasone          fi
524288090Sjasone        fi
525299587Sjasone      fi
526286866Sjasone
527299587Sjasone      # If we have a sysroot, assume that's where we are supposed to look and skip pkg-config.
528288090Sjasone      if test "x$SYSROOT" = x; then
529288090Sjasone        if test "x$FOUND_FREETYPE" != xyes; then
530288090Sjasone          # Check modules using pkg-config, but only if we have it (ugly output results otherwise)
531234370Sjasone          if test "x$PKG_CONFIG" != x; then
532234370Sjasone            PKG_CHECK_MODULES(FREETYPE, freetype2, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
533286866Sjasone            if test "x$FOUND_FREETYPE" = xyes; then
534286866Sjasone              # On solaris, pkg_check adds -lz to freetype libs, which isn't necessary for us.
535234370Sjasone              FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's/-lz//g'`
536299587Sjasone              # 64-bit libs for Solaris x86 are installed in the amd64 subdirectory, change lib to lib/amd64
537234370Sjasone              if test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$OPENJDK_TARGET_CPU" = xx86_64; then
538234370Sjasone                FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's?/lib?/lib/amd64?g'`
539299587Sjasone              fi
540234370Sjasone              # BDEPS_CHECK_MODULE will set FREETYPE_CFLAGS and _LIBS, but we don't get a lib path for bundling.
541286866Sjasone              if test "x$BUNDLE_FREETYPE" = xyes; then
542286866Sjasone                AC_MSG_NOTICE([Found freetype using pkg-config, but ignoring since we can not bundle that])
543234370Sjasone                FOUND_FREETYPE=no
544234370Sjasone              else
545234370Sjasone                AC_MSG_CHECKING([for freetype])
546234370Sjasone                AC_MSG_RESULT([yes (using pkg-config)])
547234370Sjasone              fi
548            fi
549          fi
550        fi
551      fi
552
553      if test "x$FOUND_FREETYPE" != xyes; then
554        # Check in well-known locations
555        if test "x$OPENJDK_TARGET_OS" = xwindows; then
556          FREETYPE_BASE_DIR="$PROGRAMFILES/GnuWin32"
557          BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(FREETYPE_BASE_DIR)
558          LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
559          if test "x$FOUND_FREETYPE" != xyes; then
560            FREETYPE_BASE_DIR="$ProgramW6432/GnuWin32"
561            BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(FREETYPE_BASE_DIR)
562            LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
563          fi
564        else
565          FREETYPE_BASE_DIR="$SYSROOT/usr"
566          LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
567
568          if test "x$FOUND_FREETYPE" != xyes; then
569            FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
570            LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
571          fi
572
573          if test "x$FOUND_FREETYPE" != xyes; then
574            FREETYPE_BASE_DIR="$SYSROOT/usr/sfw"
575            LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
576          fi
577
578          if test "x$FOUND_FREETYPE" != xyes; then
579            FREETYPE_BASE_DIR="$SYSROOT/usr"
580            if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
581              LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/x86_64-linux-gnu], [well-known location])
582            else
583              LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
584              if test "x$FOUND_FREETYPE" != xyes; then
585                LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib32], [well-known location])
586              fi
587            fi
588          fi
589        fi
590      fi # end check in well-known locations
591
592      if test "x$FOUND_FREETYPE" != xyes; then
593        HELP_MSG_MISSING_DEPENDENCY([freetype])
594        AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
595      fi
596    fi # end user specified settings
597
598    # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
599    if test "x$FREETYPE_CFLAGS" = x; then
600      BASIC_FIXUP_PATH(FREETYPE_INCLUDE_PATH)
601      if test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype; then
602        FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
603      else
604        FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
605      fi
606    fi
607
608    if test "x$FREETYPE_LIBS" = x; then
609      BASIC_FIXUP_PATH(FREETYPE_LIB_PATH)
610      if test "x$OPENJDK_TARGET_OS" = xwindows; then
611        FREETYPE_LIBS="$FREETYPE_LIB_PATH/$FREETYPE_BASE_NAME.lib"
612      else
613        FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -l$FREETYPE_BASE_NAME"
614      fi
615    fi
616
617    # Try to compile it
618    AC_MSG_CHECKING([if we can compile and link with freetype])
619    AC_LANG_PUSH(C++)
620    PREV_CXXCFLAGS="$CXXFLAGS"
621    PREV_LIBS="$LIBS"
622    PREV_CXX="$CXX"
623    CXXFLAGS="$CXXFLAGS $FREETYPE_CFLAGS"
624    LIBS="$LIBS $FREETYPE_LIBS"
625    CXX="$FIXPATH $CXX"
626    AC_LINK_IFELSE([AC_LANG_SOURCE([[
627          #include<ft2build.h>
628          #include FT_FREETYPE_H
629          int main () {
630            FT_Init_FreeType(NULL);
631            return 0;
632          }
633        ]])],
634        [
635          AC_MSG_RESULT([yes])
636        ],
637        [
638          AC_MSG_RESULT([no])
639          AC_MSG_NOTICE([Could not compile and link with freetype. This might be a 32/64-bit mismatch.])
640          AC_MSG_NOTICE([Using FREETYPE_CFLAGS=$FREETYPE_CFLAGS and FREETYPE_LIBS=$FREETYPE_LIBS])
641
642          HELP_MSG_MISSING_DEPENDENCY([freetype])
643
644          AC_MSG_ERROR([Can not continue without freetype. $HELP_MSG])
645        ]
646    )
647    CXXCFLAGS="$PREV_CXXFLAGS"
648    LIBS="$PREV_LIBS"
649    CXX="$PREV_CXX"
650    AC_LANG_POP(C++)
651
652    AC_MSG_CHECKING([if we should bundle freetype])
653    if test "x$BUNDLE_FREETYPE" = xyes; then
654      FREETYPE_BUNDLE_LIB_PATH="$FREETYPE_LIB_PATH"
655    fi
656    AC_MSG_RESULT([$BUNDLE_FREETYPE])
657
658  fi # end freetype needed
659
660  AC_SUBST(FREETYPE_BUNDLE_LIB_PATH)
661  AC_SUBST(FREETYPE_CFLAGS)
662  AC_SUBST(FREETYPE_LIBS)
663])
664
665AC_DEFUN_ONCE([LIB_SETUP_ALSA],
666[
667
668  ###############################################################################
669  #
670  # Check for alsa headers and libraries. Used on Linux/GNU systems.
671  #
672  AC_ARG_WITH(alsa, [AS_HELP_STRING([--with-alsa],
673      [specify prefix directory for the alsa package
674      (expecting the libraries under PATH/lib and the headers under PATH/include)])])
675  AC_ARG_WITH(alsa-include, [AS_HELP_STRING([--with-alsa-include],
676      [specify directory for the alsa include files])])
677  AC_ARG_WITH(alsa-lib, [AS_HELP_STRING([--with-alsa-lib],
678      [specify directory for the alsa library])])
679
680  if test "x$ALSA_NOT_NEEDED" = xyes; then
681    if test "x${with_alsa}" != x || test "x${with_alsa_include}" != x || test "x${with_alsa_lib}" != x; then
682      AC_MSG_WARN([alsa not used, so --with-alsa is ignored])
683    fi
684    ALSA_CFLAGS=
685    ALSA_LIBS=
686  else
687    ALSA_FOUND=no
688
689    if test "x${with_alsa}" = xno || test "x${with_alsa_include}" = xno || test "x${with_alsa_lib}" = xno; then
690      AC_MSG_ERROR([It is not possible to disable the use of alsa. Remove the --without-alsa option.])
691    fi
692
693    if test "x${with_alsa}" != x; then
694      ALSA_LIBS="-L${with_alsa}/lib -lasound"
695      ALSA_CFLAGS="-I${with_alsa}/include"
696      ALSA_FOUND=yes
697    fi
698    if test "x${with_alsa_include}" != x; then
699      ALSA_CFLAGS="-I${with_alsa_include}"
700      ALSA_FOUND=yes
701    fi
702    if test "x${with_alsa_lib}" != x; then
703      ALSA_LIBS="-L${with_alsa_lib} -lasound"
704      ALSA_FOUND=yes
705    fi
706    if test "x$ALSA_FOUND" = xno; then
707      BDEPS_CHECK_MODULE(ALSA, alsa, xxx, [ALSA_FOUND=yes], [ALSA_FOUND=no])
708    fi
709    # Do not try pkg-config if we have a sysroot set.
710    if test "x$SYSROOT" = x; then
711      if test "x$ALSA_FOUND" = xno; then
712        PKG_CHECK_MODULES(ALSA, alsa, [ALSA_FOUND=yes], [ALSA_FOUND=no])
713      fi
714    fi
715    if test "x$ALSA_FOUND" = xno; then
716      AC_CHECK_HEADERS([alsa/asoundlib.h],
717          [
718            ALSA_FOUND=yes
719            ALSA_CFLAGS=-Iignoreme
720            ALSA_LIBS=-lasound
721            DEFAULT_ALSA=yes
722          ],
723          [ALSA_FOUND=no])
724    fi
725    if test "x$ALSA_FOUND" = xno; then
726      HELP_MSG_MISSING_DEPENDENCY([alsa])
727      AC_MSG_ERROR([Could not find alsa! $HELP_MSG ])
728    fi
729  fi
730
731  AC_SUBST(ALSA_CFLAGS)
732  AC_SUBST(ALSA_LIBS)
733])
734
735AC_DEFUN_ONCE([LIB_SETUP_MISC_LIBS],
736[
737
738  ###############################################################################
739  #
740  # Check for the jpeg library
741  #
742
743  AC_ARG_WITH(libjpeg, [AS_HELP_STRING([--with-libjpeg],
744      [use libjpeg from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
745
746  AC_MSG_CHECKING([for which libjpeg to use])
747
748  # default is bundled
749  DEFAULT_LIBJPEG=bundled
750
751  #
752  # if user didn't specify, use DEFAULT_LIBJPEG
753  #
754  if test "x${with_libjpeg}" = "x"; then
755    with_libjpeg=${DEFAULT_LIBJPEG}
756  fi
757
758  AC_MSG_RESULT(${with_libjpeg})
759
760  if test "x${with_libjpeg}" = "xbundled"; then
761    USE_EXTERNAL_LIBJPEG=false
762  elif test "x${with_libjpeg}" = "xsystem"; then
763    AC_CHECK_HEADER(jpeglib.h, [],
764        [ AC_MSG_ERROR([--with-libjpeg=system specified, but jpeglib.h not found!])])
765    AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, [],
766        [ AC_MSG_ERROR([--with-libjpeg=system specified, but no libjpeg found])])
767
768    USE_EXTERNAL_LIBJPEG=true
769  else
770    AC_MSG_ERROR([Invalid use of --with-libjpeg: ${with_libjpeg}, use 'system' or 'bundled'])
771  fi
772
773  AC_SUBST(USE_EXTERNAL_LIBJPEG)
774
775  ###############################################################################
776  #
777  # Check for the gif library
778  #
779
780  AC_ARG_WITH(giflib, [AS_HELP_STRING([--with-giflib],
781      [use giflib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
782
783
784  AC_MSG_CHECKING([for which giflib to use])
785
786  # default is bundled
787  DEFAULT_GIFLIB=bundled
788
789  #
790  # if user didn't specify, use DEFAULT_GIFLIB
791  #
792  if test "x${with_giflib}" = "x"; then
793    with_giflib=${DEFAULT_GIFLIB}
794  fi
795
796  AC_MSG_RESULT(${with_giflib})
797
798  if test "x${with_giflib}" = "xbundled"; then
799    USE_EXTERNAL_LIBGIF=false
800  elif test "x${with_giflib}" = "xsystem"; then
801    AC_CHECK_HEADER(gif_lib.h, [],
802        [ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])])
803    AC_CHECK_LIB(gif, DGifGetCode, [],
804        [ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])])
805
806    USE_EXTERNAL_LIBGIF=true
807  else
808    AC_MSG_ERROR([Invalid value of --with-giflib: ${with_giflib}, use 'system' or 'bundled'])
809  fi
810  AC_SUBST(USE_EXTERNAL_LIBGIF)
811
812  ###############################################################################
813  #
814  # Check for the lcms2 library
815  #
816
817  AC_ARG_WITH(lcms, [AS_HELP_STRING([--with-lcms],
818  	[use lcms2 from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
819
820  AC_MSG_CHECKING([for which lcms to use])
821
822  DEFAULT_LCMS=bundled
823
824  #
825  # If user didn't specify, use DEFAULT_LCMS
826  #
827  if test "x${with_lcms}" = "x"; then
828      with_lcms=${DEFAULT_LCMS}
829  fi
830
831  if test "x${with_lcms}" = "xbundled"; then
832    USE_EXTERNAL_LCMS=false
833    AC_MSG_RESULT([bundled])
834  elif test "x${with_lcms}" = "xsystem"; then
835    AC_MSG_RESULT([system])
836    PKG_CHECK_MODULES([LCMS], [lcms2], [LCMS_FOUND=yes], [LCMS_FOUND=no])
837    if test "x${LCMS_FOUND}" = "xyes"; then
838      USE_EXTERNAL_LCMS=true
839    else
840      AC_MSG_ERROR([--with-lcms=system specified, but no lcms found!])
841    fi
842  else
843    AC_MSG_ERROR([Invalid value for --with-lcms: ${with_lcms}, use 'system' or 'bundled'])
844  fi
845
846  AC_SUBST(USE_EXTERNAL_LCMS)
847
848  ###############################################################################
849  #
850  # Check for the png library
851  #
852
853  AC_ARG_WITH(libpng, [AS_HELP_STRING([--with-libpng],
854     [use libpng from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
855
856
857  AC_MSG_CHECKING([for which libpng to use])
858
859  # default is bundled
860  DEFAULT_LIBPNG=bundled
861
862  #
863  # if user didn't specify, use DEFAULT_LIBPNG
864  #
865  if test "x${with_libpng}" = "x"; then
866      with_libpng=${DEFAULT_LIBPNG}
867  fi
868
869  if test "x${with_libpng}" = "xbundled"; then
870      USE_EXTERNAL_LIBPNG=false
871      AC_MSG_RESULT([bundled])
872  elif test "x${with_libpng}" = "xsystem"; then
873      PKG_CHECK_MODULES(PNG, libpng,
874                   [ LIBPNG_FOUND=yes ],
875                   [ LIBPNG_FOUND=no ])
876      if test "x${LIBPNG_FOUND}" = "xyes"; then
877          USE_EXTERNAL_LIBPNG=true
878          AC_MSG_RESULT([system])
879      else
880          AC_MSG_RESULT([system not found])
881          AC_MSG_ERROR([--with-libpng=system specified, but no libpng found!])
882      fi
883  else
884      AC_MSG_ERROR([Invalid value of --with-libpng: ${with_libpng}, use 'system' or 'bundled'])
885  fi
886  AC_SUBST(USE_EXTERNAL_LIBPNG)
887
888  ###############################################################################
889  #
890  # Check for the zlib library
891  #
892
893  AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib],
894      [use zlib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
895
896  AC_CHECK_LIB(z, compress,
897      [ ZLIB_FOUND=yes ],
898      [ ZLIB_FOUND=no ])
899
900  AC_MSG_CHECKING([for which zlib to use])
901
902  DEFAULT_ZLIB=bundled
903  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
904    #
905    # On macosx default is system...on others default is
906    #
907    DEFAULT_ZLIB=system
908  fi
909
910  if test "x${ZLIB_FOUND}" != "xyes"; then
911    #
912    # If we don't find any system...set default to bundled
913    #
914    DEFAULT_ZLIB=bundled
915  fi
916
917  #
918  # If user didn't specify, use DEFAULT_ZLIB
919  #
920  if test "x${with_zlib}" = "x"; then
921    with_zlib=${DEFAULT_ZLIB}
922  fi
923
924  if test "x${with_zlib}" = "xbundled"; then
925    USE_EXTERNAL_LIBZ=false
926    AC_MSG_RESULT([bundled])
927  elif test "x${with_zlib}" = "xsystem"; then
928    if test "x${ZLIB_FOUND}" = "xyes"; then
929      USE_EXTERNAL_LIBZ=true
930      AC_MSG_RESULT([system])
931    else
932      AC_MSG_RESULT([system not found])
933      AC_MSG_ERROR([--with-zlib=system specified, but no zlib found!])
934    fi
935  else
936    AC_MSG_ERROR([Invalid value for --with-zlib: ${with_zlib}, use 'system' or 'bundled'])
937  fi
938
939  AC_SUBST(USE_EXTERNAL_LIBZ)
940
941  ###############################################################################
942  LIBZIP_CAN_USE_MMAP=true
943
944  AC_SUBST(LIBZIP_CAN_USE_MMAP)
945
946  ###############################################################################
947  #
948  # Check if altzone exists in time.h
949  #
950
951  AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [return (int)altzone;])],
952      [has_altzone=yes],
953      [has_altzone=no])
954  if test "x$has_altzone" = xyes; then
955    AC_DEFINE([HAVE_ALTZONE], 1, [Define if you have the external 'altzone' variable in time.h])
956  fi
957
958  ###############################################################################
959  #
960  # Check the maths library
961  #
962
963  AC_CHECK_LIB(m, cos, [],
964      [
965        AC_MSG_NOTICE([Maths library was not found])
966      ]
967  )
968  AC_SUBST(LIBM)
969
970  ###############################################################################
971  #
972  # Check for libdl.so
973
974  save_LIBS="$LIBS"
975  LIBS=""
976  AC_CHECK_LIB(dl,dlopen)
977  LIBDL="$LIBS"
978  AC_SUBST(LIBDL)
979  LIBS="$save_LIBS"
980])
981
982AC_DEFUN_ONCE([LIB_SETUP_STATIC_LINK_LIBSTDCPP],
983[
984  ###############################################################################
985  #
986  # statically link libstdc++ before C++ ABI is stablized on Linux unless
987  # dynamic build is configured on command line.
988  #
989  AC_ARG_WITH([stdc++lib], [AS_HELP_STRING([--with-stdc++lib=<static>,<dynamic>,<default>],
990      [force linking of the C++ runtime on Linux to either static or dynamic, default is static with dynamic as fallback])],
991      [
992        if test "x$with_stdc__lib" != xdynamic && test "x$with_stdc__lib" != xstatic \
993                && test "x$with_stdc__lib" != xdefault; then
994          AC_MSG_ERROR([Bad parameter value --with-stdc++lib=$with_stdc__lib!])
995        fi
996      ],
997      [with_stdc__lib=default]
998  )
999
1000  if test "x$OPENJDK_TARGET_OS" = xlinux; then
1001    # Test if -lstdc++ works.
1002    AC_MSG_CHECKING([if dynamic link of stdc++ is possible])
1003    AC_LANG_PUSH(C++)
1004    OLD_CXXFLAGS="$CXXFLAGS"
1005    CXXFLAGS="$CXXFLAGS -lstdc++"
1006    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1007        [has_dynamic_libstdcxx=yes],
1008        [has_dynamic_libstdcxx=no])
1009    CXXFLAGS="$OLD_CXXFLAGS"
1010    AC_LANG_POP(C++)
1011    AC_MSG_RESULT([$has_dynamic_libstdcxx])
1012
1013    # Test if stdc++ can be linked statically.
1014    AC_MSG_CHECKING([if static link of stdc++ is possible])
1015    STATIC_STDCXX_FLAGS="-Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic"
1016    AC_LANG_PUSH(C++)
1017    OLD_LIBS="$LIBS"
1018    OLD_CXX="$CXX"
1019    LIBS="$STATIC_STDCXX_FLAGS"
1020    CXX="$CC"
1021    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1022        [has_static_libstdcxx=yes],
1023        [has_static_libstdcxx=no])
1024    LIBS="$OLD_LIBS"
1025    CXX="$OLD_CXX"
1026    AC_LANG_POP(C++)
1027    AC_MSG_RESULT([$has_static_libstdcxx])
1028
1029    if test "x$has_static_libstdcxx" = xno && test "x$has_dynamic_libstdcxx" = xno; then
1030      AC_MSG_ERROR([Cannot link to stdc++, neither dynamically nor statically!])
1031    fi
1032
1033    if test "x$with_stdc__lib" = xstatic && test "x$has_static_libstdcxx" = xno; then
1034      AC_MSG_ERROR([Static linking of libstdc++ was not possible!])
1035    fi
1036
1037    if test "x$with_stdc__lib" = xdynamic && test "x$has_dynamic_libstdcxx" = xno; then
1038      AC_MSG_ERROR([Dynamic linking of libstdc++ was not possible!])
1039    fi
1040
1041    AC_MSG_CHECKING([how to link with libstdc++])
1042    # If dynamic was requested, it's available since it would fail above otherwise.
1043    # If dynamic wasn't requested, go with static unless it isn't available.
1044    if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
1045      LIBCXX="$LIBCXX -lstdc++"
1046      LDCXX="$CXX"
1047      STATIC_CXX_SETTING="STATIC_CXX=false"
1048      AC_MSG_RESULT([dynamic])
1049    else
1050      LIBCXX="$LIBCXX $STATIC_STDCXX_FLAGS"
1051      LDCXX="$CC"
1052      STATIC_CXX_SETTING="STATIC_CXX=true"
1053      AC_MSG_RESULT([static])
1054    fi
1055  fi
1056  AC_SUBST(STATIC_CXX_SETTING)
1057
1058  if test "x$JVM_VARIANT_ZERO" = xtrue || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
1059    # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS
1060    PKG_CHECK_MODULES([LIBFFI], [libffi])
1061
1062  fi
1063
1064  if test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
1065    AC_CHECK_PROG([LLVM_CONFIG], [llvm-config], [llvm-config])
1066
1067    if test "x$LLVM_CONFIG" != xllvm-config; then
1068      AC_MSG_ERROR([llvm-config not found in $PATH.])
1069    fi
1070
1071    llvm_components="jit mcjit engine nativecodegen native"
1072    unset LLVM_CFLAGS
1073    for flag in $("$LLVM_CONFIG" --cxxflags); do
1074      if echo "${flag}" | grep -q '^-@<:@ID@:>@'; then
1075        if test "${flag}" != "-D_DEBUG" ; then
1076          if test "${LLVM_CFLAGS}" != "" ; then
1077            LLVM_CFLAGS="${LLVM_CFLAGS} "
1078          fi
1079          LLVM_CFLAGS="${LLVM_CFLAGS}${flag}"
1080        fi
1081      fi
1082    done
1083    llvm_version=$("${LLVM_CONFIG}" --version | sed 's/\.//; s/svn.*//')
1084    LLVM_CFLAGS="${LLVM_CFLAGS} -DSHARK_LLVM_VERSION=${llvm_version}"
1085
1086    unset LLVM_LDFLAGS
1087    for flag in $("${LLVM_CONFIG}" --ldflags); do
1088      if echo "${flag}" | grep -q '^-L'; then
1089        if test "${LLVM_LDFLAGS}" != ""; then
1090          LLVM_LDFLAGS="${LLVM_LDFLAGS} "
1091        fi
1092        LLVM_LDFLAGS="${LLVM_LDFLAGS}${flag}"
1093      fi
1094    done
1095
1096    unset LLVM_LIBS
1097    for flag in $("${LLVM_CONFIG}" --libs ${llvm_components}); do
1098      if echo "${flag}" | grep -q '^-l'; then
1099        if test "${LLVM_LIBS}" != ""; then
1100          LLVM_LIBS="${LLVM_LIBS} "
1101        fi
1102        LLVM_LIBS="${LLVM_LIBS}${flag}"
1103      fi
1104    done
1105
1106    AC_SUBST(LLVM_CFLAGS)
1107    AC_SUBST(LLVM_LDFLAGS)
1108    AC_SUBST(LLVM_LIBS)
1109  fi
1110
1111  # libCrun is the c++ runtime-library with SunStudio (roughly the equivalent of gcc's libstdc++.so)
1112  if test "x$TOOLCHAIN_TYPE" = xsolstudio && test "x$LIBCXX" = x; then
1113    LIBCXX="${SYSROOT}/usr/lib${OPENJDK_TARGET_CPU_ISADIR}/libCrun.so.1"
1114  fi
1115
1116  # TODO better (platform agnostic) test
1117  if test "x$OPENJDK_TARGET_OS" = xmacosx && test "x$LIBCXX" = x && test "x$TOOLCHAIN_TYPE" = xgcc; then
1118    LIBCXX="-lstdc++"
1119  fi
1120
1121  AC_SUBST(LIBCXX)
1122])
1123
1124AC_DEFUN_ONCE([LIB_SETUP_ON_WINDOWS],
1125[
1126  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
1127    TOOLCHAIN_SETUP_MSVCR_DLL
1128    BASIC_DEPRECATED_ARG_WITH([dxsdk])
1129    BASIC_DEPRECATED_ARG_WITH([dxsdk-lib])
1130    BASIC_DEPRECATED_ARG_WITH([dxsdk-include])
1131  fi
1132  AC_SUBST(MSVCR_DLL)
1133])
1134