This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Backport Nicholas' changes to Configure for xs_extensions
[metaconfig.git] / U / perl / Extensions.U
1 ?RCS: $Id: Extensions.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 ?RCS: $Log: Extensions.U,v $
9 ?RCS:
10 ?MAKE:known_extensions extensions dynamic_ext static_ext nonxs_ext \
11         useposix useopcode : \
12         Myread hint usedl d_sem d_socket i_db i_dbm i_rpcsvcdbm i_gdbm \
13         d_ndbm usethreads use5005threads package test cat rsrc \
14         d_msg d_shm osname use64bitint i_langinfo d_nl_langinfo \
15         libs d_cplusplus sed ls rm contains trnl sort
16 ?MAKE:  -pick add $@ %<
17 ?Y:BOTTOM
18 ?S:known_extensions:
19 ?S:     This variable holds a list of all extensions (both XS and non-xs)
20 ?S:     included in the package source distribution.  This information is
21 ?S:     only really of use during the Perl build, as the list makes no
22 ?S:     distinction between extensions which were build and installed, and
23 ?S:     those which where not.  See "extensions" for the list of extensions
24 ?S:     actually built and available.
25 ?S:.
26 ?S:dynamic_ext:
27 ?S:     This variable holds a list of XS extension files we want to
28 ?S:     link dynamically into the package.  It is used by Makefile.
29 ?S:.
30 ?S:static_ext:
31 ?S:     This variable holds a list of XS extension files we want to
32 ?S:     link statically into the package.  It is used by Makefile.
33 ?S:.
34 ?S:nonxs_ext:
35 ?S:     This variable holds a list of all non-xs extensions built and
36 ?S:     installed by the package.  By default, all non-xs extensions
37 ?S:     distributed will be built, with the exception of platform-specific
38 ?S:     extensions (currently only one VMS specific extension).
39 ?S:.
40 ?S:extensions:
41 ?S:     This variable holds a list of all extension files (both XS and
42 ?S:     non-xs) installed with the package.  It is propagated to Config.pm
43 ?S:     and is typically used to test whether a particular extension
44 ?S:     is available.
45 ?S:.
46 ?S:useposix:
47 ?S:     This variable holds either 'true' or 'false' to indicate
48 ?S:     whether the POSIX extension should be used.  The sole
49 ?S:     use for this currently is to allow an easy mechanism
50 ?S:     for hints files to indicate that POSIX will not compile
51 ?S:     on a particular system.
52 ?S:.
53 ?S:useopcode:
54 ?S:     This variable holds either 'true' or 'false' to indicate
55 ?S:     whether the Opcode extension should be used.  The sole
56 ?S:     use for this currently is to allow an easy mechanism
57 ?S:     for users to skip the Opcode extension from the Configure
58 ?S:     command line.
59 ?S:.
60 ?T:xxx avail_ext this_ext tdir xs_extensions nonxs_extensions find_extensions
61 ?INIT:: set useposix=false in your hint file to disable the POSIX extension.
62 ?INIT:useposix=true
63 ?INIT:: set useopcode=false in your hint file to disable the Opcode extension.
64 ?INIT:useopcode=true
65 ?LINT:extern noextensions
66 ?LINT:extern onlyextensions
67 ?T:keepextensions i
68 : Check extensions
69 echo " "
70 echo "Looking for extensions..." >&4
71 : If we are using the old config.sh, nonxs_extensions and xs_extensions may
72 : contain old or inaccurate or duplicate values.
73 nonxs_extensions=''
74 xs_extensions=''
75 : We do not use find because it might not be available.
76 : We do not just use MANIFEST because the user may have dropped
77 : some additional extensions into the source tree and expect them
78 : to be built.
79
80 : Function to recursively find available extensions, ignoring DynaLoader
81 : NOTE: recursion limit of 10 to prevent runaway in case of symlink madness
82 : In 5.10.1 and later, extensions are stored in directories
83 : like File-Glob instead of the older File/Glob/.
84 find_extensions='
85     for xxx in *; do
86         case "$xxx" in
87             DynaLoader|dynaload) ;;
88             *)
89             this_ext=`echo $xxx | $sed -e s/-/\\\//g`;
90             echo " $xs_extensions $nonxs_extensions" > $$.tmp;
91             if $contains " $this_ext " $$.tmp; then
92                 echo >&4;
93                 echo "Duplicate directories detected for extension $xxx" >&4;
94                 echo "Configure cannot correctly recover from this - shall I abort?" >&4;
95                 case "$knowitall" in
96                 "") dflt=y;;
97                 *) dflt=n;;
98                 esac;
99                 . ../UU/myread;
100                 case "$ans" in
101                 n*|N*) ;;
102                 *) echo >&4;
103                     echo "Ok.  Stopping Configure." >&4;
104                     echo "Please remove the duplicate directory (e.g. using git clean) and then re-run Configure" >&4;
105                     exit 1;;
106                 esac;
107                 echo "Ok.  You will need to correct config.sh before running make." >&4;
108             fi;
109             $ls -1 $xxx > $$.tmp;
110             if   $contains "\.xs$" $$.tmp > /dev/null 2>&1; then
111                 xs_extensions="$xs_extensions $this_ext";
112             elif $contains "\.c$"  $$.tmp > /dev/null 2>&1; then
113                 xs_extensions="$xs_extensions $this_ext";
114             elif $test -d $xxx; then
115                 nonxs_extensions="$nonxs_extensions $this_ext";
116             fi;
117             $rm -f $$.tmp;
118             ;;
119         esac;
120     done'
121 tdir=`pwd`
122 cd "$rsrc/cpan"
123 set X
124 shift
125 eval $find_extensions
126 cd "$rsrc/dist"
127 set X
128 shift
129 eval $find_extensions
130 cd "$rsrc/ext"
131 set X
132 shift
133 eval $find_extensions
134 set X $xs_extensions
135 shift
136 xs_extensions=`echo "$*" | tr ' ' $trnl | $sort | tr $trnl ' '`
137 set X $nonxs_extensions
138 shift
139 nonxs_extensions=`echo "$*" | tr ' ' $trnl | $sort | tr $trnl ' '`
140 cd "$tdir"
141 known_extensions=`echo $nonxs_extensions $xs_extensions  | tr ' ' $trnl | $sort | tr $trnl ' '`
142
143 : Now see which are supported on this system.
144 ?X: avail_ext lists available XS extensions.
145 avail_ext=''
146 for xxx in $xs_extensions ; do
147         case "$xxx" in
148 ?X: Handle possible DOS 8.3 filename and case alterations
149         DB_File|db_file)
150                 case "$i_db" in
151                 $define) avail_ext="$avail_ext $xxx" ;;
152                 esac
153                 ;;
154         GDBM_File|gdbm_fil)
155                 case "$i_gdbm" in
156                 $define) avail_ext="$avail_ext $xxx" ;;
157                 esac
158                 ;;
159         I18N/Langinfo|i18n_lan)
160                 case "$i_langinfo$d_nl_langinfo" in
161                 $define$define) avail_ext="$avail_ext $xxx" ;;
162                 esac
163                 ;;
164         IPC/SysV|ipc/sysv)
165                 : XXX Do we need a useipcsysv variable here
166                 case "${d_msg}${d_sem}${d_shm}" in
167                 *"${define}"*) avail_ext="$avail_ext $xxx" ;;
168                 esac
169                 ;;
170         NDBM_File|ndbm_fil)
171                 case "$d_ndbm" in
172                 $define)
173                     case "$osname-$use64bitint" in
174                     hpux-define)
175                         case "$libs" in
176                         *-lndbm*) avail_ext="$avail_ext $xxx" ;;
177                         esac
178                         ;;
179                     *) avail_ext="$avail_ext $xxx" ;;
180                     esac
181                     ;;
182                 esac
183                 ;;
184         ODBM_File|odbm_fil)
185                 case "${i_dbm}${i_rpcsvcdbm}" in
186                 *"${define}"*)
187                     case "$d_cplusplus" in
188                     define) ;; # delete as a function name will not work
189                     *)  case "$osname-$use64bitint" in
190                         hpux-define)
191                             case "$libs" in
192                             *-ldbm*) avail_ext="$avail_ext $xxx" ;;
193                             esac
194                             ;;
195                         *) avail_ext="$avail_ext $xxx" ;;
196                         esac
197                         ;;
198                     esac
199                     ;;
200                 esac
201                 ;;
202         Opcode|opcode)
203                 case "$useopcode" in
204                 true|define|y) avail_ext="$avail_ext $xxx" ;;
205                 esac
206                 ;;
207         POSIX|posix)
208                 case "$useposix" in
209                 true|define|y) avail_ext="$avail_ext $xxx" ;;
210                 esac
211                 ;;
212         Socket|socket)
213                 case "$d_socket" in
214                 true|$define|y) avail_ext="$avail_ext $xxx" ;;
215                 esac
216                 ;;
217         Sys/Syslog|sys/syslog)
218                 : XXX syslog requires socket
219                 case "$d_socket" in
220                 true|$define|y) avail_ext="$avail_ext $xxx" ;;
221                 esac
222                 ;;
223         Thread|thread)
224                 case "$usethreads" in
225                 true|$define|y)
226                         case "$use5005threads" in
227                         $define|true|[yY]*) avail_ext="$avail_ext $xxx" ;;
228                         esac
229                 esac
230                 ;;
231         threads|threads/shared)
232                 # threads and threads::shared are special cases.
233                 # To stop people from asking "Perl 5.8.0 was supposed
234                 # to have this new fancy threads implementation but my
235                 # perl doesn't have it" and from people trying to
236                 # (re)install the threads module using CPAN.pm and
237                 # CPAN.pm then offering to reinstall Perl 5.8.0,
238                 # the threads.pm and threads/shared.pm will always be
239                 # there, croaking informatively ("you need to rebuild
240                 # all of Perl with threads, sorry") when threads haven't
241                 # been compiled in.
242                 # --jhi
243                 avail_ext="$avail_ext $xxx"
244                 ;;
245         VMS*)
246                 ;;
247         Win32*)
248                 case "$osname" in
249                 cygwin) avail_ext="$avail_ext $xxx" ;;
250                 esac
251                 ;;
252         XS/APItest|xs/apitest)
253                 # This is just for testing.  Skip it unless we have dynamic loading.
254
255                 case "$usedl" in
256                 $define) avail_ext="$avail_ext $xxx" ;;
257                 esac
258                 ;;
259         XS/Typemap|xs/typemap)
260                 # This is just for testing.  Skip it unless we have dynamic loading.
261                 case "$usedl" in
262                 $define) avail_ext="$avail_ext $xxx" ;;
263                 esac
264                 ;;
265         *)      avail_ext="$avail_ext $xxx"
266                 ;;
267         esac
268 done
269
270 set X $avail_ext
271 shift
272 avail_ext="$*"
273
274 case "$onlyextensions" in
275 '') ;;
276 *)  keepextensions=''
277     echo "You have requested that only certain extensions be included..." >&4
278     for i in $onlyextensions; do
279         case " $avail_ext " in
280         *" $i "*)
281             echo "Keeping extension $i."
282             keepextensions="$keepextensions $i"
283             ;;
284         *) echo "Ignoring extension $i." ;;
285         esac
286     done
287     avail_ext="$keepextensions"
288     ;;
289 esac
290
291 case "$noextensions" in
292 '') ;;
293 *)  keepextensions=''
294     echo "You have requested that certain extensions be ignored..." >&4
295     for i in $avail_ext; do
296         case " $noextensions " in
297         *" $i "*) echo "Ignoring extension $i." ;;
298         *) echo "Keeping extension $i.";
299            keepextensions="$keepextensions $i"
300            ;;
301         esac
302     done
303     avail_ext="$keepextensions"
304     ;;
305 esac
306
307 : Now see which nonxs extensions are supported on this system.
308 : For now assume all are.
309 nonxs_ext=''
310 for xxx in $nonxs_extensions ; do
311         case "$xxx" in
312         VMS*)
313                 ;;
314         *)      nonxs_ext="$nonxs_ext $xxx"
315                 ;;
316         esac
317 done
318
319 set X $nonxs_ext
320 shift
321 nonxs_ext="$*"
322
323 case $usedl in
324 $define)
325         $cat <<EOM
326 A number of extensions are supplied with $package.  You may choose to
327 compile these extensions for dynamic loading (the default), compile
328 them into the $package executable (static loading), or not include
329 them at all.  Answer "none" to include no extensions.
330 Note that DynaLoader is always built and need not be mentioned here.
331
332 EOM
333         case "$dynamic_ext" in
334         '')
335                 : Exclude those listed in static_ext
336                 dflt=''
337                 for xxx in $avail_ext; do
338                         case " $static_ext " in
339                         *" $xxx "*) ;;
340                         *) dflt="$dflt $xxx" ;;
341                         esac
342                 done
343                 set X $dflt
344                 shift
345                 dflt="$*"
346                 ;;
347         *)      dflt="$dynamic_ext"
348                 # Perhaps we are reusing an old out-of-date config.sh.
349                 case "$hint" in
350                 previous)
351                         if test X"$dynamic_ext" != X"$avail_ext"; then
352                                 $cat <<EOM
353 NOTICE:  Your previous config.sh list may be incorrect.
354 The extensions now available to you are
355         ${avail_ext}
356 but the default list from your previous config.sh is
357         ${dynamic_ext}
358
359 EOM
360                         fi
361                         ;;
362                 esac
363                 ;;
364         esac
365         case "$dflt" in
366         '')     dflt=none;;
367         esac
368         rp="What extensions do you wish to load dynamically?"
369         . ./myread
370         case "$ans" in
371 ?X: Use ' ' so a subsequent Configure will preserve that value.
372         none) dynamic_ext=' ' ;;
373         *) dynamic_ext="$ans" ;;
374         esac
375
376         case "$static_ext" in
377         '')
378                 : Exclude those already listed in dynamic linking
379                 dflt=''
380                 for xxx in $avail_ext; do
381                         case " $dynamic_ext " in
382                         *" $xxx "*) ;;
383                         *) dflt="$dflt $xxx" ;;
384                         esac
385                 done
386                 set X $dflt
387                 shift
388                 dflt="$*"
389                 ;;
390         *)  dflt="$static_ext"
391                 ;;
392         esac
393
394         case "$dflt" in
395         '')     dflt=none;;
396         esac
397         rp="What extensions do you wish to load statically?"
398         . ./myread
399         case "$ans" in
400 ?X: Use ' ' so a subsequent Configure will preserve that value.
401         none) static_ext=' ' ;;
402         *) static_ext="$ans" ;;
403         esac
404         ;;
405 *)
406         $cat <<EOM
407 A number of extensions are supplied with $package.  Answer "none"
408 to include no extensions.
409 Note that DynaLoader is always built and need not be mentioned here.
410
411 EOM
412         case "$static_ext" in
413         '') dflt="$avail_ext" ;;
414         *)      dflt="$static_ext"
415                 # Perhaps we are reusing an old out-of-date config.sh.
416                 case "$hint" in
417                 previous)
418                         if test X"$static_ext" != X"$avail_ext"; then
419                                 $cat <<EOM
420 NOTICE:  Your previous config.sh list may be incorrect.
421 The extensions now available to you are
422         ${avail_ext}
423 but the default list from your previous config.sh is
424         ${static_ext}
425
426 EOM
427                         fi
428                         ;;
429                 esac
430                 ;;
431         esac
432         : Exclude those that are not xs extensions
433         case "$dflt" in
434         '')     dflt=none;;
435         esac
436         rp="What extensions do you wish to include?"
437         . ./myread
438         case "$ans" in
439 ?X: Use ' ' so a subsequent Configure will preserve that value.
440         none) static_ext=' ' ;;
441         *) static_ext="$ans" ;;
442         esac
443         ;;
444 esac
445 #
446 # Encode is a special case.  If we are building Encode as a static
447 # extension, we need to explicitly list its subextensions as well.
448 # For other nested extensions, this is handled automatically by
449 # the appropriate Makefile.PL.
450 case " $static_ext " in
451         *" Encode "*) # Add the subextensions of Encode
452         cd "$rsrc/cpan"
453         for xxx in `ls Encode/*/Makefile.PL|awk -F/ '{print $2}'`; do
454                 static_ext="$static_ext Encode/$xxx"
455                 known_extensions="$known_extensions Encode/$xxx"
456         done
457         cd "$tdir"
458         ;;
459 esac
460
461 set X $dynamic_ext $static_ext $nonxs_ext
462 shift
463 extensions="$*"
464
465 # Sanity check:  We require an extension suitable for use with
466 # AnyDBM_File, as well as Fcntl and IO.  (Failure to have these
467 # should show up as failures in the test suite, but it's helpful to
468 # catch them now.) The 'extensions' list is normally sorted
469 # alphabetically, so we need to accept either
470 #    DB_File ... Fcntl ... IO  ....
471 # or something like
472 #    Fcntl ... NDBM_File ... IO  ....
473 case " $extensions"  in
474 *"_File "*" Fcntl "*" IO "*) ;; # DB_File
475 *" Fcntl "*"_File "*" IO "*) ;; # GDBM_File
476 *" Fcntl "*" IO "*"_File "*) ;; # NDBM_File
477 *) echo "WARNING: Extensions DB_File or *DBM_File, Fcntl, and IO not configured." >&4
478    echo "WARNING: The Perl you are building will be quite crippled." >& 4
479    ;;
480 esac
481