diff options
author | Richard Levitte <levitte@openssl.org> | 2021-02-25 17:43:57 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2021-03-03 14:47:01 +0100 |
commit | 79f47ef507c945f4c73bcf8eb12f2caef19dc04e (patch) | |
tree | 3d9c60e10b4040c460ad3d161018dc7e08a1c467 /Configurations/unix-Makefile.tmpl | |
parent | 3f399e3787788b1cc3832e254c53cda42873d847 (diff) |
build.info: Make it possible to use compiled programs as generators
Our goal is to be able to produce fipsmodule.cnf with the help of
'openssl fipsinstall', using the openssl program that we build.
This refactors the generatesrc code in all the build file templates to
replace $generator and $generator_incs with $gen0, $gen_args and $gen_incs,
which makes it easier and more consistent to manipulate different bits
of the generator command, and also keeps the variable names consistent
while not overly long.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14320)
Diffstat (limited to 'Configurations/unix-Makefile.tmpl')
-rw-r--r-- | Configurations/unix-Makefile.tmpl | 130 |
1 files changed, 89 insertions, 41 deletions
diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 610a6f6557..f0095d9fd6 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -1315,58 +1315,52 @@ EOF sub generatesrc { my %args = @_; - my $generator = join(" ", @{$args{generator}}); - my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}}); + my $gen0 = $args{generator}->[0]; + my $gen_args = join('', map { " $_" } + @{$args{generator}}[1..$#{$args{generator}}]); + my $gen_incs = join("", map { " -I".$_ } @{$args{generator_incs}}); my $incs = join("", map { " -I".$_ } @{$args{incs}}); my $defs = join("", map { " -D".$_ } @{$args{defs}}); my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}}); if ($args{src} =~ /\.html$/) { - my $title = basename($args{src}, ".html"); - my $pod = $args{generator}->[0]; - return <<"EOF"; + # + # HTML generator + # + my $title = basename($args{src}, ".html"); + my $pod = $gen0; + return <<"EOF"; $args{src}: $pod \$(PERL) \$(SRCDIR)/util/mkpod2html.pl -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc" EOF } elsif ($args{src} =~ /\.(\d)$/) { - my $section = $1; - my $name = uc basename($args{src}, ".$section"); - my $pod = $args{generator}->[0]; - return <<"EOF"; + # + # Man-page generator + # + my $section = $1; + my $name = uc basename($args{src}, ".$section"); + my $pod = $gen0; + return <<"EOF"; $args{src}: $pod pod2man --name=$name --section=$section --center=OpenSSL \\ --release=\$(VERSION) $pod >\$\@ EOF } elsif (platform->isdef($args{src})) { + # + # Linker script-ish generator + # my $target = platform->def($args{src}); (my $mkdef_os = $target{shared_target}) =~ s|-shared$||; my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : ''; my $ord_name = $args{generator}->[1] || $args{product}; return <<"EOF"; -$target: $args{generator}->[0] $deps \$(SRCDIR)/util/mkdef.pl - \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --ordinals $args{generator}->[0] --name $ord_name --OS $mkdef_os > $target -EOF - } elsif (!platform->isasm($args{src})) { - if ($args{generator}->[0] =~ m|^.*\.in$|) { - my $dofile = abs2rel(rel2abs(catfile($config{sourcedir}, - "util", "dofile.pl")), - rel2abs($config{builddir})); - my @modules = ( 'configdata.pm', - grep { $_ =~ m|\.pm$| } @{$args{deps}} ); - my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules; - @modules = map { "-M".basename($_, '.pm') } @modules; - my $modules = join(' ', '', sort keys %moduleincs, @modules); - return <<"EOF"; -$args{src}: $args{generator}->[0] $deps \$(BLDDIR)/configdata.pm - \$(PERL)$modules "$dofile" "-o$target{build_file}" $generator > \$@ +$target: $gen0 $deps \$(SRCDIR)/util/mkdef.pl + \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --ordinals $gen0 --name $ord_name --OS $mkdef_os > $target EOF - } else { - return <<"EOF"; -$args{src}: $args{generator}->[0] $deps - \$(PERL)$generator_incs $generator > \$@ -EOF - } - } else { + } elsif (platform->isasm($args{src})) { + # + # Assembler generator + # my $cppflags = { shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)', lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)', @@ -1374,28 +1368,82 @@ EOF bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)' } -> {$args{intent}}; - if ($args{generator}->[0] =~ /\.pl$/) { - $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator + my $generator; + if ($gen0 =~ /\.pl$/) { + $generator = 'CC="$(CC)" $(PERL)'.$gen_incs.' '.$gen0.$gen_args .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)'; - } elsif ($args{generator}->[0] =~ /\.m4$/) { - $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >' - } elsif ($args{generator}->[0] =~ /\.S$/) { + } elsif ($gen0 =~ /\.m4$/) { + $generator = 'm4 -B 8192'.$gen_incs.' '.$gen0.$gen_args.' >' + } elsif ($gen0 =~ /\.S$/) { $generator = undef; } else { - die "Generator type for $args{src} unknown: $generator\n"; + die "Generator type for $args{src} unknown: $gen0\n"; } if (defined($generator)) { return <<"EOF"; -$args{src}: $args{generator}->[0] $deps +$args{src}: $gen0 $deps $generator \$@ EOF } return <<"EOF"; -$args{src}: $args{generator}->[0] $deps - \$(CC) $incs $cppflags $defs -E $args{generator}->[0] | \\ +$args{src}: $gen0 $deps + \$(CC) $incs $cppflags $defs -E $gen0 | \\ \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@ EOF + } elsif ($gen0 =~ m|^.*\.in$|) { + # + # "dofile" generator (file.in -> file) + # + my $dofile = abs2rel(rel2abs(catfile($config{sourcedir}, + "util", "dofile.pl")), + rel2abs($config{builddir})); + my @modules = ( 'configdata.pm', + grep { $_ =~ m|\.pm$| } @{$args{deps}} ); + my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules; + $deps = join(' ', $deps, @modules); + @modules = map { "-M".basename($_, '.pm') } @modules; + my $modules = join(' ', '', sort keys %moduleincs, @modules); + return <<"EOF"; +$args{src}: $gen0 $deps + \$(PERL)$modules "$dofile" "-o$target{build_file}" $gen0$gen_args > \$@ +EOF + } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) { + # + # Generic generator using OpenSSL programs + # + + # Redo $deps, because programs aren't expected to have deps of their + # own. This is a little more tricky, though, because running programs + # may have dependencies on all sorts of files, so we search through + # our database of programs and modules to see if our dependencies + # are one of those. + $deps = join(' ', map { my $x = $_; + if (grep { $x eq $_ } + @{$unified_info{programs}}) { + platform->bin($x); + } elsif (grep { $x eq $_ } + @{$unified_info{modules}}) { + platform->dso($x); + } else { + $x; + } + } @{$args{deps}}); + # Also redo $gen0, to ensure that we have the proper extension where + # necessary. + $gen0 = platform->bin($gen0); + return <<"EOF"; +$args{src}: $gen0 $deps \$(BLDDIR)/util/wrap.pl + \$(BLDDIR)/util/wrap.pl $gen0$gen_args > \$@ +EOF + } else { + # + # Generic generator using Perl + # + return <<"EOF"; +$args{src}: $gen0 $deps + \$(PERL)$gen_incs $gen0$gen_args > \$@ +EOF } } |