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