This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
91a2b3b8cc3b82e01486573eccde01e7cf50f3ee
[metaconfig.git] / U / perl / libperl.U
1 ?RCS: $Id: libperl.U,v $
2 ?RCS:
3 ?RCS: Copyright (c) 1996-1998, Andy Dougherty
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?MAKE:libperl useshrplib shrpenv ldlibpthname: \
9         Myread Oldconfig archlibexp awk cat libc \
10         _a osname osvers so patchlevel subversion usedl ld \
11         ccdlflags installarchlib userelocatableinc
12 ?MAKE:  -pick wipe $@ %<
13 ?S:libperl:
14 ?S:     The perl executable is obtained by linking perlmain.c with
15 ?S:     libperl, any static extensions (usually just DynaLoader),
16 ?S:     and any other libraries needed on this system.  libperl
17 ?S:     is usually libperl.a, but can also be libperl.so.xxx if
18 ?S:     the user wishes to build a perl executable with a shared
19 ?S:     library.
20 ?S:.
21 ?S:useshrplib:
22 ?S:     This variable is set to 'true' if the user wishes
23 ?S:     to build a shared libperl, and 'false' otherwise.
24 ?S:.
25 ?S:shrpenv:
26 ?S:     If the user builds a shared libperl.so, then we need to tell the
27 ?S:     'perl' executable where it will be able to find the installed libperl.so.
28 ?S:     One way to do this on some systems is to set the environment variable
29 ?S:     LD_RUN_PATH to the directory that will be the final location of the
30 ?S:     shared libperl.so.  The makefile can use this with something like
31 ?S:             $shrpenv $(CC) -o perl perlmain.o $libperl $libs
32 ?S:     Typical values are
33 ?S:             shrpenv="env LD_RUN_PATH=$archlibexp/CORE"
34 ?S:     or
35 ?S:             shrpenv=''
36 ?S:     See the main perl Makefile.SH for actual working usage.
37 ?S: Alternatively, we might be able to use a command line option such
38 ?S:     as -R $archlibexp/CORE (Solaris) or -Wl,-rpath
39 ?S:     $archlibexp/CORE (Linux).
40 ?S:.
41 ?S:ldlibpthname:
42 ?S:     This variable holds the name of the shared library
43 ?S:     search path, often LD_LIBRARY_PATH.  To get an empty
44 ?S:     string, the hints file must set this to 'none'.
45 ?S:.
46 ?T:shrpdir majonly majmin also xxx tmp_shrpenv
47 ?X: metalint gets confused and thinks we're actually setting LDOPTS
48 ?X: and LD_RUN_PATH.
49 ?LINT:extern LDOPTS
50 ?LINT:change LDOPTS
51 ?LINT:extern LD_RUN_PATH
52 ?LINT:change LD_RUN_PATH
53 ?LINT:change ccdlflags
54 ?LINT:extern maintloc maintname
55 ?Y:top
56 : Do we want a shared libperl?
57 also=''
58 case "$usedl" in
59 $undef)
60         # No dynamic loading being used, so don't bother even to prompt.
61         useshrplib='false'
62         ;;
63 *)      case "$useshrplib" in
64         '')     case "$osname" in
65                 svr4*|nonstopux|dgux|dynixptx|esix|powerux|haiku|cygwin*)
66                         dflt=y
67                         also='Building a shared libperl is required for dynamic loading to work on your system.'
68                         ;;
69                 *)      dflt=n
70                         ;;
71                 esac
72                 ;;
73         $define|true|[Yy]*)
74                 dflt=y
75                 ;;
76         *)      dflt=n
77                 ;;
78         esac
79         $cat << EOM
80
81 The perl executable is normally obtained by linking perlmain.c with
82 libperl${_a}, any static extensions (usually just DynaLoader), and
83 any other libraries needed on this system (such as -lm, etc.).  Since
84 your system supports dynamic loading, it is probably possible to build
85 a shared libperl.$so.  If you will have more than one executable linked
86 to libperl.$so, this will significantly reduce the size of each
87 executable, but it may have a noticeable effect on performance.  The
88 default is probably sensible for your system.
89 $also
90
91 EOM
92         rp="Build a shared libperl.$so (y/n)"
93         . ./myread
94         case "$ans" in
95         true|$define|[Yy]*)
96                 useshrplib='true'  ;;
97         *)      useshrplib='false' ;;
98         esac
99         ;;
100 esac
101
102 case "$useshrplib" in
103 true)
104         case "$userelocatableinc" in
105         true|define)
106                 echo "Cannot build with both -Duserelocatableinc and -Duseshrplib" >&4
107                 echo "See INSTALL for an explanation why that won't work." >&4
108                 exit 4
109                 ;;
110         esac
111         case "$libperl" in
112         '')
113                 # Figure out a good name for libperl.so.  Since it gets stored in
114                 # a version-specific architecture-dependent library, the version
115                 # number isn't really that important, except for making cc/ld happy.
116                 #
117                 # A name such as libperl.so.10.1
118                 majmin="libperl.$so.$patchlevel.$subversion"
119                 # A name such as libperl.so.100
120                 majonly=`echo $patchlevel $subversion |
121                         $awk '{printf "%d%02d", $1, $2}'`
122                 majonly=libperl.$so.$majonly
123                 # I'd prefer to keep the os-specific stuff here to a minimum, and
124                 # rely on figuring it out from the naming of libc.
125                 case "${osname}${osvers}" in
126                 *linux*|gnu*)  # ld won't link with a bare -lperl otherwise.
127                         dflt=libperl.$so
128                         ;;
129                 cygwin*) # ld links now against the dll directly
130                         majmin="cygperl5_${patchlevel}_${subversion}.${so}"
131                         majonly=`echo $patchlevel $subversion |
132                                 $awk '{printf "%03d%03d", $1, $2}'`
133                         majonly=cygperl5.$majonly.$so
134                         dflt=$majmin
135                         ;;
136                 *)      # Try to guess based on whether libc has major.minor.
137                         case "$libc" in
138                         *libc.$so.[0-9]*.[0-9]*) dflt=$majmin ;;
139                         *libc.$so.[0-9]*) dflt=$majonly ;;
140                         *)      dflt=libperl.$so ;;
141                         esac
142                         ;;
143                 esac
144                 ;;
145         *)      dflt=$libperl
146                 ;;
147         esac
148         cat << EOM
149
150 I need to select a good name for the shared libperl.  If your system uses
151 library names with major and minor numbers, then you might want something
152 like $majmin.  Alternatively, if your system uses a single version
153 number for shared libraries, then you might want to use $majonly.
154 Or, your system might be quite happy with a simple libperl.$so.
155
156 Since the shared libperl will get installed into a version-specific
157 architecture-dependent directory, the version number of the shared perl
158 library probably isn't important, so the default should be o.k.
159
160 EOM
161         rp='What name do you want to give to the shared libperl?'
162         . ./myread
163         libperl=$ans
164         echo "Ok, I'll use $libperl"
165         ;;
166 *)
167         libperl="libperl${_a}"
168         ;;
169 esac
170
171 # Detect old use of shrpdir via undocumented Configure -Dshrpdir
172 case "$shrpdir" in
173 '') ;;
174 *)      $cat >&4 <<EOM
175 WARNING:  Use of the shrpdir variable for the installation location of
176 the shared $libperl is not supported.  It was never documented and
177 will not work in this version.  Let me (<$maintloc>)
178 know of any problems this may cause.
179
180 EOM
181         case "$shrpdir" in
182         "$archlibexp/CORE")
183                 $cat >&4 <<EOM
184 But your current setting of $shrpdir is
185 the default anyway, so it's harmless.
186 EOM
187                 ;;
188         *)
189                 $cat >&4 <<EOM
190 Further, your current attempted setting of $shrpdir
191 conflicts with the value of $archlibexp/CORE
192 that installperl will use.
193 EOM
194                 ;;
195         esac
196         ;;
197 esac
198
199 # How will the perl executable find the installed shared $libperl?
200 # Add $xxx to ccdlflags.
201 # If we can't figure out a command-line option, use $shrpenv to
202 # set env LD_RUN_PATH.  The main perl makefile uses this.
203 shrpdir=$archlibexp/CORE
204 xxx=''
205 tmp_shrpenv=''
206 if "$useshrplib"; then
207     case "$osname" in
208         aix)
209                 # We'll set it in Makefile.SH...
210                 ;;
211         solaris)
212                 xxx="-R $shrpdir"
213                 ;;
214         freebsd|mirbsd|netbsd|openbsd|interix|dragonfly|bitrig)
215                 xxx="-Wl,-R$shrpdir"
216                 ;;
217         bsdos|linux|irix*|dec_osf|gnu*)
218                 xxx="-Wl,-rpath,$shrpdir"
219                 ;;
220         haiku)
221                 # Haiku doesn't like the default, either.
222                 ;;
223         hpux*)
224                 # hpux doesn't like the default, either.
225                 tmp_shrpenv="env LDOPTS=\"+s +b${shrpdir}\""
226                 ;;
227         cygwin)
228                 # cygwin needs only ldlibpth
229                 ;;
230         *)
231                 tmp_shrpenv="env LD_RUN_PATH=$shrpdir"
232                 ;;
233         esac
234         case "$xxx" in
235         '') ;;
236         *)
237                 # Only add $xxx if it isn't already in ccdlflags.
238                 case " $ccdlflags " in
239                 *" $xxx "*)     ;;
240                 *)      ccdlflags="$ccdlflags $xxx"
241                         cat <<EOM >&4
242
243 Adding $xxx to the flags
244 passed to $ld so that the perl executable will find the
245 installed shared $libperl.
246
247 EOM
248                         ;;
249                 esac
250                 ;;
251         esac
252 fi
253 # Fix ccdlflags in AIX for building external extensions.
254 # (For building Perl itself bare -bE:perl.exp is needed,
255 #  Makefile.SH takes care of this.)
256 case "$osname" in
257 aix) ccdlflags="$ccdlflags -bE:$installarchlib/CORE/perl.exp" ;;
258 esac
259 # Respect a hint or command-line value.
260 case "$shrpenv" in
261 '') shrpenv="$tmp_shrpenv" ;;
262 esac
263 case "$ldlibpthname" in
264 '')     ldlibpthname=LD_LIBRARY_PATH ;;
265 none)   ldlibpthname='' ;;
266 esac
267