11cb0ef41Sopenharmony_ci#! /usr/bin/env perl -w
21cb0ef41Sopenharmony_ciuse 5.10.0;
31cb0ef41Sopenharmony_ciuse strict;
41cb0ef41Sopenharmony_ciuse FindBin;
51cb0ef41Sopenharmony_ciuse lib "$FindBin::Bin/../openssl/util/perl/OpenSSL";
61cb0ef41Sopenharmony_ciuse Text::Template;
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciour $src_dir = "../openssl";
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cimy @openssl_headers = shift @ARGV;
111cb0ef41Sopenharmony_cimy @crypto_headers = shift @ARGV;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cimy $include_tmpl = Text::Template->new(TYPE => 'FILE',
141cb0ef41Sopenharmony_ci                                       SOURCE => 'include.h.tmpl',
151cb0ef41Sopenharmony_ci                                       DELIMITERS => [ "%%-", "-%%" ]);
161cb0ef41Sopenharmony_cimy $include_conf_tmpl = Text::Template->new(TYPE => 'FILE',
171cb0ef41Sopenharmony_ci                                            SOURCE => 'include_config.tmpl',
181cb0ef41Sopenharmony_ci                                            DELIMITERS => [ "%%-", "-%%" ]);
191cb0ef41Sopenharmony_cimy $include_asm_tmpl = Text::Template->new(TYPE => 'FILE',
201cb0ef41Sopenharmony_ci                                           SOURCE => 'include_asm.h.tmpl',
211cb0ef41Sopenharmony_ci                                           DELIMITERS => [ "%%-", "-%%" ]);
221cb0ef41Sopenharmony_cimy $include_no_asm_tmpl = Text::Template->new(TYPE => 'FILE',
231cb0ef41Sopenharmony_ci                                              SOURCE => 'include_no-asm.h.tmpl',
241cb0ef41Sopenharmony_ci                                              DELIMITERS => [ "%%-", "-%%" ]);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cigen_headers(@openssl_headers, 'openssl');
271cb0ef41Sopenharmony_cigen_headers(@crypto_headers, 'crypto');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cisub gen_headers {
301cb0ef41Sopenharmony_ci  my @headers = split / /, $_[0];
311cb0ef41Sopenharmony_ci  my $inc_dir = $_[1];
321cb0ef41Sopenharmony_ci  foreach my $header_name (@headers) {
331cb0ef41Sopenharmony_ci    print("Generating headers for: $header_name\n");
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci    # Populate and write header file that will be placed OpenSSL's include
361cb0ef41Sopenharmony_ci    # directory.
371cb0ef41Sopenharmony_ci    my $include = $include_tmpl->fill_in(HASH => { name => $header_name });
381cb0ef41Sopenharmony_ci    open(INCLUDE, "> $src_dir/include/${inc_dir}/${header_name}.h");
391cb0ef41Sopenharmony_ci    print INCLUDE "$include";
401cb0ef41Sopenharmony_ci    close(INCLUDE);
411cb0ef41Sopenharmony_ci    #
421cb0ef41Sopenharmony_ci    # Poplulate and write the header in the config directory (currently the same
431cb0ef41Sopenharmony_ci    # directory as this file) which will determine which include to use
441cb0ef41Sopenharmony_ci    # depending on if asm is available or not.
451cb0ef41Sopenharmony_ci    my $include_conf = $include_conf_tmpl->fill_in(
461cb0ef41Sopenharmony_ci       HASH => { name => $header_name });
471cb0ef41Sopenharmony_ci    open(INCLUDE_CONF, "> ./${header_name}.h");
481cb0ef41Sopenharmony_ci    print INCLUDE_CONF "$include_conf";
491cb0ef41Sopenharmony_ci    close(INCLUDE_CONF);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci    # Poplulate and write the asm header.
521cb0ef41Sopenharmony_ci    my $include_asm = $include_asm_tmpl->fill_in(
531cb0ef41Sopenharmony_ci      HASH => { asmdir => 'asm', incdir => $inc_dir, name => $header_name });
541cb0ef41Sopenharmony_ci    open(INCLUDE_ASM, "> ./${header_name}_asm.h");
551cb0ef41Sopenharmony_ci    print INCLUDE_ASM "$include_asm";
561cb0ef41Sopenharmony_ci    close(INCLUDE_ASM);
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci    # Poplulate and write the no-asm header.
591cb0ef41Sopenharmony_ci    my $include_no_asm = $include_no_asm_tmpl->fill_in(
601cb0ef41Sopenharmony_ci      HASH => { asmdir => 'no-asm',
611cb0ef41Sopenharmony_ci                incdir => $inc_dir,
621cb0ef41Sopenharmony_ci		name => $header_name });
631cb0ef41Sopenharmony_ci    open(INCLUDE_NO_ASM, "> ./${header_name}_no-asm.h");
641cb0ef41Sopenharmony_ci    print INCLUDE_NO_ASM "$include_no_asm";
651cb0ef41Sopenharmony_ci    close(INCLUDE_NO_ASM);
661cb0ef41Sopenharmony_ci  }
671cb0ef41Sopenharmony_ci}
68