jdk

Форк
0
/
util_paths.m4 
558 строк · 18.7 Кб
1
#
2
# Copyright (c) 2011, 2023, 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
# Appends a string to a path variable, only adding the : when needed.
28
AC_DEFUN([UTIL_APPEND_TO_PATH],
29
[
30
  if test "x$2" != x; then
31
    if test "x[$]$1" = x; then
32
      $1="$2"
33
    else
34
      $1="[$]$1:$2"
35
    fi
36
  fi
37
])
38

39
###############################################################################
40
# Prepends a string to a path variable, only adding the : when needed.
41
AC_DEFUN([UTIL_PREPEND_TO_PATH],
42
[
43
  if test "x$2" != x; then
44
    if test "x[$]$1" = x; then
45
      $1="$2"
46
    else
47
      $1="$2:[$]$1"
48
    fi
49
  fi
50
])
51

52
###############################################################################
53
# This will make sure the given variable points to a full and proper
54
# path. This means:
55
# 1) There will be no spaces in the path. On unix platforms,
56
#    spaces in the path will result in an error. On Windows,
57
#    the path will be rewritten using short-style to be space-free.
58
# 2) The path will be absolute, and it will be in unix-style (on
59
#     cygwin).
60
# $1: The name of the variable to fix
61
# $2: if NOFAIL, errors will be silently ignored
62
AC_DEFUN([UTIL_FIXUP_PATH],
63
[
64
  # Only process if variable expands to non-empty
65
  path="[$]$1"
66
  if test "x$path" != x; then
67
    if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
68
      if test "x$2" = "xNOFAIL"; then
69
        quiet_option="-q"
70
      fi
71
      imported_path=`$FIXPATH_BASE $quiet_option import "$path"`
72
      $FIXPATH_BASE verify "$imported_path"
73
      if test $? -ne 0; then
74
        if test "x$2" != "xNOFAIL"; then
75
          AC_MSG_ERROR([The path of $1, which resolves as "$path", could not be imported.])
76
        else
77
          imported_path=""
78
        fi
79
      fi
80
      if test "x$imported_path" != "x$path"; then
81
        $1="$imported_path"
82
      fi
83
    else
84
      [ if [[ "$path" =~ " " ]]; then ]
85
        if test "x$2" != "xNOFAIL"; then
86
          AC_MSG_NOTICE([The path of $1, which resolves as "$path", is invalid.])
87
          AC_MSG_ERROR([Spaces are not allowed in this path.])
88
        else
89
          path=""
90
        fi
91
      fi
92

93
      # Use eval to expand a potential ~.
94
      eval new_path="$path"
95
      if test ! -e "$new_path"; then
96
        if test "x$2" != "xNOFAIL"; then
97
          AC_MSG_ERROR([The path of $1, which resolves as "$new_path", is not found.])
98
        else
99
          new_path=""
100
        fi
101
      fi
102

103
      # Make the path absolute
104
      if test "x$new_path" != x; then
105
        if test -d "$new_path"; then
106
          path="`cd "$new_path"; pwd -L`"
107
        else
108
          dir="`$DIRNAME "$new_path"`"
109
          base="`$BASENAME "$new_path"`"
110
          path="`cd "$dir"; pwd -L`/$base"
111
        fi
112
      else
113
        path=""
114
      fi
115

116
      $1="$path"
117
    fi
118
  fi
119
])
120

121
##############################################################################
122
# Fixup path to be a Windows full long path
123
# Note: Only supported with cygwin/msys2 (cygpath tool)
124
AC_DEFUN([UTIL_FIXUP_WIN_LONG_PATH],
125
[
126
  # Only process if variable expands to non-empty
127
  path="[$]$1"
128
  if test "x$path" != x; then
129
    if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
130
      win_path=$($PATHTOOL -wl "$path")
131
      if test "x$win_path" != "x$path"; then
132
        $1="$win_path"
133
      fi
134
    fi
135
  fi
136
])
137

138

