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