Unified - Add the build.info command OVERRIDE, to avoid build file clashes
[openssl.git] / Configurations / common.tmpl
1 {- # -*- Mode: perl -*-
2
3      # A cache of objects for which a recipe has already been generated
4      my %cache;
5
6  # resolvedepends and reducedepends work in tandem to make sure
7  # there are no duplicate dependencies and that they are in the
8  # right order.  This is especially used to sort the list of
9  # libraries that a build depends on.
10  sub resolvedepends {
11      my $thing = shift;
12      my @listsofar = @_;    # to check if we're looping
13      my @list = @{$unified_info{depends}->{$thing}};
14      my @newlist = ();
15      if (scalar @list) {
16          foreach my $item (@list) {
17              # It's time to break off when the dependency list starts looping
18              next if grep { $_ eq $item } @listsofar;
19              push @newlist, $item, resolvedepends($item, @listsofar, $item);
20          }
21      }
22      @newlist;
23  }
24  sub reducedepends {
25      my @list = @_;
26      my @newlist = ();
27      while (@list) {
28          my $item = shift @list;
29          push @newlist, $item
30              unless grep { $item eq $_ } @list;
31      }
32      @newlist;
33  }
34
35  sub dogenerate {
36      my $src = shift;
37      return "" if $cache{$src};
38      my %opts = @_;
39      if ($unified_info{generate}->{$src}) {
40          $OUT .= generatesrc(src => $src,
41                              generator => $unified_info{generate}->{$src},
42                              deps => $unified_info{depends}->{$src},
43                              %opts);
44          foreach (@{$unified_info{depends}->{$src}}) {
45              dogenerate($_, %opts);
46          }
47      }
48      $cache{$src} = 1;
49  }
50
51  # doobj is responsible for producing all the recipes that build
52  # object files as well as dependency files.
53  sub doobj {
54      my $obj = shift;
55      return "" if $cache{$obj};
56      (my $obj_no_o = $obj) =~ s|\.o$||;
57      my $bin = shift;
58      my %opts = @_;
59      if (@{$unified_info{sources}->{$obj}}) {
60          $OUT .= src2obj(obj => $obj_no_o,
61                          srcs => $unified_info{sources}->{$obj},
62                          deps => $unified_info{depends}->{$obj},
63                          incs => [ @{$unified_info{includes}->{$bin}},
64                                    @{$unified_info{includes}->{$obj}} ],
65                          %opts);
66          foreach ((@{$unified_info{sources}->{$obj}},
67                    @{$unified_info{depends}->{$obj}})) {
68              dogenerate($_, %opts);
69          }
70      }
71      $cache{$obj} = 1;
72  }
73
74  # dolib is responsible for building libraries.  It will call
75  # libobj2shlib is shared libraries are produced, and obj2lib in all
76  # cases.  It also makes sure all object files for the library are
77  # built.
78  sub dolib {
79      my $lib = shift;
80      return "" if $cache{$lib};
81      unless ($disabled{shared}) {
82          my %ordinals =
83              $unified_info{ordinals}->{$lib}
84              ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
85          $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
86                               lib => $lib,
87                               objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
88                                         @{$unified_info{sources}->{$lib}} ],
89                               deps => [ reducedepends(resolvedepends($lib)) ],
90                               %ordinals);
91      }
92      $OUT .= obj2lib(lib => $lib,
93                      objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
94                                @{$unified_info{sources}->{$lib}} ]);
95      map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
96      $cache{$lib} = 1;
97  }
98
99  # doengine is responsible for building engines.  It will call
100  # obj2dso, and also makes sure all object files for the library
101  # are built.
102  sub doengine {
103      my $lib = shift;
104      return "" if $cache{$lib};
105      $OUT .= obj2dso(lib => $lib,
106                      objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
107                                @{$unified_info{sources}->{$lib}} ],
108                      deps => [ resolvedepends($lib) ]);
109      map { doobj($_, $lib, intent => "dso") } @{$unified_info{sources}->{$lib}};
110      $cache{$lib} = 1;
111  }
112
113  # dobin is responsible for building programs.  It will call obj2bin,
114  # and also makes sure all object files for the library are built.
115  sub dobin {
116      my $bin = shift;
117      return "" if $cache{$bin};
118      my $deps = [ reducedepends(resolvedepends($bin)) ];
119      $OUT .= obj2bin(bin => $bin,
120                      objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
121                                @{$unified_info{sources}->{$bin}} ],
122                      deps => $deps);
123      map { doobj($_, $bin, intent => "bin") } @{$unified_info{sources}->{$bin}};
124      $cache{$bin} = 1;
125  }
126
127  # dobin is responsible for building scripts from templates.  It will
128  # call in2script.
129  sub doscript {
130      my $script = shift;
131      return "" if $cache{$script};
132      $OUT .= in2script(script => $script,
133                        sources => $unified_info{sources}->{$script});
134      $cache{$script} = 1;
135  }
136
137  # Start with populating the cache with all the overrides
138  %cache = map { $_ => 1 } @{$unified_info{overrides}};
139
140  # Build all known libraries, engines, programs and scripts.
141  # Everything else will be handled as a consequence.
142  map { dolib($_) } @{$unified_info{libraries}};
143  map { doengine($_) } @{$unified_info{engines}};
144  map { dobin($_) } @{$unified_info{programs}};
145  map { doscript($_) } @{$unified_info{scripts}};
146
147  # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
148  # they are added here.
149  $OUT .= $_."\n" foreach(@{$unified_info{rawlines}});
150 -}