139
###############################################################################
140
# Check if the given file is a unix-style or windows-style executable, that is,
141
# if it expects paths in unix-style or windows-style.
142
# Returns "windows" or "unix" in $RESULT.
143
AC_DEFUN([UTIL_CHECK_WINENV_EXEC_TYPE],
144
[
145
  # For cygwin and msys2, if it's linked with the correct helper lib, it
146
  # accept unix paths
147
  if test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.cygwin" || \
148
      test "x$OPENJDK_BUILD_OS_ENV" = "xwindows.msys2"; then
149
    linked_libs=`$LDD $1 2>&1`
150
    if test $? -ne 0; then
151
      # Non-binary files (e.g. shell scripts) are unix files
152
      RESULT=unix
153
    else
154
      [ if [[ "$linked_libs" =~ $WINENV_MARKER_DLL ]]; then ]
155
        RESULT=unix
156
      else
157
        RESULT=windows
158
      fi
159
    fi
160
  elif test "x$OPENJDK_BUILD_OS" = "xwindows"; then
161
    # On WSL, we can check if it is a PE file
162
    file_type=`$FILE -b $1 2>&1`
163
    [ if [[ $file_type =~ PE.*Windows ]]; then ]
164
      RESULT=windows
165
    else
166
      RESULT=unix
167
    fi
168
  else
169
    RESULT=unix
170
  fi
171
])
172

173
###############################################################################
174
# This will make sure the given variable points to a executable
175
# with a full and proper path. This means:
176
# 1) There will be no spaces in the path. On unix platforms,
177
#    spaces in the path will result in an error. On Windows,
178
#    the path will be rewritten using short-style to be space-free.
179
# 2) The path will be absolute, and it will be in unix-style (on
180
#     cygwin).
181
# Any arguments given to the executable is preserved.
182
# If the input variable does not have a directory specification, then
183
# it need to be in the PATH.
184
# $1: The name of the variable to fix
185
# $2: Where to look for the command (replaces $PATH)
186
# $3: set to NOFIXPATH to skip prefixing FIXPATH, even if needed on platform
187
AC_DEFUN([UTIL_FIXUP_EXECUTABLE],
188
[
189
  input="[$]$1"
190

191
  # Only process if variable expands to non-empty
192
  if test "x$input" != x; then
193
    # First separate the path from the arguments. This will split at the first
194
    # space.
195
    [ if [[ "$OPENJDK_BUILD_OS" = "windows" && input =~ ^$FIXPATH ]]; then
196
      line="${input#$FIXPATH }"
197
      fixpath_prefix="$FIXPATH "
198
    else
199
      line="$input"
200
      fixpath_prefix=""
201
    fi ]
202
    path="${line%% *}"
203
    arguments="${line#"$path"}"
204

205
    [ if ! [[ "$path" =~ /|\\ ]]; then ]
206
      # This is a command without path (e.g. "gcc" or "echo")
207
      command_type=`type -t "$path"`
208
      if test "x$command_type" = xbuiltin || test "x$command_type" = xkeyword; then
209
        # Shell builtin or keyword; we're done here
210
        new_path="$path"
211
      else
212
        # Search in $PATH using bash built-in 'type -p'.
213
        saved_path="$PATH"
214
        if test "x$2" != x; then
215
          PATH="$2"
216
        fi
217
        new_path=`type -p "$path"`
218
        if test "x$new_path" = x && test "x$OPENJDK_BUILD_OS" = "xwindows"; then
219
          # Try again with .exe
220
          new_path="`type -p "$path.exe"`"
221
        fi
222
        PATH="$saved_path"
223

224
        if test "x$new_path" = x; then
225
          AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not found in the PATH.])
226
          AC_MSG_ERROR([Cannot locate $path])
227
        fi
228
      fi
229
    else
230
      # This is a path with slashes, don't look at $PATH
231
      if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
232
        # fixpath.sh import will do all heavy lifting for us
233
        new_path=`$FIXPATH_BASE import "$path"`
234

235
        if test ! -e $new_path; then
236
          # It failed, but maybe spaces were part of the path and not separating
237
          # the command and argument. Retry using that assumption.
238
          new_path=`$FIXPATH_BASE import "$input"`
239
          if test ! -e $new_path; then
240
            AC_MSG_NOTICE([The command for $1, which resolves as "$input", can not be found.])
241
            AC_MSG_ERROR([Cannot locate $input])
242
          fi
243
          # It worked, clear all "arguments"
244
          arguments=""
245
        fi
246
      else # on unix
247
        # Make absolute
248
        $1="$path"
