1#
2# Copyright (c) 2011, 2018, 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
26################################################################################
27# Setup X11 Windows system
28################################################################################
29AC_DEFUN_ONCE([LIB_SETUP_X11],
30[
31  if test "x$NEEDS_LIB_X11" = xfalse; then
32    if (test "x${with_x}" != x && test "x${with_x}" != xno); then
33      AC_MSG_WARN([X11 is not used, so --with-x is ignored])
34    fi
35    X_CFLAGS=
36    X_LIBS=
37  else
38
39    if test "x${with_x}" = xno; then
40      AC_MSG_ERROR([It is not possible to disable the use of X11. Remove the --without-x option.])
41    fi
42
43    if test "x${with_x}" != x &&  test "x${with_x}" != xyes; then
44      # The user has specified a X11 base directory. Use it for includes and
45      # libraries, unless explicitly overridden.
46      if test "x$x_includes" = xNONE; then
47        x_includes="${with_x}/include"
48      fi
49      if test "x$x_libraries" = xNONE; then
50        x_libraries="${with_x}/lib"
51      fi
52    else
53      # Check if the user has specified sysroot, but not --with-x, --x-includes or --x-libraries.
54      # Make a simple check for the libraries at the sysroot, and setup --x-includes and
55      # --x-libraries for the sysroot, if that seems to be correct.
56      if test "x$SYSROOT" != "x"; then
57        if test "x$x_includes" = xNONE; then
58          if test -f "$SYSROOT/usr/X11R6/include/X11/Xlib.h"; then
59            x_includes="$SYSROOT/usr/X11R6/include"
60          elif test -f "$SYSROOT/usr/include/X11/Xlib.h"; then
61            x_includes="$SYSROOT/usr/include"
62          fi
63        fi
64        if test "x$x_libraries" = xNONE; then
65          if test -f "$SYSROOT/usr/X11R6/lib/libX11.so"; then
66            x_libraries="$SYSROOT/usr/X11R6/lib"
67          elif test -f "$SYSROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
68            x_libraries="$SYSROOT/usr/lib64"
69          elif test -f "$SYSROOT/usr/lib/libX11.so"; then
70            x_libraries="$SYSROOT/usr/lib"
71          elif test -f "$SYSROOT/usr/lib/$OPENJDK_TARGET_CPU-$OPENJDK_TARGET_OS-$OPENJDK_TARGET_ABI/libX11.so"; then
72            x_libraries="$SYSROOT/usr/lib/$OPENJDK_TARGET_CPU-$OPENJDK_TARGET_OS-$OPENJDK_TARGET_ABI/libX11.so"
73          elif test -f "$SYSROOT/usr/lib/$OPENJDK_TARGET_CPU_AUTOCONF-$OPENJDK_TARGET_OS-$OPENJDK_TARGET_ABI/libX11.so"; then
74            x_libraries="$SYSROOT/usr/lib/$OPENJDK_TARGET_CPU_AUTOCONF-$OPENJDK_TARGET_OS-$OPENJDK_TARGET_ABI/libX11.so"
75          fi
76        fi
77      fi
78    fi
79
80    # Now let autoconf do it's magic
81    AC_PATH_X
82    AC_PATH_XTRA
83
84    # AC_PATH_XTRA creates X_LIBS and sometimes adds -R flags. When cross compiling
85    # this doesn't make sense so we remove it.
86    if test "x$COMPILE_TYPE" = xcross; then
87      X_LIBS=`$ECHO $X_LIBS | $SED 's/-R \{0,1\}[[^ ]]*//g'`
88    fi
89
90    if test "x$no_x" = xyes; then
91      HELP_MSG_MISSING_DEPENDENCY([x11])
92      AC_MSG_ERROR([Could not find X11 libraries. $HELP_MSG])
93    fi
94
95    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
96      OPENWIN_HOME="/usr/openwin"
97      X_CFLAGS="-I$SYSROOT$OPENWIN_HOME/include -I$SYSROOT$OPENWIN_HOME/include/X11/extensions"
98      X_LIBS="-L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
99          -R$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR"
100    fi
101
102    AC_LANG_PUSH(C)
103    OLD_CFLAGS="$CFLAGS"
104    CFLAGS="$CFLAGS $SYSROOT_CFLAGS $X_CFLAGS"
105
106    HEADERS_TO_CHECK="X11/extensions/shape.h X11/extensions/Xrender.h X11/extensions/XTest.h X11/Intrinsic.h"
107    # There is no Xrandr extension on AIX
108    if test "x$OPENJDK_TARGET_OS" != xaix; then
109      HEADERS_TO_CHECK="$HEADERS_TO_CHECK X11/extensions/Xrandr.h"
110    fi
111
112    # Need to include Xlib.h and Xutil.h to avoid "present but cannot be compiled" warnings on Solaris 10
113    AC_CHECK_HEADERS([$HEADERS_TO_CHECK],
114        [X11_HEADERS_OK=yes],
115        [X11_HEADERS_OK=no; break],
116        [
117          # include <X11/Xlib.h>
118          # include <X11/Xutil.h>
119        ]
120    )
121
122    if test "x$X11_HEADERS_OK" = xno; then
123      HELP_MSG_MISSING_DEPENDENCY([x11])
124      AC_MSG_ERROR([Could not find all X11 headers (shape.h Xrender.h Xrandr.h XTest.h Intrinsic.h). $HELP_MSG])
125    fi
126
127    # If XLinearGradient isn't available in Xrender.h, signal that it needs to be
128    # defined in libawt_xawt.
129    AC_MSG_CHECKING([if XlinearGradient is defined in Xrender.h])
130    AC_COMPILE_IFELSE(
131        [AC_LANG_PROGRAM([[#include <X11/extensions/Xrender.h>]],
132            [[XLinearGradient x;]])],
133        [AC_MSG_RESULT([yes])],
134        [AC_MSG_RESULT([no])
135         X_CFLAGS="$X_CFLAGS -DSOLARIS10_NO_XRENDER_STRUCTS"])
136
137    CFLAGS="$OLD_CFLAGS"
138    AC_LANG_POP(C)
139  fi # NEEDS_LIB_X11
140
141  AC_SUBST(X_CFLAGS)
142  AC_SUBST(X_LIBS)
143])
144