11cb0ef41Sopenharmony_ci#! /usr/bin/env perl -w
21cb0ef41Sopenharmony_ciuse 5.10.0;
31cb0ef41Sopenharmony_ciuse strict;
41cb0ef41Sopenharmony_ciuse FindBin;
51cb0ef41Sopenharmony_ciuse lib "$FindBin::Bin/../openssl/";
61cb0ef41Sopenharmony_ciuse lib "$FindBin::Bin/../openssl/util/perl";
71cb0ef41Sopenharmony_ciuse lib "$FindBin::Bin/../openssl/util/perl/OpenSSL";
81cb0ef41Sopenharmony_ciuse File::Basename;
91cb0ef41Sopenharmony_ciuse File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
101cb0ef41Sopenharmony_ciuse File::Copy;
111cb0ef41Sopenharmony_ciuse File::Path qw/make_path/;
121cb0ef41Sopenharmony_ci#use with_fallback qw(Text::Template);
131cb0ef41Sopenharmony_ciuse fallback qw(Text::Template);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci# Read configdata from ../openssl/configdata.pm that is generated
161cb0ef41Sopenharmony_ci# with ../openssl/Configure options arch
171cb0ef41Sopenharmony_ciuse configdata;
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cimy $asm = shift @ARGV;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciunless ($asm eq "asm" or $asm eq "asm_avx2" or $asm eq "no-asm") {
221cb0ef41Sopenharmony_ci  die "Error: $asm is invalid argument";
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_cimy $arch = shift @ARGV;
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci# nasm version check
271cb0ef41Sopenharmony_cimy $nasm_banner = `nasm -v`;
281cb0ef41Sopenharmony_cidie "Error: nasm is not installed." if (!$nasm_banner);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci# gas version check
311cb0ef41Sopenharmony_cimy $gas_version_min = 2.30;
321cb0ef41Sopenharmony_cimy $gas_banner = `gcc -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`;
331cb0ef41Sopenharmony_cimy ($gas_version) = ($gas_banner =~/GNU assembler version ([2-9]\.[0-9]+)/);
341cb0ef41Sopenharmony_ciif ($gas_version < $gas_version_min) {
351cb0ef41Sopenharmony_ci  die "Error: gas version $gas_version is too old." .
361cb0ef41Sopenharmony_ci    "$gas_version_min or higher is required.";
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciour $src_dir = "../openssl";
401cb0ef41Sopenharmony_ciour $arch_dir = "../config/archs/$arch";
411cb0ef41Sopenharmony_ciour $base_dir = "$arch_dir/$asm";
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_cimy $is_win = ($arch =~/^VC-WIN/);
441cb0ef41Sopenharmony_ci# VC-WIN32 and VC-WIN64A generate makefile but it can be available
451cb0ef41Sopenharmony_ci# with only nmake. Use pre-created Makefile_VC_WIN32
461cb0ef41Sopenharmony_ci# Makefile_VC-WIN64A instead.
471cb0ef41Sopenharmony_cimy $makefile = $is_win ? "../config/Makefile_$arch": "Makefile";
481cb0ef41Sopenharmony_ci# Generate arch dependent header files with Makefile
491cb0ef41Sopenharmony_cimy $buildinf = "crypto/buildinf.h";
501cb0ef41Sopenharmony_cimy $progs = "apps/progs.h";
511cb0ef41Sopenharmony_cimy $prov_headers = "providers/common/include/prov/der_dsa.h providers/common/include/prov/der_wrap.h providers/common/include/prov/der_rsa.h providers/common/include/prov/der_ecx.h providers/common/include/prov/der_sm2.h providers/common/include/prov/der_ec.h providers/common/include/prov/der_digests.h";
521cb0ef41Sopenharmony_cimy $fips_ld = ($arch =~ m/linux/ ? "providers/fips.ld" : "");
531cb0ef41Sopenharmony_cimy $cmd1 = "cd ../openssl; make -f $makefile clean build_generated $buildinf $progs $prov_headers $fips_ld;";
541cb0ef41Sopenharmony_cisystem($cmd1) == 0 or die "Error in system($cmd1)";
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci# Copy and move all arch dependent header files into config/archs
571cb0ef41Sopenharmony_cimake_path("$base_dir/crypto/include/internal", "$base_dir/include/openssl",
581cb0ef41Sopenharmony_ci	  "$base_dir/include/crypto", "$base_dir/providers/common/include/prov",
591cb0ef41Sopenharmony_ci	  "$base_dir/apps",
601cb0ef41Sopenharmony_ci          {
611cb0ef41Sopenharmony_ci           error => \my $make_path_err});
621cb0ef41Sopenharmony_ciif (@$make_path_err) {
631cb0ef41Sopenharmony_ci  for my $diag (@$make_path_err) {
641cb0ef41Sopenharmony_ci    my ($file, $message) = %$diag;
651cb0ef41Sopenharmony_ci    die "make_path error: $file $message\n";
661cb0ef41Sopenharmony_ci  }
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_cicopy("$src_dir/configdata.pm", "$base_dir/") or die "Copy failed: $!";
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_cimy @openssl_dir_headers = shift @ARGV;
711cb0ef41Sopenharmony_cicopy_headers(@openssl_dir_headers, 'openssl');
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_cimy @crypto_dir_headers = shift @ARGV;
741cb0ef41Sopenharmony_cicopy_headers(@crypto_dir_headers, 'crypto');
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_cimove("$src_dir/include/crypto/bn_conf.h",
771cb0ef41Sopenharmony_ci     "$base_dir/include/crypto/bn_conf.h") or die "Move failed: $!";
781cb0ef41Sopenharmony_cimove("$src_dir/include/crypto/dso_conf.h",
791cb0ef41Sopenharmony_ci     "$base_dir/include/crypto/dso_conf.h") or die "Move failed: $!";
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_cicopy("$src_dir/$buildinf",
821cb0ef41Sopenharmony_ci     "$base_dir/crypto/") or die "Copy failed: $!";
831cb0ef41Sopenharmony_cimove("$src_dir/$progs",
841cb0ef41Sopenharmony_ci     "$base_dir/include") or die "Copy failed: $!";
851cb0ef41Sopenharmony_cicopy("$src_dir/apps/progs.c",
861cb0ef41Sopenharmony_ci     "$base_dir/apps") or die "Copy failed: $!";
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_dsa.h",
891cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
901cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_wrap.h",
911cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
921cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_rsa.h",
931cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
941cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_ecx.h",
951cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
961cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_sm2.h",
971cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
981cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_ec.h",
991cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
1001cb0ef41Sopenharmony_cicopy("$src_dir/providers/common/include/prov/der_digests.h",
1011cb0ef41Sopenharmony_ci     "$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_cimy $linker_script_dir = "<(PRODUCT_DIR)/../../deps/openssl/config/archs/$arch/$asm/providers";
1041cb0ef41Sopenharmony_cimy $fips_linker_script = "";
1051cb0ef41Sopenharmony_ciif ($fips_ld ne "" and not $is_win) {
1061cb0ef41Sopenharmony_ci  $fips_linker_script = "$linker_script_dir/fips.ld";
1071cb0ef41Sopenharmony_ci  copy("$src_dir/providers/fips.ld",
1081cb0ef41Sopenharmony_ci       "$base_dir/providers/fips.ld") or die "Copy failed: $!";
1091cb0ef41Sopenharmony_ci}
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci# read openssl source lists from configdata.pm
1131cb0ef41Sopenharmony_cimy @libapps_srcs = ();
1141cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'apps/libapps.a'}}) {
1151cb0ef41Sopenharmony_ci    #print("libapps ${$unified_info{sources}->{$obj}}[0]\n");
1161cb0ef41Sopenharmony_ci    push(@libapps_srcs, ${$unified_info{sources}->{$obj}}[0]);
1171cb0ef41Sopenharmony_ci}
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_cimy @libssl_srcs = ();
1201cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{libssl}}) {
1211cb0ef41Sopenharmony_ci  push(@libssl_srcs, ${$unified_info{sources}->{$obj}}[0]);
1221cb0ef41Sopenharmony_ci}
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_cimy @libcrypto_srcs = ();
1251cb0ef41Sopenharmony_cimy @generated_srcs = ();
1261cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'libcrypto'}}) {
1271cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
1281cb0ef41Sopenharmony_ci  #print("libcrypto src: $src \n");
1291cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
1301cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
1311cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
1321cb0ef41Sopenharmony_ci    $src =~ s\.[sS]$\.asm\ if ($is_win);
1331cb0ef41Sopenharmony_ci    push(@generated_srcs, $src);
1341cb0ef41Sopenharmony_ci  } else {
1351cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
1361cb0ef41Sopenharmony_ci      push(@libcrypto_srcs, $src);
1371cb0ef41Sopenharmony_ci    }
1381cb0ef41Sopenharmony_ci  }
1391cb0ef41Sopenharmony_ci}
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ciif ($arch eq 'linux32-s390x' || $arch eq  'linux64-s390x') {
1421cb0ef41Sopenharmony_ci  push(@libcrypto_srcs, 'crypto/bn/asm/s390x.S');
1431cb0ef41Sopenharmony_ci}
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_cimy @lib_defines = ();
1461cb0ef41Sopenharmony_ciforeach my $df (@{$unified_info{defines}->{libcrypto}}) {
1471cb0ef41Sopenharmony_ci  #print("libcrypto defines: $df\n");
1481cb0ef41Sopenharmony_ci  push(@lib_defines, $df);
1491cb0ef41Sopenharmony_ci}
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/libdefault.a'}}) {
1531cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
1541cb0ef41Sopenharmony_ci  #print("libdefault src: $src \n");
1551cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
1561cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
1571cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
1581cb0ef41Sopenharmony_ci    $src =~ s\.[sS]$\.asm\ if ($is_win);
1591cb0ef41Sopenharmony_ci    push(@generated_srcs, $src);
1601cb0ef41Sopenharmony_ci  } else {
1611cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
1621cb0ef41Sopenharmony_ci      push(@libcrypto_srcs, $src);
1631cb0ef41Sopenharmony_ci    }
1641cb0ef41Sopenharmony_ci  }
1651cb0ef41Sopenharmony_ci}
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/libcommon.a'}}) {
1681cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
1691cb0ef41Sopenharmony_ci  #print("libimplementations src: $src \n");
1701cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
1711cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
1721cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
1731cb0ef41Sopenharmony_ci    $src =~ s\.[sS]$\.asm\ if ($is_win);
1741cb0ef41Sopenharmony_ci    push(@generated_srcs, $src);
1751cb0ef41Sopenharmony_ci  } else {
1761cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
1771cb0ef41Sopenharmony_ci      push(@libcrypto_srcs, $src);
1781cb0ef41Sopenharmony_ci    }
1791cb0ef41Sopenharmony_ci  }
1801cb0ef41Sopenharmony_ci}
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/liblegacy.a'}}) {
1831cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
1841cb0ef41Sopenharmony_ci  #print("liblegacy src: $src \n");
1851cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
1861cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
1871cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
1881cb0ef41Sopenharmony_ci    $src =~ s\.[sS]$\.asm\ if ($is_win);
1891cb0ef41Sopenharmony_ci    push(@generated_srcs, $src);
1901cb0ef41Sopenharmony_ci  } else {
1911cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
1921cb0ef41Sopenharmony_ci      push(@libcrypto_srcs, $src);
1931cb0ef41Sopenharmony_ci    }
1941cb0ef41Sopenharmony_ci  }
1951cb0ef41Sopenharmony_ci}
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/legacy'}}) {
1981cb0ef41Sopenharmony_ci  if ($obj eq 'providers/legacy.ld' and not $is_win) {
1991cb0ef41Sopenharmony_ci    push(@generated_srcs, $obj);
2001cb0ef41Sopenharmony_ci  } else {
2011cb0ef41Sopenharmony_ci    my $src = ${$unified_info{sources}->{$obj}}[0];
2021cb0ef41Sopenharmony_ci    #print("providers/fips obj: $obj, src: $src\n");
2031cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
2041cb0ef41Sopenharmony_ci      push(@libcrypto_srcs, $src);
2051cb0ef41Sopenharmony_ci    }
2061cb0ef41Sopenharmony_ci  }
2071cb0ef41Sopenharmony_ci}
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_cimy @libfips_srcs = ();
2101cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/libfips.a'}}) {
2111cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
2121cb0ef41Sopenharmony_ci  #print("providers/libfips.a obj: $obj src: $src \n");
2131cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
2141cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
2151cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
2161cb0ef41Sopenharmony_ci    #$src =~ s\.[sS]$\.asm\ if ($is_win);
2171cb0ef41Sopenharmony_ci    #push(@generated_srcs, $src);
2181cb0ef41Sopenharmony_ci  } else {
2191cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
2201cb0ef41Sopenharmony_ci      push(@libfips_srcs, $src);
2211cb0ef41Sopenharmony_ci    }
2221cb0ef41Sopenharmony_ci  }
2231cb0ef41Sopenharmony_ci}
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/libcommon.a'}}) {
2261cb0ef41Sopenharmony_ci  my $src = ${$unified_info{sources}->{$obj}}[0];
2271cb0ef41Sopenharmony_ci  #print("providers/libfips.a obj: $obj src: $src \n");
2281cb0ef41Sopenharmony_ci  # .S files should be preprocessed into .s
2291cb0ef41Sopenharmony_ci  if ($unified_info{generate}->{$src}) {
2301cb0ef41Sopenharmony_ci    # .S or .s files should be preprocessed into .asm for WIN
2311cb0ef41Sopenharmony_ci    #$src =~ s\.[sS]$\.asm\ if ($is_win);
2321cb0ef41Sopenharmony_ci    #push(@generated_srcs, $src);
2331cb0ef41Sopenharmony_ci  } else {
2341cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
2351cb0ef41Sopenharmony_ci      push(@libfips_srcs, $src);
2361cb0ef41Sopenharmony_ci    }
2371cb0ef41Sopenharmony_ci  }
2381cb0ef41Sopenharmony_ci}
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'providers/fips'}}) {
2411cb0ef41Sopenharmony_ci  if ($obj eq 'providers/fips.ld' and not $is_win) {
2421cb0ef41Sopenharmony_ci    push(@generated_srcs, $obj);
2431cb0ef41Sopenharmony_ci  } else {
2441cb0ef41Sopenharmony_ci    my $src = ${$unified_info{sources}->{$obj}}[0];
2451cb0ef41Sopenharmony_ci    #print("providers/fips obj: $obj, src: $src\n");
2461cb0ef41Sopenharmony_ci    if ($src =~ m/\.c$/) {
2471cb0ef41Sopenharmony_ci      push(@libfips_srcs, $src);
2481cb0ef41Sopenharmony_ci    }
2491cb0ef41Sopenharmony_ci  }
2501cb0ef41Sopenharmony_ci}
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_cimy @libfips_defines = ();
2531cb0ef41Sopenharmony_ciforeach my $df (@{$unified_info{defines}->{'providers/libfips.a'}}) {
2541cb0ef41Sopenharmony_ci  #print("libfips defines: $df\n");
2551cb0ef41Sopenharmony_ci  push(@libfips_defines, $df);
2561cb0ef41Sopenharmony_ci}
2571cb0ef41Sopenharmony_ci
2581cb0ef41Sopenharmony_ciforeach my $df (@{$unified_info{defines}->{'providers/fips'}}) {
2591cb0ef41Sopenharmony_ci  #print("libfips defines: $df\n");
2601cb0ef41Sopenharmony_ci  push(@libfips_defines, $df);
2611cb0ef41Sopenharmony_ci}
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_cimy @apps_openssl_srcs = ();
2641cb0ef41Sopenharmony_ciforeach my $obj (@{$unified_info{sources}->{'apps/openssl'}}) {
2651cb0ef41Sopenharmony_ci  push(@apps_openssl_srcs, ${$unified_info{sources}->{$obj}}[0]);
2661cb0ef41Sopenharmony_ci}
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci# Generate all asm files and copy into config/archs
2691cb0ef41Sopenharmony_ciforeach my $src (@generated_srcs) {
2701cb0ef41Sopenharmony_ci  my $cmd = "cd ../openssl; CC=gcc ASM=nasm make -f $makefile $src;" .
2711cb0ef41Sopenharmony_ci    "cp --parents $src ../config/archs/$arch/$asm; cd ../config";
2721cb0ef41Sopenharmony_ci  system("$cmd") == 0 or die "Error in system($cmd)";
2731cb0ef41Sopenharmony_ci}
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci$target{'lib_cppflags'} =~ s/-D//g;
2761cb0ef41Sopenharmony_cimy @lib_cppflags = split(/ /, $target{'lib_cppflags'});
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_cimy @cflags = ();
2791cb0ef41Sopenharmony_cipush(@cflags, @{$config{'cflags'}});
2801cb0ef41Sopenharmony_cipush(@cflags, @{$config{'CFLAGS'}});
2811cb0ef41Sopenharmony_cipush(@cflags, $target{'cflags'});
2821cb0ef41Sopenharmony_cipush(@cflags, $target{'CFLAGS'});
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci# AIX has own assembler not GNU as that does not support --noexecstack
2851cb0ef41Sopenharmony_ciif ($arch =~ /aix/) {
2861cb0ef41Sopenharmony_ci  @cflags = grep $_ ne '-Wa,--noexecstack', @cflags;
2871cb0ef41Sopenharmony_ci}
2881cb0ef41Sopenharmony_ci
2891cb0ef41Sopenharmony_ci# Create openssl.gypi
2901cb0ef41Sopenharmony_cimy $template =
2911cb0ef41Sopenharmony_ci    Text::Template->new(TYPE => 'FILE',
2921cb0ef41Sopenharmony_ci                        SOURCE => 'openssl.gypi.tmpl',
2931cb0ef41Sopenharmony_ci                        DELIMITERS => [ "%%-", "-%%" ]
2941cb0ef41Sopenharmony_ci                        );
2951cb0ef41Sopenharmony_cimy $gypi = $template->fill_in(
2961cb0ef41Sopenharmony_ci    HASH => {
2971cb0ef41Sopenharmony_ci        libssl_srcs => \@libssl_srcs,
2981cb0ef41Sopenharmony_ci        libcrypto_srcs => \@libcrypto_srcs,
2991cb0ef41Sopenharmony_ci        lib_defines => \@lib_defines,
3001cb0ef41Sopenharmony_ci        generated_srcs => \@generated_srcs,
3011cb0ef41Sopenharmony_ci        config => \%config,
3021cb0ef41Sopenharmony_ci        target => \%target,
3031cb0ef41Sopenharmony_ci        cflags => \@cflags,
3041cb0ef41Sopenharmony_ci        asm => \$asm,
3051cb0ef41Sopenharmony_ci        arch => \$arch,
3061cb0ef41Sopenharmony_ci        lib_cppflags => \@lib_cppflags,
3071cb0ef41Sopenharmony_ci        is_win => \$is_win,
3081cb0ef41Sopenharmony_ci    });
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ciopen(GYPI, "> ./archs/$arch/$asm/openssl.gypi");
3111cb0ef41Sopenharmony_ciprint GYPI "$gypi";
3121cb0ef41Sopenharmony_ciclose(GYPI);
3131cb0ef41Sopenharmony_ci#
3141cb0ef41Sopenharmony_ci# Create openssl-fips.gypi
3151cb0ef41Sopenharmony_cimy $fipstemplate =
3161cb0ef41Sopenharmony_ci    Text::Template->new(TYPE => 'FILE',
3171cb0ef41Sopenharmony_ci                        SOURCE => 'openssl-fips.gypi.tmpl',
3181cb0ef41Sopenharmony_ci                        DELIMITERS => [ "%%-", "-%%" ]
3191cb0ef41Sopenharmony_ci                        );
3201cb0ef41Sopenharmony_cimy $fipsgypi = $fipstemplate->fill_in(
3211cb0ef41Sopenharmony_ci    HASH => {
3221cb0ef41Sopenharmony_ci        libfips_srcs => \@libfips_srcs,
3231cb0ef41Sopenharmony_ci        libfips_defines => \@libfips_defines,
3241cb0ef41Sopenharmony_ci        generated_srcs => \@generated_srcs,
3251cb0ef41Sopenharmony_ci        config => \%config,
3261cb0ef41Sopenharmony_ci        target => \%target,
3271cb0ef41Sopenharmony_ci        cflags => \@cflags,
3281cb0ef41Sopenharmony_ci        asm => \$asm,
3291cb0ef41Sopenharmony_ci        arch => \$arch,
3301cb0ef41Sopenharmony_ci        lib_cppflags => \@lib_cppflags,
3311cb0ef41Sopenharmony_ci        is_win => \$is_win,
3321cb0ef41Sopenharmony_ci	linker_script => $fips_linker_script,
3331cb0ef41Sopenharmony_ci    });
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ciopen(FIPSGYPI, "> ./archs/$arch/$asm/openssl-fips.gypi");
3361cb0ef41Sopenharmony_ciprint FIPSGYPI "$fipsgypi";
3371cb0ef41Sopenharmony_ciclose(FIPSGYPI);
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci# Create openssl-cl.gypi
3401cb0ef41Sopenharmony_cimy $cltemplate =
3411cb0ef41Sopenharmony_ci    Text::Template->new(TYPE => 'FILE',
3421cb0ef41Sopenharmony_ci                        SOURCE => 'openssl-cl.gypi.tmpl',
3431cb0ef41Sopenharmony_ci                        DELIMITERS => [ "%%-", "-%%" ]
3441cb0ef41Sopenharmony_ci                        );
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_cimy $clgypi = $cltemplate->fill_in(
3471cb0ef41Sopenharmony_ci    HASH => {
3481cb0ef41Sopenharmony_ci        apps_openssl_srcs => \@apps_openssl_srcs,
3491cb0ef41Sopenharmony_ci        lib_defines => \@lib_defines,
3501cb0ef41Sopenharmony_ci        libapps_srcs => \@libapps_srcs,
3511cb0ef41Sopenharmony_ci        config => \%config,
3521cb0ef41Sopenharmony_ci        target => \%target,
3531cb0ef41Sopenharmony_ci        cflags => \@cflags,
3541cb0ef41Sopenharmony_ci        asm => \$asm,
3551cb0ef41Sopenharmony_ci        arch => \$arch,
3561cb0ef41Sopenharmony_ci        lib_cppflags => \@lib_cppflags,
3571cb0ef41Sopenharmony_ci        is_win => \$is_win,
3581cb0ef41Sopenharmony_ci    });
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ciopen(CLGYPI, "> ./archs/$arch/$asm/openssl-cl.gypi");
3611cb0ef41Sopenharmony_ciprint CLGYPI "$clgypi";
3621cb0ef41Sopenharmony_ciclose(CLGYPI);
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci# Clean Up
3651cb0ef41Sopenharmony_cimy $cmd2 ="cd $src_dir; make -f $makefile clean; make -f $makefile distclean;" .
3661cb0ef41Sopenharmony_ci    "git clean -f $src_dir/crypto";
3671cb0ef41Sopenharmony_cisystem($cmd2) == 0 or die "Error in system($cmd2)";
3681cb0ef41Sopenharmony_ci
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_cisub copy_headers {
3711cb0ef41Sopenharmony_ci  my @headers = split / /, $_[0];
3721cb0ef41Sopenharmony_ci  my $inc_dir = $_[1];
3731cb0ef41Sopenharmony_ci  foreach my $header_name (@headers) {
3741cb0ef41Sopenharmony_ci    # Copy the header from OpenSSL source directory to the arch specific dir.
3751cb0ef41Sopenharmony_ci    #print("copy header $src_dir/include/$inc_dir/${header_name}.h to $base_dir/include/$inc_dir \n");
3761cb0ef41Sopenharmony_ci    copy("$src_dir/include/$inc_dir/${header_name}.h",
3771cb0ef41Sopenharmony_ci         "$base_dir/include/$inc_dir/") or die "Copy failed: $!";
3781cb0ef41Sopenharmony_ci   }
3791cb0ef41Sopenharmony_ci}
380