249
        UTIL_FIXUP_PATH($1, NOFAIL)
250
        new_path="[$]$1"
251

252
        if test ! -e $new_path; then
253
          AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not found])
254
          [ if [[ "$path" =~ " " ]]; then ]
255
            AC_MSG_NOTICE([This might be caused by spaces in the path, which is not allowed.])
256
          fi
257
          AC_MSG_ERROR([Cannot locate $path])
258
        fi
259
        if test ! -x $new_path; then
260
          AC_MSG_NOTICE([The command for $1, which resolves as "$input", is not executable.])
261
          AC_MSG_ERROR([Cannot execute command at $path])
262
        fi
263
      fi # end on unix
264
    fi # end with or without slashes
265

266
    # Now we have a usable command as new_path, with arguments in arguments
267
    if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
268
      if test "x$fixpath_prefix" = x; then
269
        # Only mess around if fixpath_prefix was not given
270
        UTIL_CHECK_WINENV_EXEC_TYPE("$new_path")
271
        if test "x$RESULT" = xwindows; then
272
          fixpath_prefix="$FIXPATH "
273
          # make sure we have an .exe suffix (but not two)
274
          new_path="${new_path%.exe}.exe"
275
        else
276
          # If we have gotten a .exe suffix, remove it
277
          new_path="${new_path%.exe}"
278
        fi
279
      fi
280
    fi
281

282
    if test "x$3" = xNOFIXPATH; then
283
      fixpath_prefix=""
284
    fi
285

286
    # Now join together the path and the arguments once again
287
    new_complete="$fixpath_prefix$new_path$arguments"
288
    $1="$new_complete"
289
  fi
290
])
291

