toolchain_windows.m4 revision 1315:32470a815f99
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([TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT],
27[
28  if test "x$VS_ENV_CMD" = x; then
29    VS100BASE="$1"
30    METHOD="$2"
31    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VS100BASE)
32    if test -d "$VS100BASE"; then
33      if test -f "$VS100BASE/$VCVARSFILE"; then
34        AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
35        VS_ENV_CMD="$VS100BASE/$VCVARSFILE"
36        # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
37        # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be one of 'v100', 'v110' or 'v120' for VS 2010, 2012 or VS2013
38        # TODO: improve detection for other versions of VS
39        PLATFORM_TOOLSET="v100"
40      else
41        AC_MSG_NOTICE([Found Visual Studio installation at $VS100BASE using $METHOD])
42        AC_MSG_NOTICE([Warning: $VCVARSFILE is missing, this is probably Visual Studio Express. Ignoring])
43      fi
44    fi
45  fi
46])
47
48AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT],
49[
50  if test "x$VS_ENV_CMD" = x; then
51    WIN_SDK_BASE="$1"
52    METHOD="$2"
53    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(WIN_SDK_BASE)
54    if test -d "$WIN_SDK_BASE"; then
55      # There have been cases of partial or broken SDK installations. A missing
56      # lib dir is not going to work.
57      if test ! -d "$WIN_SDK_BASE/../lib"; then
58        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
59        AC_MSG_NOTICE([Warning: Installation is broken, lib dir is missing. Ignoring])
60      elif test -f "$WIN_SDK_BASE/SetEnv.Cmd"; then
61        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
62        VS_ENV_CMD="$WIN_SDK_BASE/SetEnv.Cmd"
63        if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
64          VS_ENV_ARGS="/x86"
65        else
66          VS_ENV_ARGS="/x64"
67        fi
68        # PLATFORM_TOOLSET is used during the compilation of the freetype sources (see
69        # 'LIB_BUILD_FREETYPE' in libraries.m4) and must be 'Windows7.1SDK' for Windows7.1SDK
70        # TODO: improve detection for other versions of SDK
71        PLATFORM_TOOLSET="Windows7.1SDK"
72      else
73        AC_MSG_NOTICE([Found Windows SDK installation at $WIN_SDK_BASE using $METHOD])
74        AC_MSG_NOTICE([Warning: Installation is broken, SetEnv.Cmd is missing. Ignoring])
75      fi
76    fi
77  fi
78])
79
80AC_DEFUN([TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE],
81[
82  if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
83    VCVARSFILE="vc/bin/vcvars32.bat"
84  else
85    VCVARSFILE="vc/bin/amd64/vcvars64.bat"
86  fi
87
88  VS_ENV_CMD=""
89  VS_ENV_ARGS=""
90  if test "x$with_toolsdir" != x; then
91    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$with_toolsdir/../..], [--with-tools-dir])
92  fi
93
94  if test "x$with_toolsdir" != x && test "x$VS_ENV_CMD" = x; then
95    # Having specified an argument which is incorrect will produce an instant failure;
96    # we should not go on looking
97    AC_MSG_NOTICE([The path given by --with-tools-dir does not contain a valid Visual Studio installation])
98    AC_MSG_NOTICE([Please point to the VC/bin directory within the Visual Studio installation])
99    AC_MSG_ERROR([Cannot locate a valid Visual Studio installation])
100  fi
101
102  if test "x$VS100COMNTOOLS" != x; then
103    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$VS100COMNTOOLS/../..], [VS100COMNTOOLS variable])
104  fi
105  if test "x$PROGRAMFILES" != x; then
106    TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([$PROGRAMFILES/Microsoft Visual Studio 10.0], [well-known name])
107  fi
108  TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files/Microsoft Visual Studio 10.0], [well-known name])
109  TOOLCHAIN_CHECK_POSSIBLE_VISUAL_STUDIO_ROOT([C:/Program Files (x86)/Microsoft Visual Studio 10.0], [well-known name])
110
111  if test "x$ProgramW6432" != x; then
112    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$ProgramW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
113  fi
114  if test "x$PROGRAMW6432" != x; then
115    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMW6432/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
116  fi
117  if test "x$PROGRAMFILES" != x; then
118    TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([$PROGRAMFILES/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
119  fi
120  TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
121  TOOLCHAIN_CHECK_POSSIBLE_WIN_SDK_ROOT([C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1/Bin], [well-known name])
122])
123
124# Check if the VS env variables were setup prior to running configure.
125# If not, then find vcvarsall.bat and run it automatically, and integrate
126# the set env variables into the spec file.
127AC_DEFUN([TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV],
128[
129  # Store path to cygwin link.exe to help excluding it when searching for
130  # VS linker. This must be done before changing the PATH when looking for VS.
131  AC_PATH_PROG(CYGWIN_LINK, link)
132  if test "x$CYGWIN_LINK" != x; then
133    AC_MSG_CHECKING([if the first found link.exe is actually the Cygwin link tool])
134    "$CYGWIN_LINK" --version > /dev/null
135    if test $? -eq 0 ; then
136      AC_MSG_RESULT([yes])
137    else
138      AC_MSG_RESULT([no])
139      # This might be the VS linker. Don't exclude it later on.
140      CYGWIN_LINK=""
141    fi
142  fi
143
144  # First-hand choice is to locate and run the vsvars bat file.
145  TOOLCHAIN_FIND_VISUAL_STUDIO_BAT_FILE
146  if test "x$VS_ENV_CMD" != x; then
147    # We have found a Visual Studio environment on disk, let's extract variables from the vsvars bat file.
148    BASIC_FIXUP_EXECUTABLE(VS_ENV_CMD)
149
150    # Lets extract the variables that are set by vcvarsall.bat/vsvars32.bat/vsvars64.bat
151    AC_MSG_NOTICE([Trying to extract Visual Studio environment variables])
152
153    # We need to create a couple of temporary files.
154    VS_ENV_TMP_DIR="$OUTPUT_ROOT/vs-env"
155    $MKDIR -p $VS_ENV_TMP_DIR
156
157    # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment).
158    # Instead create a shell script which will set the relevant variables when run.
159    WINPATH_VS_ENV_CMD="$VS_ENV_CMD"
160    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_VS_ENV_CMD])
161    WINPATH_BASH="$BASH"
162    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH([WINPATH_BASH])
163
164    # Generate a DOS batch file which runs $VS_ENV_CMD, and then creates a shell
165    # script (executable by bash) that will setup the important variables.
166    EXTRACT_VC_ENV_BAT_FILE="$VS_ENV_TMP_DIR/extract-vs-env.bat"
167    $ECHO "@echo off" >  $EXTRACT_VC_ENV_BAT_FILE
168    # This will end up something like:
169    # call C:/progra~2/micros~2.0/vc/bin/amd64/vcvars64.bat
170    $ECHO "call $WINPATH_VS_ENV_CMD $VS_ENV_ARGS" >> $EXTRACT_VC_ENV_BAT_FILE
171    # These will end up something like:
172    # C:/CygWin/bin/bash -c 'echo VS_PATH=\"$PATH\" > localdevenv.sh
173    # The trailing space for everyone except PATH is no typo, but is needed due
174    # to trailing \ in the Windows paths. These will be stripped later.
175    $ECHO "$WINPATH_BASH -c 'echo VS_PATH="'\"$PATH\" > set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
176    $ECHO "$WINPATH_BASH -c 'echo VS_INCLUDE="'\"$INCLUDE\;$include \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
177    $ECHO "$WINPATH_BASH -c 'echo VS_LIB="'\"$LIB\;$lib \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
178    $ECHO "$WINPATH_BASH -c 'echo VCINSTALLDIR="'\"$VCINSTALLDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
179    $ECHO "$WINPATH_BASH -c 'echo WindowsSdkDir="'\"$WindowsSdkDir \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
180    $ECHO "$WINPATH_BASH -c 'echo WINDOWSSDKDIR="'\"$WINDOWSSDKDIR \" >> set-vs-env.sh' >> $EXTRACT_VC_ENV_BAT_FILE
181
182    # Now execute the newly created bat file.
183    # The | cat is to stop SetEnv.Cmd to mess with system colors on msys.
184    # Change directory so we don't need to mess with Windows paths in redirects.
185    cd $VS_ENV_TMP_DIR
186    cmd /c extract-vs-env.bat | $CAT
187    cd $CURDIR
188
189    if test ! -s $VS_ENV_TMP_DIR/set-vs-env.sh; then
190      AC_MSG_NOTICE([Could not succesfully extract the envionment variables needed for the VS setup.])
191      AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
192      AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
193      AC_MSG_ERROR([Cannot continue])
194    fi
195
196    # Now set all paths and other env variables. This will allow the rest of
197    # the configure script to find and run the compiler in the proper way.
198    AC_MSG_NOTICE([Setting extracted environment variables])
199    . $VS_ENV_TMP_DIR/set-vs-env.sh
200    # Now we have VS_PATH, VS_INCLUDE, VS_LIB. For further checking, we
201    # also define VCINSTALLDIR, WindowsSdkDir and WINDOWSSDKDIR.
202  else
203    # We did not find a vsvars bat file, let's hope we are run from a VS command prompt.
204    AC_MSG_NOTICE([Cannot locate a valid Visual Studio installation, checking current environment])
205  fi
206
207  # At this point, we should have correct variables in the environment, or we can't continue.
208  AC_MSG_CHECKING([for Visual Studio variables])
209
210  if test "x$VCINSTALLDIR" != x || test "x$WindowsSDKDir" != x || test "x$WINDOWSSDKDIR" != x; then
211    if test "x$VS_INCLUDE" = x || test "x$VS_LIB" = x; then
212      AC_MSG_RESULT([present but broken])
213      AC_MSG_ERROR([Your VC command prompt seems broken, INCLUDE and/or LIB is missing.])
214    else
215      AC_MSG_RESULT([ok])
216      # Remove any trailing "\" ";" and " " from the variables.
217      VS_INCLUDE=`$ECHO "$VS_INCLUDE" | $SED -e 's/\\\\*;* *$//'`
218      VS_LIB=`$ECHO "$VS_LIB" | $SED 's/\\\\*;* *$//'`
219      VCINSTALLDIR=`$ECHO "$VCINSTALLDIR" | $SED 's/\\\\* *$//'`
220      WindowsSDKDir=`$ECHO "$WindowsSDKDir" | $SED 's/\\\\* *$//'`
221      WINDOWSSDKDIR=`$ECHO "$WINDOWSSDKDIR" | $SED 's/\\\\* *$//'`
222      # Remove any paths containing # (typically F#) as that messes up make. This
223      # is needed if visual studio was installed with F# support.
224      VS_PATH=`$ECHO "$VS_PATH" | $SED 's/[[^:#]]*#[^:]*://g'`
225
226      AC_SUBST(VS_PATH)
227      AC_SUBST(VS_INCLUDE)
228      AC_SUBST(VS_LIB)
229
230      # Convert VS_INCLUDE into SYSROOT_CFLAGS
231      OLDIFS="$IFS"
232      IFS=";"
233      for i in $VS_INCLUDE; do
234        ipath=$i
235	IFS="$OLDIFS"
236        BASIC_FIXUP_PATH([ipath])
237	IFS=";"
238      	SYSROOT_CFLAGS="$SYSROOT_CFLAGS -I$ipath"
239      done
240      # Convert VS_LIB into SYSROOT_LDFLAGS
241      for i in $VS_LIB; do
242        libpath=$i
243	IFS="$OLDIFS"
244        BASIC_FIXUP_PATH([libpath])
245	IFS=";"
246      	SYSROOT_LDFLAGS="$SYSROOT_LDFLAGS -libpath:$libpath"
247      done
248      IFS="$OLDIFS"
249    fi
250  else
251    AC_MSG_RESULT([not found])
252
253    if test "x$VS_ENV_CMD" = x; then
254      AC_MSG_NOTICE([Cannot locate a valid Visual Studio or Windows SDK installation on disk,])
255      AC_MSG_NOTICE([nor is this script run from a Visual Studio command prompt.])
256    else
257      AC_MSG_NOTICE([Running the extraction script failed.])
258    fi
259    AC_MSG_NOTICE([Try setting --with-tools-dir to the VC/bin directory within the VS installation])
260    AC_MSG_NOTICE([or run "bash.exe -l" from a VS command prompt and then run configure from there.])
261    AC_MSG_ERROR([Cannot continue])
262  fi
263])
264
265AC_DEFUN([TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL],
266[
267  POSSIBLE_MSVCR_DLL="$1"
268  METHOD="$2"
269  if test -e "$POSSIBLE_MSVCR_DLL"; then
270    AC_MSG_NOTICE([Found msvcr100.dll at $POSSIBLE_MSVCR_DLL using $METHOD])
271
272    # Need to check if the found msvcr is correct architecture
273    AC_MSG_CHECKING([found msvcr100.dll architecture])
274    MSVCR_DLL_FILETYPE=`$FILE -b "$POSSIBLE_MSVCR_DLL"`
275    if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys"; then
276      # The MSYS 'file' command returns "PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit"
277      # on x32 and "PE32+ executable for MS Windows (DLL) (GUI) Mono/.Net assembly" on x64 systems.
278      if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
279        CORRECT_MSVCR_ARCH="PE32 executable"
280      else
281        CORRECT_MSVCR_ARCH="PE32+ executable"
282      fi
283    else
284      if test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
285        CORRECT_MSVCR_ARCH=386
286      else
287        CORRECT_MSVCR_ARCH=x86-64
288      fi
289    fi
290    if $ECHO "$MSVCR_DLL_FILETYPE" | $GREP "$CORRECT_MSVCR_ARCH" 2>&1 > /dev/null; then
291      AC_MSG_RESULT([ok])
292      MSVCR_DLL="$POSSIBLE_MSVCR_DLL"
293      AC_MSG_CHECKING([for msvcr100.dll])
294      AC_MSG_RESULT([$MSVCR_DLL])
295    else
296      AC_MSG_RESULT([incorrect, ignoring])
297      AC_MSG_NOTICE([The file type of the located msvcr100.dll is $MSVCR_DLL_FILETYPE])
298    fi
299  fi
300])
301
302AC_DEFUN([TOOLCHAIN_SETUP_MSVCR_DLL],
303[
304  AC_ARG_WITH(msvcr-dll, [AS_HELP_STRING([--with-msvcr-dll],
305      [copy this msvcr100.dll into the built JDK (Windows only) @<:@probed@:>@])])
306
307  if test "x$with_msvcr_dll" != x; then
308    # If given explicitely by user, do not probe. If not present, fail directly.
309    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$with_msvcr_dll], [--with-msvcr-dll])
310    if test "x$MSVCR_DLL" = x; then
311      AC_MSG_ERROR([Could not find a proper msvcr100.dll as specified by --with-msvcr-dll])
312    fi
313  fi
314
315  if test "x$MSVCR_DLL" = x; then
316    # Probe: Using well-known location from Visual Studio 10.0
317    if test "x$VCINSTALLDIR" != x; then
318      CYGWIN_VC_INSTALL_DIR="$VCINSTALLDIR"
319      BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VC_INSTALL_DIR)
320      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
321        POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x64/Microsoft.VC100.CRT/msvcr100.dll"
322      else
323        POSSIBLE_MSVCR_DLL="$CYGWIN_VC_INSTALL_DIR/redist/x86/Microsoft.VC100.CRT/msvcr100.dll"
324      fi
325      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in VCINSTALLDIR])
326    fi
327  fi
328
329  if test "x$MSVCR_DLL" = x; then
330    # Probe: Check in the Boot JDK directory.
331    POSSIBLE_MSVCR_DLL="$BOOT_JDK/bin/msvcr100.dll"
332    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in Boot JDK])
333  fi
334
335  if test "x$MSVCR_DLL" = x; then
336    # Probe: Look in the Windows system32 directory
337    CYGWIN_SYSTEMROOT="$SYSTEMROOT"
338    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_SYSTEMROOT)
339    POSSIBLE_MSVCR_DLL="$CYGWIN_SYSTEMROOT/system32/msvcr100.dll"
340    TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [well-known location in SYSTEMROOT])
341  fi
342
343  if test "x$MSVCR_DLL" = x; then
344    # Probe: If Visual Studio Express is installed, there is usually one with the debugger
345    if test "x$VS100COMNTOOLS" != x; then
346      CYGWIN_VS_TOOLS_DIR="$VS100COMNTOOLS/.."
347      BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(CYGWIN_VS_TOOLS_DIR)
348      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
349        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x64/ | $HEAD --lines 1`
350      else
351        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VS_TOOLS_DIR" -name msvcr100.dll | $GREP -i /x86/ | $HEAD --lines 1`
352      fi
353      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VS100COMNTOOLS])
354    fi
355  fi
356
357  if test "x$MSVCR_DLL" = x; then
358    # Probe: Search wildly in the VCINSTALLDIR. We've probably lost by now.
359    # (This was the original behaviour; kept since it might turn up something)
360    if test "x$CYGWIN_VC_INSTALL_DIR" != x; then
361      if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
362        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x64 | $HEAD --lines 1`
363      else
364        POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $GREP x86 | $GREP -v ia64 | $GREP -v x64 | $HEAD --lines 1`
365        if test "x$POSSIBLE_MSVCR_DLL" = x; then
366          # We're grasping at straws now...
367          POSSIBLE_MSVCR_DLL=`$FIND "$CYGWIN_VC_INSTALL_DIR" -name msvcr100.dll | $HEAD --lines 1`
368        fi
369      fi
370
371      TOOLCHAIN_CHECK_POSSIBLE_MSVCR_DLL([$POSSIBLE_MSVCR_DLL], [search of VCINSTALLDIR])
372    fi
373  fi
374
375  if test "x$MSVCR_DLL" = x; then
376    AC_MSG_CHECKING([for msvcr100.dll])
377    AC_MSG_RESULT([no])
378    AC_MSG_ERROR([Could not find msvcr100.dll. Please specify using --with-msvcr-dll.])
379  fi
380
381  BASIC_FIXUP_PATH(MSVCR_DLL)
382])
383