Don't treat .d (depend) files separately from object files
[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      }
47  }
48
49  # dolib is responsible for building libraries.  It will call
50  # libobj2shlib is shared libraries are produced, and obj2lib in all
51  # cases.  It also makes sure all object files for the library are
52  # built.
53  sub dolib {
54      my $lib = shift;
55      if (!$config{no_shared}) {
56          my %ordinals =
57              $unified_info{ordinals}->{$lib}
58              ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
59          $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
60                               lib => $lib,
61                               objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
62                                         @{$unified_info{sources}->{$lib}} ],
63                               deps => [ reducedepends(resolvedepends($lib)) ],
64                               %ordinals);
65      }
66      $OUT .= obj2lib(lib => $lib,
67                      objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
68                                @{$unified_info{sources}->{$lib}} ]);
69      map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
70  }
71
72  # doengine is responsible for building engines.  It will call
73  # obj2dynlib, and also makes sure all object files for the library
74  # are built.
75  sub doengine {
76      my $lib = shift;
77      $OUT .= obj2dynlib(lib => $lib,
78                         objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
79                                   @{$unified_info{sources}->{$lib}} ],
80                         deps => [ resolvedepends($lib) ]);
81      map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
82  }
83
84  # dobin is responsible for building programs.  It will call obj2bin,
85  # and also makes sure all object files for the library are built.
86  sub dobin {
87      my $bin = shift;
88      my $deps = [ reducedepends(resolvedepends($bin)) ];
89      $OUT .= obj2bin(bin => $bin,
90                      objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
91                                @{$unified_info{sources}->{$bin}} ],
92                      deps => $deps);
93      map { doobj($_, $bin, intent => "bin") } @{$unified_info{sources}->{$bin}};
94  }
95
96  # dobin is responsible for building scripts from templates.  It will
97  # call in2script.
98  sub doscript {
99      my $script = shift;
100      $OUT .= in2script(script => $script,
101                        sources => $unified_info{sources}->{$script});
102  }
103
104  # Build all known libraries, engines, programs and scripts.
105  # Everything else will be handled as a consequence.
106  map { dolib($_) } @{$unified_info{libraries}};
107  map { doengine($_) } @{$unified_info{engines}};
108  map { dobin($_) } @{$unified_info{programs}};
109  map { doscript($_) } @{$unified_info{scripts}};
110
111  # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
112  # they are added here.
113  $OUT .= $_."\n" foreach(@{$unified_info{rawlines}});
114 -}