This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Improved $^X absolute pathname conversion.
[metaconfig.git] / U / perl / d_procselfexe.U
1 ?MAKE:d_procselfexe procselfexe: \
2         Oldconfig Setvar rm ls contains issymlink d_readlink
3 ?MAKE:  -pick add $@ %<
4 ?S:d_procselfexe:
5 ?S:     Defined if $procselfexe is symlink to the absolute
6 ?S:     pathname of the executing program.
7 ?S:.
8 ?S:procselfexe:
9 ?S:     If d_procselfexe is defined, $procselfexe is the filename
10 ?S:     of the symbolic link pointing to the absolute pathname of
11 ?S:     the executing program.
12 ?S:.
13 ?C:HAS_PROCSELFEXE:
14 ?C:     This symbol is defined if PROCSELFEXE_PATH is a symlink
15 ?C:     to the absolute pathname of the executing program.
16 ?C:.
17 ?C:PROCSELFEXE_PATH:
18 ?C:     If HAS_PROCSELFEXE is defined this symbol is the filename
19 ?C:     of the symbolic link pointing to the absolute pathname of
20 ?C:     the executing program.
21 ?C:.
22 ?H:#$d_procselfexe HAS_PROCSELFEXE      /**/
23 ?H:?%<:#if defined(HAS_PROCSELFEXE) && !defined(PROCSELFEXE_PATH)
24 ?H:?%<:#define PROCSELFEXE_PATH $procselfexe    /**/
25 ?H:?%<:#endif
26 ?H:.
27 ?T:try type
28 ?LINT: set d_procselfexe
29 : Check if exe is symlink to abs path of executing program
30 echo " "
31 procselfexe=''
32 val="$undef"
33 case "$d_readlink" in
34     "$define")
35         : NetBSD first as /proc/self is a symlink to /proc/curproc, and it feels
36         : more tidy to avoid an extra level of symlink
37         set NetBSD /proc/curproc/exe Linux /proc/self/exe FreeBSD /proc/curproc/file Solaris /proc/self/path/a.out
38         while test $# -gt 0; do
39             type=$1; try=$2
40             shift; shift
41             if $issymlink $try; then
42                 $ls -l $try > reflect
43                 if $contains /`basename $ls` reflect >/dev/null 2>&1; then
44                     echo "You have $type-like $try."
45                     procselfexe='"'$try'"'
46                     val="$define"
47                     : This will break out of the loop
48                     set X; shift
49                 fi
50             fi
51         done
52         ;;
53 esac
54 $rm -f reflect
55 set d_procselfexe
56 eval $setvar
57