Unified - Add the build.info command GENERATE, to generate source files
authorRichard Levitte <levitte@openssl.org>
Mon, 7 Mar 2016 13:37:00 +0000 (14:37 +0100)
committerRichard Levitte <levitte@openssl.org>
Mon, 7 Mar 2016 17:25:56 +0000 (18:25 +0100)
In some cases, one might want to generate some source files from
others, that's done as follows:

    GENERATE[foo.s]=asm/something.pl $(CFLAGS)
    GENERATE[bar.s]=asm/bar.S

The value of each GENERATE line is a command line or part of it.
Configure places no rules on the command line, except the the first
item muct be the generator file.  It is, however, entirely up to the
build file template to define exactly how those command lines should
be handled, how the output is captured and so on.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Configurations/README
Configurations/README.design
Configurations/common.tmpl
Configure

index afc60049d18478643a40d770a9ccf3264283a903..40875a3ba2bba11f52957924239bb652279a8da6 100644 (file)
@@ -363,8 +363,22 @@ include paths the build of their source files should use:
 
     INCLUDE[foo]=include
 
-It's possible to have raw build file lines, between BEGINRAW and
-ENDRAW lines as follows:
+In some cases, one might want to generate some source files from
+others, that's done as follows:
+
+    GENERATE[foo.s]=asm/something.pl $(CFLAGS)
+    GENERATE[bar.s]=asm/bar.S
+
+The value of each GENERATE line is a command line or part of it.
+Configure places no rules on the command line, except the the first
+item muct be the generator file.  It is, however, entirely up to the
+build file template to define exactly how those command lines should
+be handled, how the output is captured and so on.
+
+NOTE: GENERATE lines are limited to one command only per GENERATE.
+
+As a last resort, it's possible to have raw build file lines, between
+BEGINRAW and ENDRAW lines as follows:
 
     BEGINRAW[Makefile(unix)]
     haha.h: {- $builddir -}/Makefile
@@ -461,6 +475,26 @@ The build-file template is expected to define at least the following
 perl functions in a perl code fragment enclosed with "{-" and "-}".
 They are all expected to return a string with the lines they produce.
 
+    generatesrc - function that produces build file lines to generate
+                  a source file from some input.
+
+                  It's called like this:
+
+                        generatesrc(src => "PATH/TO/tobegenerated",
+                                    generator => [ "generatingfile", ... ]
+                                    deps => [ "dep1", ... ],
+                                    intent => one of "libs", "dso", "bin" );
+
+                  'src' has the name of the file to be generated.
+                  'generator' is the command or part of command to
+                  generate the file, of which the first item is
+                  expected to be the file to generate from.
+                  generatesrc() is expected to analyse and figure out
+                  exactly how to apply that file and how to capture
+                  the result.  'deps' is a list of explicit
+                  dependencies.  'intent' indicates what the generated
+                  file is going to be used for.
+
     src2obj     - function that produces build file lines to build an
                   object file from source files and associated data.
 
index 5a28ef3271c3155e29794dd86135510301a52f6c..5065960a764aa63a3c8a42a2ee10ba16169d1cbc 100644 (file)
@@ -89,11 +89,8 @@ depends on the library 'libssl' to function properly.
     SOURCE[../libcrypto]=aes.c evp.c cversion.c
     DEPEND[cversion.o]=buildinf.h
     
-    BEGINRAW[Makefile(unix)]
-    crypto/buildinf.h : Makefile
-       perl util/mkbuildinf.h "$(CC) $(CFLAGS)" "$(PLATFORM)" \
-           > crypto/buildinf.h
-    ENDRAW[Makefile(unix)]
+    GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)"
+    DEPEND[buildinf.h]=../Makefile
 
 This is the build.info file in 'crypto', and it tells us a little more
 about what's needed to produce 'libcrypto'.  LIBS is used again to
@@ -161,11 +158,8 @@ information comes down to this:
     DEPEND[engines/libossltest]=libcrypto
     INCLUDE[engines/libossltest]=include
     
