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