| 1 | #!/usr/local/bin/perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 84 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 84 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 84 | ▶ | use SPVM::Global; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 84 | ▶ | use SPVM::Builder::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 84 | ▶ | use SPVM::Builder::Exe; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # NEVER add compiler/linker options here; all flags must be managed in config files to prevent object file inconsistency. | ||||||||||||||
| 11 | 84 | SPVM::Builder::Util::getopt | |||||||||||||
| 12 | # spvm,spvmcc,spvmdeps common | ||||||||||||||
| 13 | 'h|help' => \my $help, | ||||||||||||||
| 14 | 'v|version' => \my $show_version, | ||||||||||||||
| 15 | 'I=s' => \my @spvm_include_dirs, | ||||||||||||||
| 16 | 'Mblib' => \my $blib, | ||||||||||||||
| 17 | |||||||||||||||
| 18 | # spvm,spvmcc common | ||||||||||||||
| 19 | 'B|build-dir=s' => \my $build_dir, | ||||||||||||||
| 20 | 'w' => \my $warning, | ||||||||||||||
| 21 | 'f|force' => \my $force, | ||||||||||||||
| 22 | |||||||||||||||
| 23 | # spvmcc only | ||||||||||||||
| 24 | 'q|quiet' => \my $quiet, | ||||||||||||||
| 25 | 'o|output=s' => \my $output_file, | ||||||||||||||
| 26 | 'no-config' => \my $allow_no_config_file, | ||||||||||||||
| 27 | 'm|mode=s' => \my $mode, | ||||||||||||||
| 28 | 'object-file=s' => \my @external_object_files, | ||||||||||||||
| 29 | 'class' => \my $script_name_is_class_name | ||||||||||||||
| 30 | ; | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 83 | ▶ | if ($help) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 33 | 0 | print SPVM::Builder::Util::extract_usage; | |||||||||||||
| 34 | 0 | exit 0; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | elsif ($show_version) { | ||||||||||||||
| 37 | 0 | my $version_string = "spvmcc v$SPVM::VERSION"; | |||||||||||||
| 38 | 0 | print "$version_string\n"; | |||||||||||||
| 39 | 0 | exit 0; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 83 | my $script_name = shift; | |||||||||||||
| 43 | |||||||||||||||
| 44 | 83 | ▶ | unless (defined $script_name) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 0 | warn "<script_name> is required.\n\n"; | |||||||||||||
| 46 | 0 | warn SPVM::Builder::Util::extract_usage; | |||||||||||||
| 47 | 0 | exit 255; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 83 | ▶ | unless (defined $output_file) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 0 | warn "-o, --output option is required.\n\n"; | |||||||||||||
| 52 | 0 | warn SPVM::Builder::Util::extract_usage; | |||||||||||||
| 53 | 0 | exit 255; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 83 | ▶ | if ($script_name_is_class_name) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 0 | my $class_name = $script_name; | |||||||||||||
| 58 | 0 | $script_name = SPVM::Builder::Util::search_spvm_file($class_name); | |||||||||||||
| 59 | 0 | ▶ | unless (defined $script_name) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | die "Cannot find $class_name class in @INC"; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 83 | my $source = ""; | |||||||||||||
| 65 | 83 | eval { $source = SPVM::Builder::Util::slurp_binary($script_name); }; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 83 | SPVM::Builder::Util::setup_spvm_command_environment($script_name, $source, $blib, \@spvm_include_dirs, $build_dir, $quiet, undef, $warning, $force); | |||||||||||||
| 68 | |||||||||||||||
| 69 | 83 | my $build_exe = SPVM::Builder::Exe->new( | |||||||||||||
| 70 | script_name => $script_name, | ||||||||||||||
| 71 | output_file => $output_file, | ||||||||||||||
| 72 | mode => $mode, | ||||||||||||||
| 73 | allow_no_config_file => $allow_no_config_file, | ||||||||||||||
| 74 | external_object_files => \@external_object_files, | ||||||||||||||
| 75 | ); | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 81 | $build_exe->build_exe_file; | |||||||||||||
| 78 | |||||||||||||||
| 79 | =encoding utf8 | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 Name | ||||||||||||||
| 82 | |||||||||||||||
| 83 | spvmcc - Generating Excutable File | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 Description | ||||||||||||||
| 86 | |||||||||||||||
| 87 | The spvmcc command generates an executable file from SPVM classes. | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head1 Usage | ||||||||||||||
| 90 | |||||||||||||||
| 91 | Usage: spvmcc [OPTIONS] SCRIPT_NAME | ||||||||||||||
| 92 | |||||||||||||||
| 93 | spvmcc -o myapp myapp.spvm | ||||||||||||||
| 94 | |||||||||||||||
| 95 | spvmcc -I lib -o myapp myapp.spvm | ||||||||||||||
| 96 | |||||||||||||||
| 97 | Options: | ||||||||||||||
| 98 | -h, --help Shows this message | ||||||||||||||
| 99 | -v, --version Shows the version | ||||||||||||||
| 100 | -I DIR Adds a include directory | ||||||||||||||
| 101 | -Mblib Same as "-Mblib" in perl | ||||||||||||||
| 102 | |||||||||||||||
| 103 | -B, --build-dir DIR Build directory | ||||||||||||||
| 104 | -w Enables warning flag | ||||||||||||||
| 105 | -f|--force Compilations and links are forced | ||||||||||||||
| 106 | |||||||||||||||
| 107 | -q, --quiet Stops diagnostic messages. | ||||||||||||||
| 108 | -o, --output FILE The output file name | ||||||||||||||
| 109 | --no-config No configration file is ok | ||||||||||||||
| 110 | -m, --mode MODE Config mode | ||||||||||||||
| 111 | --class Interprets SCRIPT_NAME as a class name and searches for it | ||||||||||||||
| 112 | |||||||||||||||
| 113 | =head1 Details | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =head2 spvmcc Command | ||||||||||||||
| 116 | |||||||||||||||
| 117 | spvmcc [OPTIONS] SCRIPT_NAME | ||||||||||||||
| 118 | |||||||||||||||
| 119 | The C<spvmcc> command generates an executable file from SPVM classes. | ||||||||||||||
| 120 | |||||||||||||||
| 121 | I<OPTIONS> are L<options|/"Options">. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | I<SCRIPT_NAME> is a script path that contains an SPVM script. | ||||||||||||||
| 124 | |||||||||||||||
| 125 | # myapp.spvm | ||||||||||||||
| 126 | use Fn; | ||||||||||||||
| 127 | my $var = 1; | ||||||||||||||
| 128 | say $var; | ||||||||||||||
| 129 | |||||||||||||||
| 130 | Anon class that contains a L<bootstrap method|SPVM::Document::Language::Class/"Bootstrap Method"> is allowed as an SPVM script. | ||||||||||||||
| 131 | |||||||||||||||
| 132 | # myapp.spvm | ||||||||||||||
| 133 | class { | ||||||||||||||
| 134 | |||||||||||||||
| 135 | version "1.001"; | ||||||||||||||
| 136 | |||||||||||||||
| 137 | our $FOO : int; | ||||||||||||||
| 138 | |||||||||||||||
| 139 | use Fn; | ||||||||||||||
| 140 | |||||||||||||||
| 141 | static method main : void () { | ||||||||||||||
| 142 | my $var = 1; | ||||||||||||||
| 143 | say $var; | ||||||||||||||
| 144 | } | ||||||||||||||
| 145 | } | ||||||||||||||
| 146 | |||||||||||||||
| 147 | The base name of I<SCRIPT_NAME> must be a L<Script Base Name|spvm/"Script Base Name">. Otherwise an exception is thrown. | ||||||||||||||
| 148 | |||||||||||||||
| 149 | See L<Class Search Directories|SPVM::Document::Language::Class/"Class Search Directories"> about default class search directories. | ||||||||||||||
| 150 | |||||||||||||||
| 151 | See L<SPVM::Document::EnvironmentVariables> about available environment variables. | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =head2 Exported Functions | ||||||||||||||
| 154 | |||||||||||||||
| 155 | The executable file or dynamic link file generated by C<spvmcc> command contains the following exported functions. | ||||||||||||||
| 156 | |||||||||||||||
| 157 | int SPVMCC__main(int argc, char* argv[]); | ||||||||||||||
| 158 | |||||||||||||||
| 159 | =head2 Config File for Executable File | ||||||||||||||
| 160 | |||||||||||||||
| 161 | A config file that corresponding to the script name must exist for an executable file except for the case that L<"--no-config"> is specified. | ||||||||||||||
| 162 | |||||||||||||||
| 163 | The config for an executable file is a L<SPVM::Builder::Config::Exe> object. | ||||||||||||||
| 164 | |||||||||||||||
| 165 | C<myapp.config>: | ||||||||||||||
| 166 | |||||||||||||||
| 167 | use SPVM::Builder::Config::Exe; | ||||||||||||||
| 168 | |||||||||||||||
| 169 | my $exe_config = SPVM::Builder::Config::Exe->new; | ||||||||||||||
| 170 | |||||||||||||||
| 171 | $exe_config | ||||||||||||||
| 172 | |||||||||||||||
| 173 | =head2 Build Caching | ||||||||||||||
| 174 | |||||||||||||||
| 175 | High-reliability build caching using Ninja-compatible logs, command-line hashes, and file content SHA-1 to detect all changes perfectly. | ||||||||||||||
| 176 | |||||||||||||||
| 177 | See L<SPVM::Builder::Ninja>. | ||||||||||||||
| 178 | |||||||||||||||
| 179 | =head2 Resources | ||||||||||||||
| 180 | |||||||||||||||
| 181 | There are important points to be aware of when generating executable files. That is, L<resources|SPVM::Document::Resource> are not automatically compiled. | ||||||||||||||
| 182 | |||||||||||||||
| 183 | When you run an SPVM program with the L<spvm> command, the resources are contained within the shared library of each class. Therefore, there are no conflicts between resources. | ||||||||||||||
| 184 | |||||||||||||||
| 185 | However, in the case of executable files, there are resource conflicts. For this, the resources must be resolved manually in the configuration file. | ||||||||||||||
| 186 | |||||||||||||||
| 187 | $config->use_resource('Resource::Zlib'); | ||||||||||||||
| 188 | |||||||||||||||
| 189 | This is hard work, but given that the executable file must be compiled from source files and run on a variety of platforms, I think that solving it manually is a better way. | ||||||||||||||
| 190 | |||||||||||||||
| 191 | I have published a command that allows you to view the list of classes using resources and the resource settings. | ||||||||||||||
| 192 | |||||||||||||||
| 193 | See also L<--resource-info|spvmdeps/"--resource-info"> option in L<spvmdeps> command to dump resource information. | ||||||||||||||
| 194 | |||||||||||||||
| 195 | =head2 lib Directive | ||||||||||||||
| 196 | |||||||||||||||
| 197 | If the source code specified by I<SCRIPT_NAME> contains lib directives, The directories specified by lib directive is prepeneded to L<class search directories|SPVM::Document::Language::Class/"Class Search Directories">. | ||||||||||||||
| 198 | |||||||||||||||
| 199 | #lib "$FindBin::Bin/lib" | ||||||||||||||
| 200 | |||||||||||||||
| 201 | This directories specified by lib directive is placed after the directories specified by L</"-I"> option. | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =head1 Options | ||||||||||||||
| 204 | |||||||||||||||
| 205 | =head2 --help | ||||||||||||||
| 206 | |||||||||||||||
| 207 | See L<spvm/"--help">. | ||||||||||||||
| 208 | |||||||||||||||
| 209 | =head2 -h | ||||||||||||||
| 210 | |||||||||||||||
| 211 | -h | ||||||||||||||
| 212 | |||||||||||||||
| 213 | See L<spvm/"-h">. | ||||||||||||||
| 214 | |||||||||||||||
| 215 | =head2 --version | ||||||||||||||
| 216 | |||||||||||||||
| 217 | See L<spvm/"--version">. | ||||||||||||||
| 218 | |||||||||||||||
| 219 | =head2 -v | ||||||||||||||
| 220 | |||||||||||||||
| 221 | -v | ||||||||||||||
| 222 | |||||||||||||||
| 223 | See L<spvm/"-v">. | ||||||||||||||
| 224 | |||||||||||||||
| 225 | =head2 -I | ||||||||||||||
| 226 | |||||||||||||||
| 227 | -I DIR | ||||||||||||||
| 228 | |||||||||||||||
| 229 | See L<spvm/"-I">. | ||||||||||||||
| 230 | |||||||||||||||
| 231 | =head2 -Mblib | ||||||||||||||
| 232 | |||||||||||||||
| 233 | -Mblib | ||||||||||||||
| 234 | |||||||||||||||
| 235 | See L<spvm/"-Mblib">. | ||||||||||||||
| 236 | |||||||||||||||
| 237 | See L<spvm/"-B">. | ||||||||||||||
| 238 | |||||||||||||||
| 239 | =head2 --build-dir | ||||||||||||||
| 240 | |||||||||||||||
| 241 | --build-dir DIR | ||||||||||||||
| 242 | |||||||||||||||
| 243 | See L<spvm/"--build-dir">. | ||||||||||||||
| 244 | |||||||||||||||
| 245 | =head2 -B | ||||||||||||||
| 246 | |||||||||||||||
| 247 | -B DIR | ||||||||||||||
| 248 | |||||||||||||||
| 249 | =head2 -w | ||||||||||||||
| 250 | |||||||||||||||
| 251 | -w | ||||||||||||||
| 252 | |||||||||||||||
| 253 | See L<spvm/"-w">. | ||||||||||||||
| 254 | |||||||||||||||
| 255 | =head2 -f | ||||||||||||||
| 256 | |||||||||||||||
| 257 | -f | ||||||||||||||
| 258 | |||||||||||||||
| 259 | See L<spvm/"-f">. | ||||||||||||||
| 260 | |||||||||||||||
| 261 | =head2 --force | ||||||||||||||
| 262 | |||||||||||||||
| 263 | See L<spvm/"--force">. | ||||||||||||||
| 264 | |||||||||||||||
| 265 | =head2 --quiet | ||||||||||||||
| 266 | |||||||||||||||
| 267 | --quiet | ||||||||||||||
| 268 | |||||||||||||||
| 269 | Stops diagnostic messages. | ||||||||||||||
| 270 | |||||||||||||||
| 271 | =head2 -q | ||||||||||||||
| 272 | |||||||||||||||
| 273 | -q | ||||||||||||||
| 274 | |||||||||||||||
| 275 | Same as L</"--quiet">. | ||||||||||||||
| 276 | |||||||||||||||
| 277 | =head2 --output | ||||||||||||||
| 278 | |||||||||||||||
| 279 | --output FILE | ||||||||||||||
| 280 | |||||||||||||||
| 281 | Specifies the output file path I<FILE>. This output file is an executable file. | ||||||||||||||
| 282 | |||||||||||||||
| 283 | =head2 -o | ||||||||||||||
| 284 | |||||||||||||||
| 285 | -o FILE | ||||||||||||||
| 286 | |||||||||||||||
| 287 | Same as L</"--output">. | ||||||||||||||
| 288 | |||||||||||||||
| 289 | =head2 --no-config | ||||||||||||||
| 290 | |||||||||||||||
| 291 | If this option is specified and a config file does not exist, the C<spvmcc> command runs without finising the program. | ||||||||||||||
| 292 | |||||||||||||||
| 293 | =head2 --mode | ||||||||||||||
| 294 | |||||||||||||||
| 295 | --mode MODE | ||||||||||||||
| 296 | |||||||||||||||
| 297 | Specifies the config mode I<MODE>. | ||||||||||||||
| 298 | |||||||||||||||
| 299 | See L<Config Mode|SPVM::Builder::Config/"Config Mode"> about config modes. | ||||||||||||||
| 300 | |||||||||||||||
| 301 | =head2 -m | ||||||||||||||
| 302 | |||||||||||||||
| 303 | -m MODE | ||||||||||||||
| 304 | |||||||||||||||
| 305 | Same as L</"--mode">. | ||||||||||||||
| 306 | |||||||||||||||
| 307 | =head2 --object-file | ||||||||||||||
| 308 | |||||||||||||||
| 309 | --object-file OBJECT_FILE | ||||||||||||||
| 310 | |||||||||||||||
| 311 | An additional object file I<OBJECT_FILE> passed to the linker. | ||||||||||||||
| 312 | |||||||||||||||
| 313 | This option can be repeated. | ||||||||||||||
| 314 | |||||||||||||||
| 315 | =head2 --class | ||||||||||||||
| 316 | |||||||||||||||
| 317 | --class | ||||||||||||||
| 318 | |||||||||||||||
| 319 | See L<spvm/"--class">. | ||||||||||||||
| 320 | |||||||||||||||
| 321 | =head1 Copyright & License | ||||||||||||||
| 322 | |||||||||||||||
| 323 | Copyright 2023 Yuki Kimoto. All Rights Reserved. | ||||||||||||||
| 324 | |||||||||||||||
| 325 | MIT License. | ||||||||||||||