This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / dist-3.0at70 / mcon / pl / depend.pl
1 ;# $Id: depend.pl,v 3.0.1.3 1995/09/25 09:18:56 ram Exp $
2 ;#
3 ;#  Copyright (c) 1991-1993, Raphael Manfredi
4 ;#  
5 ;#  You may redistribute only under the terms of the Artistic Licence,
6 ;#  as specified in the README file that comes with the distribution.
7 ;#  You may reuse parts of this distribution only within the terms of
8 ;#  that same Artistic Licence; a copy of which may be found at the root
9 ;#  of the source tree for dist 3.0.
10 ;#
11 ;# $Log: depend.pl,v $
12 ;# Revision 3.0.1.3  1995/09/25  09:18:56  ram
13 ;# patch59: new ?Y: directive to change unit layout
14 ;#
15 ;# Revision 3.0.1.2  1994/10/29  16:35:23  ram
16 ;# patch36: added various escapes in strings for perl5 support
17 ;#
18 ;# Revision 3.0.1.1  1993/10/16  13:54:35  ram
19 ;# patch12: added minimal support for ?P: lines (not ready yet)
20 ;#
21 ;# Revision 3.0  1993/08/18  12:10:21  ram
22 ;# Baseline for dist 3.0 netwide release.
23 ;#
24 ;# Metaconfig-dependent part of the dependency extraction.
25 ;#
26 # Process the ?W: lines
27 sub p_wanted {
28         # Syntax is ?W:<shell symbols>:<C symbols>
29         local($active) = $_[0] =~ /^([^:]*):/;          # Symbols to activate
30         local($look_symbols) = $_[0] =~ /:(.*)/;        # When those are used
31         local(@syms) = split(/ /, $look_symbols);       # Keep original spacing info
32         $active =~ s/\s+/\n/g;                                          # One symbol per line
33
34         # Concatenate quoted strings, so saying something like 'two words' will
35         # be introduced as one single symbol "two words".
36         local(@symbols);                                # Concatenated symbols to look for
37         local($concat) = '';                    # Concatenation buffer
38         foreach (@syms) {
39                 if (s/^\'//) {
40                         $concat = $_;
41                 } elsif (s/\'$//) {
42                         push(@symbols, $concat . ' ' . $_);
43                         $concat = '';
44                 } else {
45                         push(@symbols, $_) unless $concat;
46                         $concat .= ' ' . $_ if $concat;
47                 }
48         }
49
50         # Now record symbols in master and wanted tables
51         foreach (@symbols) {
52                 $cmaster{$_} = undef;                                   # Asks for look-up in C files
53                 $cwanted{$_} = "$active" if $active;    # Shell symbols to activate
54         }
55 }
56
57 # Process the ?INIT: lines
58 sub p_init {
59         local($_) = @_;
60         print INIT "?$unit:", $_;               # Wanted only if unit is loaded
61 }
62
63 # Process the ?D: lines
64 sub p_default {
65         local($_) = @_;
66         s/^([A-Za-z_]+)=(.*)/\@if !$1\n%$1:$1=$2\n\@define $1\n\@end/
67                 && ($hasdefault{$1}++, print INIT $_);
68 }
69
70 # Process the ?P: lines
71 sub p_public {
72         local($_) = @_;
73         local($csym);                                   # C symbol(s) we're trying to look at
74         local($nosym);                                  # List of symbol(s) which mustn't be wanted
75         local($cfile);                                  # Name of file implementing csym (no .ext)
76         ($csym, $nosym, $cfile) = /([^()]+)\s*(\(.*\))\s*:\s*(\S+)/;
77         unless ($csym eq '' || $cfile eq '') {
78                 # Add dependencies for each C symbol, of the form:
79                 #       -pick public <sym> <file> <notdef symbols list>
80                 # and the file will be added to config.c whenever sym is wanted and
81                 # none of the notdef symbols is wanted.
82                 foreach $sym (split(' ', $csym)) {
83                         $dependencies .= "\t-pick public $sym $cfile $nosym\n";
84                 }
85         }
86 }
87
88 # Process the ?Y: lines
89 # Valid layouts are for now are: top, bottom, default.
90 #
91 # NOTA BENE:
92 # This routine relies on the $defined variable, a global variable set
93 # during the ?MAKE: processing, which lists all the defined symbols in
94 # the unit (the optional leading '+' for internal symbols has been removed
95 # if present).
96 #
97 # The routine fills up a %Layout table, indexed by symbol, yielding the
98 # layout imposed to this unit. That table will then be used later on when
99 # we sort wanted symbols for the Makefile.
100 sub p_layout {
101         local($_) = @_;
102         local($layout) = /^\s*(\w+)/;
103         $layout =~ tr/A-Z/a-z/;         # Case is not significant for layouts
104         unless (defined $Lcmp{$layout}) {
105                 warn "\"$file\", line $.: unknown layout directive '$layout'.\n";
106                 return;
107         }
108         foreach $sym (split(' ', $defined)) {
109                 $Layout{$sym} = $Lcmp{$layout};
110         }
111 }
112
113 # Process the ?L: lines
114 # There should not be any '-l' in front of the library name
115 sub p_library {
116         &write_out("L:$_");
117 }
118
119 # Process the ?I: lines
120 sub p_include {
121         &write_out("I:$_");
122 }
123
124 # Write out line in file Extern.U. The information recorded there has the
125 # following prototypical format:
126 #   ?symbol:L:inet bsd
127 # If 'symbol' is wanted, then 'inet bsd' will be added to $libswanted.
128 sub write_out {
129         local($_) = @_;
130         local($target) = $defined;              # By default, applies to defined symbols
131         $target = $1 if s/^(.*)://;             # List is qualified "?L:target:symbols"
132         local(@target) = split(' ', $target);
133         chop;
134         foreach $key (@target) {
135                 print EXTERN "?$key:$_\n";      # EXTERN file defined in xref.pl
136         }
137 }
138