fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 2 | |
Andres AG | 5121d4b | 2018-04-11 20:35:19 -0500 | [diff] [blame] | 3 | # Generate main file, individual apps and solution files for MS Visual Studio |
| 4 | # 2010 |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 5 | # |
Manuel Pégourié-Gonnard | 813e585 | 2015-01-26 15:42:27 +0000 | [diff] [blame] | 6 | # Must be run from mbedTLS root or scripts directory. |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 7 | # Takes no argument. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 8 | # |
| 9 | # Copyright (C) 2013-2020, Arm Limited, All Rights Reserved |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame^] | 10 | # SPDX-License-Identifier: Apache-2.0 |
| 11 | # |
| 12 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | # not use this file except in compliance with the License. |
| 14 | # You may obtain a copy of the License at |
| 15 | # |
| 16 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | # |
| 18 | # Unless required by applicable law or agreed to in writing, software |
| 19 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | # See the License for the specific language governing permissions and |
| 22 | # limitations under the License. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 23 | # |
| 24 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 684e9dc | 2013-09-20 15:11:44 +0200 | [diff] [blame] | 25 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 26 | use warnings; |
| 27 | use strict; |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 28 | use Digest::MD5 'md5_hex'; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 29 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 30 | my $vsx_dir = "visualc/VS2010"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 31 | my $vsx_ext = "vcxproj"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 32 | my $vsx_app_tpl_file = "scripts/data_files/vs2010-app-template.$vsx_ext"; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 33 | my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext"; |
Manuel Pégourié-Gonnard | 813e585 | 2015-01-26 15:42:27 +0000 | [diff] [blame] | 34 | my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext"; |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame] | 35 | my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln"; |
Manuel Pégourié-Gonnard | 813e585 | 2015-01-26 15:42:27 +0000 | [diff] [blame] | 36 | my $vsx_sln_file = "$vsx_dir/mbedTLS.sln"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 37 | |
| 38 | my $programs_dir = 'programs'; |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 39 | my $header_dir = 'include/mbedtls'; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 40 | my $source_dir = 'library'; |
| 41 | |
| 42 | # Need windows line endings! |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 43 | my $vsx_hdr_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 44 | <ClInclude Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 45 | EOT |
| 46 | my $vsx_src_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 47 | <ClCompile Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 48 | EOT |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 49 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame] | 50 | my $vsx_sln_app_entry_tpl = <<EOT; |
| 51 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"\r |
| 52 | ProjectSection(ProjectDependencies) = postProject\r |
| 53 | {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}\r |
| 54 | EndProjectSection\r |
| 55 | EndProject\r |
| 56 | EOT |
| 57 | |
| 58 | my $vsx_sln_conf_entry_tpl = <<EOT; |
| 59 | {GUID}.Debug|Win32.ActiveCfg = Debug|Win32\r |
| 60 | {GUID}.Debug|Win32.Build.0 = Debug|Win32\r |
| 61 | {GUID}.Debug|x64.ActiveCfg = Debug|x64\r |
| 62 | {GUID}.Debug|x64.Build.0 = Debug|x64\r |
| 63 | {GUID}.Release|Win32.ActiveCfg = Release|Win32\r |
| 64 | {GUID}.Release|Win32.Build.0 = Release|Win32\r |
| 65 | {GUID}.Release|x64.ActiveCfg = Release|x64\r |
| 66 | {GUID}.Release|x64.Build.0 = Release|x64\r |
| 67 | EOT |
| 68 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 69 | exit( main() ); |
| 70 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 71 | sub check_dirs { |
Manuel Pégourié-Gonnard | 51f14be | 2015-05-14 13:04:03 +0200 | [diff] [blame] | 72 | return -d $vsx_dir |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 73 | && -d $header_dir |
| 74 | && -d $source_dir |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 75 | && -d $programs_dir; |
| 76 | } |
| 77 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 78 | sub slurp_file { |
| 79 | my ($filename) = @_; |
| 80 | |
| 81 | local $/ = undef; |
| 82 | open my $fh, '<', $filename or die "Could not read $filename\n"; |
| 83 | my $content = <$fh>; |
| 84 | close $fh; |
| 85 | |
| 86 | return $content; |
| 87 | } |
| 88 | |
Manuel Pégourié-Gonnard | 411f73e | 2014-05-09 13:00:18 +0200 | [diff] [blame] | 89 | sub content_to_file { |
| 90 | my ($content, $filename) = @_; |
| 91 | |
| 92 | open my $fh, '>', $filename or die "Could not write to $filename\n"; |
| 93 | print $fh $content; |
| 94 | close $fh; |
| 95 | } |
| 96 | |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 97 | sub gen_app_guid { |
| 98 | my ($path) = @_; |
| 99 | |
Manuel Pégourié-Gonnard | 813e585 | 2015-01-26 15:42:27 +0000 | [diff] [blame] | 100 | my $guid = md5_hex( "mbedTLS:$path" ); |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 101 | $guid =~ s/(.{8})(.{4})(.{4})(.{4})(.{12})/\U{$1-$2-$3-$4-$5}/; |
| 102 | |
| 103 | return $guid; |
| 104 | } |
| 105 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 106 | sub gen_app { |
| 107 | my ($path, $template, $dir, $ext) = @_; |
| 108 | |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 109 | my $guid = gen_app_guid( $path ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 110 | $path =~ s!/!\\!g; |
| 111 | (my $appname = $path) =~ s/.*\\//; |
| 112 | |
Gilles Peskine | fea21d4 | 2020-04-01 13:34:50 +0200 | [diff] [blame] | 113 | my $srcs = "<ClCompile Include=\"..\\..\\programs\\$path.c\" \/>"; |
Andres Amaya Garcia | 024694e | 2018-10-30 21:46:21 +0000 | [diff] [blame] | 114 | if( $appname eq "ssl_client2" or $appname eq "ssl_server2" or |
| 115 | $appname eq "query_compile_time_config" ) { |
Gilles Peskine | fea21d4 | 2020-04-01 13:34:50 +0200 | [diff] [blame] | 116 | $srcs .= "\r\n <ClCompile Include=\"..\\..\\programs\\ssl\\query_config.c\" \/>"; |
Andres Amaya Garcia | 024694e | 2018-10-30 21:46:21 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 119 | my $content = $template; |
Andres Amaya Garcia | 024694e | 2018-10-30 21:46:21 +0000 | [diff] [blame] | 120 | $content =~ s/<SOURCES>/$srcs/g; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 121 | $content =~ s/<APPNAME>/$appname/g; |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 122 | $content =~ s/<GUID>/$guid/g; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 123 | |
Manuel Pégourié-Gonnard | 411f73e | 2014-05-09 13:00:18 +0200 | [diff] [blame] | 124 | content_to_file( $content, "$dir/$appname.$ext" ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | sub get_app_list { |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 128 | my $app_list = `cd $programs_dir && make list`; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 129 | die "make list failed: $!\n" if $?; |
| 130 | |
| 131 | return split /\s+/, $app_list; |
| 132 | } |
| 133 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 134 | sub gen_app_files { |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 135 | my @app_list = @_; |
| 136 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 137 | my $vsx_tpl = slurp_file( $vsx_app_tpl_file ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 138 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 139 | for my $app ( @app_list ) { |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 140 | gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext ); |
| 141 | } |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 144 | sub gen_entry_list { |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 145 | my ($tpl, @names) = @_; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 146 | |
| 147 | my $entries; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 148 | for my $name (@names) { |
| 149 | (my $entry = $tpl) =~ s/{NAME}/$name/g; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 150 | $entries .= $entry; |
| 151 | } |
| 152 | |
| 153 | return $entries; |
| 154 | } |
| 155 | |
| 156 | sub gen_main_file { |
| 157 | my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_; |
| 158 | |
| 159 | my $header_entries = gen_entry_list( $hdr_tpl, @$headers ); |
| 160 | my $source_entries = gen_entry_list( $src_tpl, @$sources ); |
| 161 | |
| 162 | my $out = slurp_file( $main_tpl ); |
| 163 | $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m; |
| 164 | $out =~ s/HEADER_ENTRIES\r\n/$header_entries/m; |
| 165 | |
Manuel Pégourié-Gonnard | 411f73e | 2014-05-09 13:00:18 +0200 | [diff] [blame] | 166 | content_to_file( $out, $main_out ); |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame] | 169 | sub gen_vsx_solution { |
| 170 | my (@app_names) = @_; |
| 171 | |
| 172 | my ($app_entries, $conf_entries); |
| 173 | for my $path (@app_names) { |
| 174 | my $guid = gen_app_guid( $path ); |
| 175 | (my $appname = $path) =~ s!.*/!!; |
| 176 | |
| 177 | my $app_entry = $vsx_sln_app_entry_tpl; |
| 178 | $app_entry =~ s/{APPNAME}/$appname/g; |
| 179 | $app_entry =~ s/{GUID}/$guid/g; |
| 180 | |
| 181 | $app_entries .= $app_entry; |
| 182 | |
| 183 | my $conf_entry = $vsx_sln_conf_entry_tpl; |
| 184 | $conf_entry =~ s/{GUID}/$guid/g; |
| 185 | |
| 186 | $conf_entries .= $conf_entry; |
| 187 | } |
| 188 | |
| 189 | my $out = slurp_file( $vsx_sln_tpl_file ); |
| 190 | $out =~ s/APP_ENTRIES\r\n/$app_entries/m; |
| 191 | $out =~ s/CONF_ENTRIES\r\n/$conf_entries/m; |
| 192 | |
Manuel Pégourié-Gonnard | 411f73e | 2014-05-09 13:00:18 +0200 | [diff] [blame] | 193 | content_to_file( $out, $vsx_sln_file ); |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Andres Amaya Garcia | 3c5f949 | 2018-01-11 19:51:27 +0000 | [diff] [blame] | 196 | sub del_vsx_files { |
| 197 | unlink glob "'$vsx_dir/*.$vsx_ext'"; |
| 198 | unlink $vsx_main_file; |
| 199 | unlink $vsx_sln_file; |
| 200 | } |
| 201 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 202 | sub main { |
| 203 | if( ! check_dirs() ) { |
| 204 | chdir '..' or die; |
Manuel Pégourié-Gonnard | 813e585 | 2015-01-26 15:42:27 +0000 | [diff] [blame] | 205 | check_dirs or die "Must but run from mbedTLS root or scripts dir\n"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Andres Amaya Garcia | 3c5f949 | 2018-01-11 19:51:27 +0000 | [diff] [blame] | 208 | # Remove old files to ensure that, for example, project files from deleted |
| 209 | # apps are not kept |
| 210 | del_vsx_files(); |
| 211 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 212 | my @app_list = get_app_list(); |
| 213 | my @headers = <$header_dir/*.h>; |
| 214 | my @sources = <$source_dir/*.c>; |
| 215 | map { s!/!\\!g } @headers; |
| 216 | map { s!/!\\!g } @sources; |
| 217 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 218 | gen_app_files( @app_list ); |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 219 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 220 | gen_main_file( \@headers, \@sources, |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 221 | $vsx_hdr_tpl, $vsx_src_tpl, |
| 222 | $vsx_main_tpl_file, $vsx_main_file ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 223 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame] | 224 | gen_vsx_solution( @app_list ); |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 225 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 226 | return 0; |
| 227 | } |