2018-04-04 21:44:29 +00:00
|
|
|
#!/usr/bin/env perl
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2023-01-10 15:09:19 +00:00
|
|
|
# Generate main file, individual apps and solution files for
|
2024-03-12 15:45:55 +00:00
|
|
|
# MS Visual Studio 2017
|
2014-05-07 15:51:20 +00:00
|
|
|
#
|
2023-01-10 15:09:19 +00:00
|
|
|
# Must be run from Mbed TLS root or scripts directory.
|
2014-05-07 15:51:20 +00:00
|
|
|
# Takes no argument.
|
2020-05-25 22:33:31 +00:00
|
|
|
#
|
2020-08-07 11:07:28 +00:00
|
|
|
# Copyright The Mbed TLS Contributors
|
2023-11-02 19:47:20 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2013-09-20 13:11:44 +00:00
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
2014-05-09 10:27:49 +00:00
|
|
|
use Digest::MD5 'md5_hex';
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2024-03-12 15:38:23 +00:00
|
|
|
my $vsx_dir = "visualc/VS2017";
|
2013-09-16 11:33:42 +00:00
|
|
|
my $vsx_ext = "vcxproj";
|
2024-03-12 15:38:23 +00:00
|
|
|
my $vsx_app_tpl_file = "scripts/data_files/vs2017-app-template.$vsx_ext";
|
|
|
|
my $vsx_main_tpl_file = "scripts/data_files/vs2017-main-template.$vsx_ext";
|
2015-01-26 15:42:27 +00:00
|
|
|
my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext";
|
2024-03-12 15:38:23 +00:00
|
|
|
my $vsx_sln_tpl_file = "scripts/data_files/vs2017-sln-template.sln";
|
2015-01-26 15:42:27 +00:00
|
|
|
my $vsx_sln_file = "$vsx_dir/mbedTLS.sln";
|
2014-05-07 15:51:20 +00:00
|
|
|
|
2024-10-31 14:28:53 +00:00
|
|
|
my $mbedtls_programs_dir = "programs";
|
|
|
|
my $tfpsacrypto_programs_dir = "tf-psa-crypto/programs";
|
|
|
|
|
2018-07-20 12:27:58 +00:00
|
|
|
my $mbedtls_header_dir = 'include/mbedtls';
|
2024-06-14 06:43:28 +00:00
|
|
|
my $drivers_builtin_header_dir = 'tf-psa-crypto/drivers/builtin/include/mbedtls';
|
2024-06-10 07:41:49 +00:00
|
|
|
my $psa_header_dir = 'tf-psa-crypto/include/psa';
|
2024-07-01 12:50:54 +00:00
|
|
|
my $tls_source_dir = 'library';
|
|
|
|
my $crypto_core_source_dir = 'tf-psa-crypto/core';
|
|
|
|
my $crypto_source_dir = 'tf-psa-crypto/drivers/builtin/src';
|
2024-11-06 16:24:49 +00:00
|
|
|
my $tls_test_source_dir = 'tests/src';
|
|
|
|
my $tls_test_header_dir = 'tests/include/test';
|
2024-10-31 15:36:05 +00:00
|
|
|
my $test_source_dir = 'framework/tests/src';
|
|
|
|
my $test_header_dir = 'framework/tests/include/test';
|
|
|
|
my $test_drivers_header_dir = 'framework/tests/include/test/drivers';
|
|
|
|
my $test_drivers_source_dir = 'framework/tests/src/drivers';
|
2020-02-12 19:34:22 +00:00
|
|
|
|
|
|
|
my @thirdparty_header_dirs = qw(
|
2024-07-01 16:33:24 +00:00
|
|
|
tf-psa-crypto/drivers/everest/include/everest
|
2020-02-12 19:34:22 +00:00
|
|
|
);
|
|
|
|
my @thirdparty_source_dirs = qw(
|
2024-07-01 16:33:24 +00:00
|
|
|
tf-psa-crypto/drivers/everest/library
|
|
|
|
tf-psa-crypto/drivers/everest/library/kremlib
|
|
|
|
tf-psa-crypto/drivers/everest/library/legacy
|
2020-02-12 19:34:22 +00:00
|
|
|
);
|
2020-02-12 19:45:18 +00:00
|
|
|
|
2020-02-19 19:08:44 +00:00
|
|
|
# Directories to add to the include path.
|
|
|
|
# Order matters in case there are files with the same name in more than
|
|
|
|
# one directory: the compiler will use the first match.
|
|
|
|
my @include_directories = qw(
|
|
|
|
include
|
2024-06-10 07:41:49 +00:00
|
|
|
tf-psa-crypto/include
|
2024-06-14 06:43:28 +00:00
|
|
|
tf-psa-crypto/drivers/builtin/include
|
2024-07-01 16:33:24 +00:00
|
|
|
tf-psa-crypto/drivers/everest/include/
|
|
|
|
tf-psa-crypto/drivers/everest/include/everest
|
|
|
|
tf-psa-crypto/drivers/everest/include/everest/vs2013
|
|
|
|
tf-psa-crypto/drivers/everest/include/everest/kremlib
|
2024-11-08 12:23:28 +00:00
|
|
|
tests/include
|
2024-10-31 15:36:05 +00:00
|
|
|
framework/tests/include
|
2020-02-19 19:08:44 +00:00
|
|
|
);
|
|
|
|
my $include_directories = join(';', map {"../../$_"} @include_directories);
|
|
|
|
|
2024-07-01 12:50:54 +00:00
|
|
|
# Directories to add to the include path when building the libraries, but not
|
2020-06-03 00:25:17 +00:00
|
|
|
# when building tests or applications.
|
|
|
|
my @library_include_directories = qw(
|
|
|
|
library
|
2024-07-01 12:50:54 +00:00
|
|
|
tf-psa-crypto/core
|
|
|
|
tf-psa-crypto/drivers/builtin/src
|
2020-06-03 00:25:17 +00:00
|
|
|
);
|
|
|
|
my $library_include_directories =
|
|
|
|
join(';', map {"../../$_"} (@library_include_directories,
|
|
|
|
@include_directories));
|
|
|
|
|
2020-02-12 19:45:18 +00:00
|
|
|
my @excluded_files = qw(
|
2024-07-01 16:33:24 +00:00
|
|
|
tf-psa-crypto/drivers/everest/library/Hacl_Curve25519.c
|
2020-02-12 19:34:22 +00:00
|
|
|
);
|
2020-02-12 19:45:18 +00:00
|
|
|
my %excluded_files = ();
|
|
|
|
foreach (@excluded_files) { $excluded_files{$_} = 1 }
|
2014-05-08 09:33:30 +00:00
|
|
|
|
|
|
|
my $vsx_hdr_tpl = <<EOT;
|
2021-04-22 18:09:25 +00:00
|
|
|
<ClInclude Include="..\\..\\{NAME}" />
|
2014-05-08 09:33:30 +00:00
|
|
|
EOT
|
|
|
|
my $vsx_src_tpl = <<EOT;
|
2021-04-22 18:09:25 +00:00
|
|
|
<ClCompile Include="..\\..\\{NAME}" />
|
2014-05-08 09:33:30 +00:00
|
|
|
EOT
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2014-05-09 10:56:03 +00:00
|
|
|
my $vsx_sln_app_entry_tpl = <<EOT;
|
2021-04-22 18:09:25 +00:00
|
|
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"
|
|
|
|
ProjectSection(ProjectDependencies) = postProject
|
|
|
|
{46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}
|
|
|
|
EndProjectSection
|
|
|
|
EndProject
|
2014-05-09 10:56:03 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
my $vsx_sln_conf_entry_tpl = <<EOT;
|
2021-04-22 18:09:25 +00:00
|
|
|
{GUID}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
|
|
{GUID}.Debug|Win32.Build.0 = Debug|Win32
|
|
|
|
{GUID}.Debug|x64.ActiveCfg = Debug|x64
|
|
|
|
{GUID}.Debug|x64.Build.0 = Debug|x64
|
|
|
|
{GUID}.Release|Win32.ActiveCfg = Release|Win32
|
|
|
|
{GUID}.Release|Win32.Build.0 = Release|Win32
|
|
|
|
{GUID}.Release|x64.ActiveCfg = Release|x64
|
|
|
|
{GUID}.Release|x64.Build.0 = Release|x64
|
2014-05-09 10:56:03 +00:00
|
|
|
EOT
|
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
exit( main() );
|
|
|
|
|
2014-05-07 15:51:20 +00:00
|
|
|
sub check_dirs {
|
2020-02-12 19:34:22 +00:00
|
|
|
foreach my $d (@thirdparty_header_dirs, @thirdparty_source_dirs) {
|
|
|
|
if (not (-d $d)) { return 0; }
|
|
|
|
}
|
2015-05-14 11:04:03 +00:00
|
|
|
return -d $vsx_dir
|
2018-07-20 12:27:58 +00:00
|
|
|
&& -d $mbedtls_header_dir
|
2024-06-14 06:43:28 +00:00
|
|
|
&& -d $drivers_builtin_header_dir
|
2018-07-20 12:27:58 +00:00
|
|
|
&& -d $psa_header_dir
|
2024-07-01 12:50:54 +00:00
|
|
|
&& -d $tls_source_dir
|
|
|
|
&& -d $crypto_core_source_dir
|
|
|
|
&& -d $crypto_source_dir
|
2020-06-05 14:00:22 +00:00
|
|
|
&& -d $test_source_dir
|
2024-11-06 16:24:49 +00:00
|
|
|
&& -d $tls_test_source_dir
|
2021-04-08 08:58:33 +00:00
|
|
|
&& -d $test_drivers_source_dir
|
2020-06-05 14:00:22 +00:00
|
|
|
&& -d $test_header_dir
|
2024-11-06 16:24:49 +00:00
|
|
|
&& -d $tls_test_header_dir
|
2020-07-16 18:26:18 +00:00
|
|
|
&& -d $test_drivers_header_dir
|
2024-10-31 14:28:53 +00:00
|
|
|
&& -d $mbedtls_programs_dir
|
|
|
|
&& -d $tfpsacrypto_programs_dir;
|
2014-05-07 15:51:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
sub slurp_file {
|
|
|
|
my ($filename) = @_;
|
|
|
|
|
|
|
|
local $/ = undef;
|
2021-04-22 18:09:25 +00:00
|
|
|
open my $fh, '<:crlf', $filename or die "Could not read $filename\n";
|
2013-09-16 11:33:42 +00:00
|
|
|
my $content = <$fh>;
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2014-05-09 11:00:18 +00:00
|
|
|
sub content_to_file {
|
|
|
|
my ($content, $filename) = @_;
|
|
|
|
|
2021-04-22 18:09:25 +00:00
|
|
|
open my $fh, '>:crlf', $filename or die "Could not write to $filename\n";
|
2014-05-09 11:00:18 +00:00
|
|
|
print $fh $content;
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
2014-05-09 10:27:49 +00:00
|
|
|
sub gen_app_guid {
|
|
|
|
my ($path) = @_;
|
|
|
|
|
2015-01-26 15:42:27 +00:00
|
|
|
my $guid = md5_hex( "mbedTLS:$path" );
|
2014-05-09 10:27:49 +00:00
|
|
|
$guid =~ s/(.{8})(.{4})(.{4})(.{4})(.{12})/\U{$1-$2-$3-$4-$5}/;
|
|
|
|
|
|
|
|
return $guid;
|
|
|
|
}
|
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
sub gen_app {
|
|
|
|
my ($path, $template, $dir, $ext) = @_;
|
|
|
|
|
2014-05-09 10:27:49 +00:00
|
|
|
my $guid = gen_app_guid( $path );
|
2013-09-16 11:33:42 +00:00
|
|
|
$path =~ s!/!\\!g;
|
|
|
|
(my $appname = $path) =~ s/.*\\//;
|
2023-11-03 18:16:56 +00:00
|
|
|
my $is_test_app = ($path =~ m/^test\\/);
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2020-04-01 11:34:50 +00:00
|
|
|
my $srcs = "<ClCompile Include=\"..\\..\\programs\\$path.c\" \/>";
|
2018-10-30 21:46:21 +00:00
|
|
|
if( $appname eq "ssl_client2" or $appname eq "ssl_server2" or
|
|
|
|
$appname eq "query_compile_time_config" ) {
|
2021-04-22 18:09:25 +00:00
|
|
|
$srcs .= "\n <ClCompile Include=\"..\\..\\programs\\test\\query_config.c\" \/>";
|
2018-10-30 21:46:21 +00:00
|
|
|
}
|
2021-01-05 20:11:16 +00:00
|
|
|
if( $appname eq "ssl_client2" or $appname eq "ssl_server2" ) {
|
2021-04-22 18:09:25 +00:00
|
|
|
$srcs .= "\n <ClCompile Include=\"..\\..\\programs\\ssl\\ssl_test_lib.c\" \/>";
|
2021-01-05 20:11:16 +00:00
|
|
|
}
|
2018-10-30 21:46:21 +00:00
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
my $content = $template;
|
2018-10-30 21:46:21 +00:00
|
|
|
$content =~ s/<SOURCES>/$srcs/g;
|
2013-09-16 11:33:42 +00:00
|
|
|
$content =~ s/<APPNAME>/$appname/g;
|
2014-05-09 10:27:49 +00:00
|
|
|
$content =~ s/<GUID>/$guid/g;
|
2023-11-03 18:16:56 +00:00
|
|
|
$content =~ s/INCLUDE_DIRECTORIES\n/($is_test_app ?
|
|
|
|
$library_include_directories :
|
|
|
|
$include_directories)/ge;
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2014-05-09 11:00:18 +00:00
|
|
|
content_to_file( $content, "$dir/$appname.$ext" );
|
2013-09-16 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_app_list {
|
2021-04-22 18:07:44 +00:00
|
|
|
my $makefile_contents = slurp_file('programs/Makefile');
|
|
|
|
$makefile_contents =~ /\n\s*APPS\s*=[\\\s]*(.*?)(?<!\\)[\#\n]/s
|
|
|
|
or die "Cannot find APPS = ... in programs/Makefile\n";
|
|
|
|
return split /(?:\s|\\)+/, $1;
|
2013-09-16 11:33:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 15:51:20 +00:00
|
|
|
sub gen_app_files {
|
2014-05-08 09:33:30 +00:00
|
|
|
my @app_list = @_;
|
|
|
|
|
2014-05-07 15:51:20 +00:00
|
|
|
my $vsx_tpl = slurp_file( $vsx_app_tpl_file );
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2014-05-08 09:33:30 +00:00
|
|
|
for my $app ( @app_list ) {
|
2013-09-16 11:33:42 +00:00
|
|
|
gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext );
|
|
|
|
}
|
2014-05-07 15:51:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 09:33:30 +00:00
|
|
|
sub gen_entry_list {
|
2014-05-08 10:53:58 +00:00
|
|
|
my ($tpl, @names) = @_;
|
2014-05-08 09:33:30 +00:00
|
|
|
|
|
|
|
my $entries;
|
2014-05-08 10:53:58 +00:00
|
|
|
for my $name (@names) {
|
|
|
|
(my $entry = $tpl) =~ s/{NAME}/$name/g;
|
2014-05-08 09:33:30 +00:00
|
|
|
$entries .= $entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gen_main_file {
|
2020-02-12 19:45:18 +00:00
|
|
|
my ($headers, $sources,
|
|
|
|
$hdr_tpl, $src_tpl,
|
|
|
|
$main_tpl, $main_out) = @_;
|
2014-05-08 09:33:30 +00:00
|
|
|
|
2020-02-12 19:45:18 +00:00
|
|
|
my $header_entries = gen_entry_list( $hdr_tpl, @$headers );
|
2014-05-08 09:33:30 +00:00
|
|
|
my $source_entries = gen_entry_list( $src_tpl, @$sources );
|
|
|
|
|
|
|
|
my $out = slurp_file( $main_tpl );
|
2021-04-22 18:09:25 +00:00
|
|
|
$out =~ s/SOURCE_ENTRIES\n/$source_entries/m;
|
|
|
|
$out =~ s/HEADER_ENTRIES\n/$header_entries/m;
|
|
|
|
$out =~ s/INCLUDE_DIRECTORIES\n/$library_include_directories/g;
|
2014-05-08 09:33:30 +00:00
|
|
|
|
2014-05-09 11:00:18 +00:00
|
|
|
content_to_file( $out, $main_out );
|
2014-05-08 09:33:30 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 10:56:03 +00:00
|
|
|
sub gen_vsx_solution {
|
|
|
|
my (@app_names) = @_;
|
|
|
|
|
|
|
|
my ($app_entries, $conf_entries);
|
|
|
|
for my $path (@app_names) {
|
|
|
|
my $guid = gen_app_guid( $path );
|
|
|
|
(my $appname = $path) =~ s!.*/!!;
|
|
|
|
|
|
|
|
my $app_entry = $vsx_sln_app_entry_tpl;
|
|
|
|
$app_entry =~ s/{APPNAME}/$appname/g;
|
|
|
|
$app_entry =~ s/{GUID}/$guid/g;
|
|
|
|
|
|
|
|
$app_entries .= $app_entry;
|
|
|
|
|
|
|
|
my $conf_entry = $vsx_sln_conf_entry_tpl;
|
|
|
|
$conf_entry =~ s/{GUID}/$guid/g;
|
|
|
|
|
|
|
|
$conf_entries .= $conf_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $out = slurp_file( $vsx_sln_tpl_file );
|
2021-04-22 18:09:25 +00:00
|
|
|
$out =~ s/APP_ENTRIES\n/$app_entries/m;
|
|
|
|
$out =~ s/CONF_ENTRIES\n/$conf_entries/m;
|
2014-05-09 10:56:03 +00:00
|
|
|
|
2014-05-09 11:00:18 +00:00
|
|
|
content_to_file( $out, $vsx_sln_file );
|
2014-05-09 10:56:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:51:27 +00:00
|
|
|
sub del_vsx_files {
|
|
|
|
unlink glob "'$vsx_dir/*.$vsx_ext'";
|
|
|
|
unlink $vsx_main_file;
|
|
|
|
unlink $vsx_sln_file;
|
|
|
|
}
|
|
|
|
|
2014-05-07 15:51:20 +00:00
|
|
|
sub main {
|
|
|
|
if( ! check_dirs() ) {
|
|
|
|
chdir '..' or die;
|
2023-01-10 15:09:19 +00:00
|
|
|
check_dirs or die "Must be run from Mbed TLS root or scripts dir\n";
|
2014-05-07 15:51:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:51:27 +00:00
|
|
|
# Remove old files to ensure that, for example, project files from deleted
|
|
|
|
# apps are not kept
|
|
|
|
del_vsx_files();
|
|
|
|
|
2014-05-08 09:33:30 +00:00
|
|
|
my @app_list = get_app_list();
|
2020-02-12 19:45:18 +00:00
|
|
|
my @header_dirs = (
|
|
|
|
$mbedtls_header_dir,
|
2024-06-14 06:43:28 +00:00
|
|
|
$drivers_builtin_header_dir,
|
2020-02-12 19:45:18 +00:00
|
|
|
$psa_header_dir,
|
2020-06-05 14:00:22 +00:00
|
|
|
$test_header_dir,
|
2024-11-06 16:24:49 +00:00
|
|
|
$tls_test_header_dir,
|
2020-07-16 18:26:18 +00:00
|
|
|
$test_drivers_header_dir,
|
2024-07-01 12:50:54 +00:00
|
|
|
$tls_source_dir,
|
|
|
|
$crypto_core_source_dir,
|
|
|
|
$crypto_source_dir,
|
2020-02-12 19:45:18 +00:00
|
|
|
@thirdparty_header_dirs,
|
|
|
|
);
|
|
|
|
my @headers = (map { <$_/*.h> } @header_dirs);
|
|
|
|
my @source_dirs = (
|
2024-07-01 12:50:54 +00:00
|
|
|
$tls_source_dir,
|
|
|
|
$crypto_core_source_dir,
|
|
|
|
$crypto_source_dir,
|
2020-06-05 14:00:22 +00:00
|
|
|
$test_source_dir,
|
2024-11-06 16:24:49 +00:00
|
|
|
$tls_test_source_dir,
|
2021-04-08 08:58:33 +00:00
|
|
|
$test_drivers_source_dir,
|
2020-02-12 19:45:18 +00:00
|
|
|
@thirdparty_source_dirs,
|
|
|
|
);
|
|
|
|
my @sources = (map { <$_/*.c> } @source_dirs);
|
|
|
|
|
|
|
|
@headers = grep { ! $excluded_files{$_} } @headers;
|
|
|
|
@sources = grep { ! $excluded_files{$_} } @sources;
|
|
|
|
map { s!/!\\!g } @headers;
|
2014-05-08 09:33:30 +00:00
|
|
|
map { s!/!\\!g } @sources;
|
|
|
|
|
|
|
|
gen_app_files( @app_list );
|
|
|
|
|
2020-02-12 19:45:18 +00:00
|
|
|
gen_main_file( \@headers, \@sources,
|
|
|
|
$vsx_hdr_tpl, $vsx_src_tpl,
|
|
|
|
$vsx_main_tpl_file, $vsx_main_file );
|
2013-09-16 11:33:42 +00:00
|
|
|
|
2014-05-09 10:56:03 +00:00
|
|
|
gen_vsx_solution( @app_list );
|
2014-05-08 10:53:58 +00:00
|
|
|
|
2013-09-16 11:33:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|