-    BEGINRAW[Makefile(unix)]
-    crypto/buildinf.h : Makefile
-       perl util/mkbuildinf.h "$(CC) $(CFLAGS)" "$(PLATFORM)" \
-           > crypto/buildinf.h
-    ENDRAW[Makefile(unix)]
+    GENERATE[crypto/buildinf.h]=util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)"
+    DEPEND[crypto/buildinf.h]=Makefile
 
 
 A few notes worth mentioning:
@@ -180,7 +174,7 @@ The indexes for SOURCE, INCLUDE and ORDINALS must only be end product
 files, such as libraries, programs or engines.  The values of SOURCE
 variables must only be source files (possibly generated)
 
-DEPEND shows a relationship between different end product files, such
+DEPEND shows a relationship between different produced files, such
 as a program depending on a library, or between an object file and
 some extra source file.
 
index 7e452dd28fae7aa08fcbb2230691f703f57bd99e..b97abfb32374382fe034b6d5a3bfc2dbfe0cd282 100644 (file)
      @newlist;
  }
 
+ sub dogenerate {
+     my $src = shift;
+     return "" if $cache{$src};
+     my %opts = @_;
+     if ($unified_info{generate}->{$src}) {
+         $OUT .= generatesrc(src => $src,
+                             generator => $unified_info{generate}->{$src},
+                             deps => $unified_info{depends}->{$src},
+                             %opts);
+         foreach (@{$unified_info{depends}->{$src}}) {
+             dogenerate($_, %opts);
+         }
+     }
+     $cache{$src} = 1;
+ }
+
  # doobj is responsible for producing all the recipes that build
  # object files as well as dependency files.
  sub doobj {
      if (@{$unified_info{sources}->{$obj}}) {
          $OUT .= src2obj(obj => $obj_no_o,
                          srcs => $unified_info{sources}->{$obj},
-                         deps => [ reducedepends(resolvedepends($obj)) ],
+                         deps => $unified_info{depends}->{$obj},
                          incs => [ @{$unified_info{includes}->{$bin}},
                                    @{$unified_info{includes}->{$obj}} ],
                          %opts);
+         foreach ((@{$unified_info{sources}->{$obj}},
+                   @{$unified_info{depends}->{$obj}})) {
+             dogenerate($_, %opts);
+         }
      }
      $cache{$obj} = 1;
  }
index 174fe150c83d3a5e2015fe32be01e6dc72563a79..da9e5a3979525b262b588f9f9065ebc57ce3b7b2 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -1283,6 +1283,7 @@ if ($builder eq "unified") {
         my %depends = ();
         my %renames = ();
         my %sharednames = ();
+        my %generate = ();
 
         push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
         my $template = Text::Template->new(TYPE => 'FILE',
@@ -1354,6 +1355,9 @@ if ($builder eq "unified") {
             qr/^\s*DEPEND\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
             => sub { push @{$depends{$1}}, split(/\s+/, $2)
                          if !@skip || $skip[$#skip] > 0 },
+            qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
+            => sub { push @{$generate{$1}}, $2
+                         if !@skip || $skip[$#skip] > 0 },
             qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
             => sub { push @{$renames{$1}}, split(/\s+/, $2)
                          if !@skip || $skip[$#skip] > 0 },
@@ -1514,6 +1518,20 @@ EOF
             }
         }
 
+        foreach (keys %generate) {
+            my $dest = $_;
+            my $ddest = cleanfile($buildd, $_, $blddir);
+            if ($unified_info{rename}->{$ddest}) {
+                $ddest = $unified_info{rename}->{$ddest};
+            }
+            die "more than one generator for $dest: "
+                    ,join(" ", @{$generate{$_}}),"\n"
+                    if scalar @{$generate{$_}} > 1;
+            my @generator = split /\s+/, $generate{$dest}->[0];
+            $generator[0] = cleanfile($sourced, $generator[0], $blddir),
+            $unified_info{generate}->{$ddest} = [ @generator ];
+        }
+
         foreach (keys %depends) {
             my $dest = $_;
             my $ddest = cleanfile($buildd, $_, $blddir);