Name

spvmcc - Generating Excutable File

Description

The spvmcc command generates an executable file from SPVM classes.

Usage

usage: spvmcc [<options>] <script_name>
  
  spvmcc -o myapp myapp.spvm
  
  spvmcc -I lib/SPVM -o myapp myapp.spvm

options:
  -h, --help                      Shows this message
  -v, --version                   Shows the version
  -o, --output <file>             The output file name
  -I, --include-dir <directory>   Adds a include directory
  -B, --build-dir <directory>     Build diretory
  -q, --quiet                     Stops the output of messages
  -f, --force                     Forces the compile and link
  --no-config                     No configration file is ok
  -m, --mode <mode>               Config mode
  --config-argv <arg>             A config argument
  --config-argv-option <arg pair> Key-value config arguments such as KEY=VALUE
  --optimize <level>              Optimization level such as O3, "-O0 -g"
  --resource-info                 Show config files of dependent resources
  --dependency                    Show dependent classes and their versions
  --dependency-cpan               Show dependent cpan modules and their versions

Details

spvmcc [<options>] <script_name>

The spvmcc command generates an executable file from SPVM classes.

<options> are options.

<script_name> is a script name that contains a bootstrap method in an anon class.

class {
  static method main : void () {
    
  }
}

See Class Search Directories about default class search directories.

See SPVM::Document::EnvironmentVariables about available environment variables.

Config File for Executable File

A config file that corresponding to the script name must exist for an executable file except for the case that "--no-config" is specified.

The config for an executable file is a SPVM::Builder::Config::Exe object.

myapp.config:

use SPVM::Builder::Config::Exe;

my $exe_config = SPVM::Builder::Config::Exe->new_gnu99(file => __FILE__);

$exe_config

Caching System

Compiled object files and an executable file are not rebuilt unless they need to be rebuilt.

"--force" option forces the rebuild.

Resources

There are important points to be aware of when generating executable files. That is, resources are not automatically compiled.

When you run an SPVM program with the spvm command, the resources are contained within the shared library of each class. Therefore, there are no conflicts between resources.

However, in the case of executable files, there are resource conflicts. For this, the resources must be resolved manually in the configuration file.

$config->use_resource('Resource::Zlib');

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.

I have published a command that allows you to view the list of classes using resources and the resource settings.

How to dump resource information

Options

--help

Outputs how to use the spvmcc command to standard output.

-h

-h

Same as "--help".

--version

Outputs the version of the spvmcc command to standard output. This version is the same as the version of SPVM.

-v

-v

Same as "--version".

--include-dir

--include-dir <directory>

Prepends <directory> to class search directories

This option can be specified multiple times.

--include-dir dir1 --include-dir dir2

In this case, class search directories becomes the following.

[dir1, dir2, default_dirs]

-I

-I <directory>

Same as "--include-dir".

--build-dir

--build-dir <directory>

Sets SPVM_BUILD_DIR environment variable to <directory>.

-B

-B <directory>

Same as "--build-dir".

--output

--output <file>

Specifies the output file path <file>. This output file is an executable file.

-o

-o <file>

Same as "--output".

--quiet

--quiet

Suppresses messages from the spvmcc command.

-q

-q

Same as "--quiet".

--force

--force

Forces the rebuild of object files and an executable file.

-f

-f

Same as "--force".

--no-config

If this option is specified and a config file does not exist, the spvmcc command runs without finising the program.

--mode

--mode <mode>

Specifies the config mode <mode>.

See Config Mode about config modes.

-m

-m <mode>

Same as "--mode".

--config-argv

--config-argv <arg>

Specifies a config argument <arg>.

This option can be specified multiple times.

See Config Arguments about config arguments.

Examples:

--config-argv FOO

--config-argv-option

--config-argv-option <arg pair>

Specifies two config arguments <arg pair> as the format KEY=VALUE.

This is expaned to the following options.

--config-argv KEY --config-argv VALUE

If only KEY exists or VALUE dose not exist, VALUE is set to an empty string "".

This option can be specified multiple times.

See Config Arguments about config arguments.

Examples:

--config-argv-option FOO=1

--optimize

--optimize <level>

Sepcifies optimization level <level>.

This affects all source files that are compiled.

Examples:

--optimize "-O0 -g"

--resource-info

--resource-info

Shows all config files loading resources.

--dependency

--dependency

Shows all dependent classes and their versions.

Output Example:

Sys 1.201
Regex 0.980
Foo

--dependency-cpan

--dependency-cpan

Shows all dependent cpan modules and their versions.

Output Example:

SPVM 1.001
SPVM::Sys 1.201
SPVM::Regex 0.980
SPVM::Foo

lib Directive

If the source code specified by <script_name> contains lib directives, The directories specified by lib directive is prepeneded to class search directories.

#lib "$FindBin::Bin/lib"

class {

}

This directories specified by lib directive is placed after the directories specified by "--include-dir" option.

Copyright & License

Copyright 2023 Yuki Kimoto. All Rights Reserved.

MIT License.