292
###############################################################################
293
# Setup a tool for the given variable. If correctly specified by the user,
294
# use that value, otherwise search for the tool using the supplied code snippet.
295
# $1: variable to set
296
# $2: code snippet to call to look for the tool
297
# $3: code snippet to call if variable was used to find tool
298
AC_DEFUN([UTIL_SETUP_TOOL],
299
[
300
  # Publish this variable in the help.
301
  AC_ARG_VAR($1, [Override default value for $1])
302

303
  if [[ -z "${$1+x}" ]]; then
304
    # The variable is not set by user, try to locate tool using the code snippet
305
    $2
306
  else
307
    # The variable is set, but is it from the command line or the environment?
308

309
    # Try to remove the string !$1! from our list.
310
    try_remove_var=${CONFIGURE_OVERRIDDEN_VARIABLES//!$1!/}
311
    if test "x$try_remove_var" = "x$CONFIGURE_OVERRIDDEN_VARIABLES"; then
312
      # If it failed, the variable was not from the command line. Ignore it,
313
      # but warn the user (except for BASH, which is always set by the calling BASH).
314
      if test "x$1" != xBASH; then
315
        AC_MSG_WARN([Ignoring value of $1 from the environment. Use command line variables instead.])
316
      fi
317
      # Try to locate tool using the code snippet
318
      $2
319
    else
320
      # If it succeeded, then it was overridden by the user. We will use it
321
      # for the tool.
322

323
      # First remove it from the list of overridden variables, so we can test
324
      # for unknown variables in the end.
325
      CONFIGURE_OVERRIDDEN_VARIABLES="$try_remove_var"
326

327
      tool_override=[$]$1
328

329
      # Check if we try to supply an empty value
330
      if test "x$tool_override" = x; then
331
        AC_MSG_CHECKING([for $1])
332
        AC_MSG_RESULT([[[disabled by user]]])
333
      else
334
        # Split up override in command part and argument part
335
        tool_and_args=($tool_override)
336
        [ tool_command=${tool_and_args[0]} ]
337
        [ unset 'tool_and_args[0]' ]
338
        [ tool_args=${tool_and_args[@]} ]
339

340
        # Check if the provided tool contains a complete path.
341
        tool_basename="${tool_command##*/}"
342
        if test "x$tool_basename" = "x$tool_command"; then
343
          # A command without a complete path is provided, search $PATH.
344
          AC_MSG_NOTICE([Will search for user supplied tool "$tool_basename"])
345
          AC_PATH_PROGS($1, $tool_basename ${tool_basename}.exe)
346
          tool_command="[$]$1"
347
          if test "x$tool_command" = x; then
348
            AC_MSG_ERROR([User supplied tool $1="$tool_basename" could not be found in PATH])
349
          fi
350
        else
351
          # Otherwise we believe it is a complete path. Use it as it is.
352
          if test ! -x "$tool_command" && test ! -x "${tool_command}.exe"; then
353
            AC_MSG_ERROR([User supplied tool $1="$tool_command" does not exist or is not executable])
354
          fi
355
          if test ! -x "$tool_command"; then
356
            tool_command="${tool_command}.exe"
357
          fi
358
          $1="$tool_command"
359
        fi
360
        if test "x$tool_args" != x; then
361
          # If we got arguments, re-append them to the command after the fixup.
362
          $1="[$]$1 $tool_args"
363
        fi
364
        AC_MSG_CHECKING([for $1])
365
        AC_MSG_RESULT([[$]$1 [[user supplied]]])
366
      fi
367
    fi
368
    $3
369
  fi
370
])
371

372
###############################################################################
373
# Locate a tool using proper methods.
374
# $1: variable to set
375
# $2: executable name (or list of names) to look for
376
# $3: [path]
377
# $4: set to NOFIXPATH to skip prefixing FIXPATH, even if needed on platform
378
AC_DEFUN([UTIL_LOOKUP_PROGS],
379
[
380
  UTIL_SETUP_TOOL($1, [
381
    $1=""
382

383
    if test "x$3" != x; then
384
      old_path="$PATH"
385
      PATH="$3"
386
    fi
387

388
    for name in $2; do
389
      AC_MSG_CHECKING(for $name)
390

391
      command_type=`type -t "$name"`
392
      if test "x$command_type" = xbuiltin || test "x$command_type" = xkeyword; then
393
        # Shell builtin or keyword; we're done here
394
        full_path="$name"
395
        $1="$full_path"
396
        AC_MSG_RESULT([[$full_path [builtin]]])
397
        break
398
      else
399
        # Search in $PATH
400
        old_ifs="$IFS"
401
        IFS=":"
402
        for elem in $PATH; do
403
          IFS="$old_ifs"
404
          if test "x$elem" = x; then
405
            continue
406
          fi
407
          full_path="$elem/$name"
408
          if test ! -e "$full_path" && test "x$OPENJDK_BUILD_OS" = "xwindows"; then
409
            # Try again with .exe
410
            full_path="$elem/$name.exe"
411
          fi
412
          if test -x "$full_path" && test ! -d "$full_path" ; then
413
            $1="$full_path"
414
            UTIL_FIXUP_EXECUTABLE($1, $3, $4)
415
            result="[$]$1"
416

417
            # If we have FIXPATH enabled, strip all instances of it and prepend
418
            # a single one, to avoid double fixpath prefixing.
419
            if test "x$4" != xNOFIXPATH; then
420
              [ if [[ $FIXPATH != "" && $result =~ ^"$FIXPATH " ]]; then ]
421
                result="\$FIXPATH ${result#"$FIXPATH "}"
422
              fi
423
            fi
424
            AC_MSG_RESULT([$result])
425
            break 2;
426
          fi
427
        done
428
        IFS="$old_ifs"
429
      fi
430
      AC_MSG_RESULT([[[not found]]])
431
    done
432

433
    if test "x$3" != x; then
434
      PATH="$old_path"
435
    fi
436
  ])
437
])
438

439
###############################################################################
440
# Call UTIL_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool. This will look
441
# first for cross-compilation tools.
442
# $1: variable to set
443
# $2: executable name (or list of names) to look for
444
# $3: [path]
445
AC_DEFUN([UTIL_LOOKUP_TOOLCHAIN_PROGS],
446
[
447
  if test "x$ac_tool_prefix" = x; then
448
    UTIL_LOOKUP_PROGS($1, $2, $3)
449
  else
450
    prefixed_names=$(for name in $2; do echo ${ac_tool_prefix}${name} $name; done)
451
    UTIL_LOOKUP_PROGS($1, $prefixed_names, $3)
452
  fi
453
])
454

455
###############################################################################
456
# Test that variable $1 denoting a program is not empty. If empty, exit with an error.
457
# $1: variable to check
458
AC_DEFUN([UTIL_CHECK_NONEMPTY],
459
[
460
  if test "x[$]$1" = x; then
461
    AC_MSG_ERROR([Could not find required tool for $1])
462
  fi
463
])
464

465
###############################################################################
466
# Like UTIL_LOOKUP_PROGS but fails if no tool was found.
467
# $1: variable to set
468
# $2: executable name (or list of names) to look for
469
# $3: [path]
470
AC_DEFUN([UTIL_REQUIRE_PROGS],
471
[
472
  UTIL_LOOKUP_PROGS($1, $2, $3)
473
  UTIL_CHECK_NONEMPTY($1)
474
])
475

476
###############################################################################
477
# Like UTIL_LOOKUP_PROGS but fails if no tool was found.
478
# $1: variable to set
479
# $2: executable name (or list of names) to look for
480
# $3: [path]
481
AC_DEFUN([UTIL_REQUIRE_TOOLCHAIN_PROGS],
482
[
483
  UTIL_LOOKUP_TOOLCHAIN_PROGS($1, $2, $3)
484
  UTIL_CHECK_NONEMPTY($1)
485
])
486

487

488
###############################################################################
489
# Like UTIL_SETUP_TOOL but fails if no tool was found.
490
# $1: variable to set
491
# $2: autoconf macro to call to look for the special tool
492
AC_DEFUN([UTIL_REQUIRE_SPECIAL],
493
[
494
  UTIL_SETUP_TOOL($1, [$2])
495
  UTIL_CHECK_NONEMPTY($1)
496
  # The special macro will return an absolute path, and is only used for
497
  # unix tools. No further processing needed.
498
])
499

500
###############################################################################
501
# Add FIXPATH prefix to variable. Normally this is done by UTIL_LOOKUP_PROGS
502
# or UTIL_FIXUP_EXECUTABLE, but in some circumstances this has to be done
503
# explicitly, such as when the command in question does not exist yet.
504
#
505
# $1: variable to add fixpath to
506
AC_DEFUN([UTIL_ADD_FIXPATH],
507
[
508
  if test "x$FIXPATH" != x; then
509
    $1="$FIXPATH [$]$1"
510
  fi
511
])
512

513
###############################################################################
514
AC_DEFUN([UTIL_REMOVE_SYMBOLIC_LINKS],
515
[
516
  if test "x$OPENJDK_BUILD_OS" != xwindows; then
517
    # Follow a chain of symbolic links. Use readlink
518
    # where it exists, else fall back to horribly
519
    # complicated shell code.
520
    if test "x$READLINK_TESTED" != yes; then
521
      # On MacOSX there is a readlink tool with a different
522
      # purpose than the GNU readlink tool. Check the found readlink.
523
      READLINK_ISGNU=`$READLINK --version 2>&1 | $GREP GNU`
524
      # If READLINK_ISGNU is empty, then it's a non-GNU readlink. Don't use it.
525
      READLINK_TESTED=yes
526
    fi
527

528
    if test "x$READLINK" != x && test "x$READLINK_ISGNU" != x; then
529
      $1=`$READLINK -f [$]$1`
530
    else
531
      # Save the current directory for restoring afterwards
532
      STARTDIR=$PWD
533
      COUNTER=0
534
      sym_link_dir=`$DIRNAME [$]$1`
535
      sym_link_file=`$BASENAME [$]$1`
536
      cd $sym_link_dir
537
      # Use -P flag to resolve symlinks in directories.
538
      cd `pwd -P`
539
      sym_link_dir=`pwd -P`
540
      # Resolve file symlinks
541
      while test $COUNTER -lt 20; do
542
        ISLINK=`$LS -l $sym_link_dir/$sym_link_file | $GREP -e '->' | $SED -e 's/.*-> \(.*\)/\1/'`
543
        if test "x$ISLINK" == x; then
544
          # This is not a symbolic link! We are done!
545
          break
546
        fi
547
        # Again resolve directory symlinks since the target of the just found
548
        # link could be in a different directory
549
        cd `$DIRNAME $ISLINK`
550
        sym_link_dir=`pwd -P`
551
        sym_link_file=`$BASENAME $ISLINK`
552
        let COUNTER=COUNTER+1
553
      done
554
      cd $STARTDIR
555
      $1=$sym_link_dir/$sym_link_file
556
    fi
557
  fi
558
])
559

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.