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 DIR                          Adds a include directory
  -B, --build-dir DIR             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
  -w                              Enable warnings
  --ccflag VALUE                  Compiler flag
  --ccflag-spvm VALUE             Same as --ccflag,
                                  but only SPVM core source files
                                  and a bootstrap file
  --ccflag-native VALUE           Same as --ccflag,
                                  but only native class source files
                                  and native source files
                                  
  --ccflag-native-class CLASS_NAME@VALUE       Same as --ccflag-native,
                                               but only a class
                                           
  --ccflag-precompile VALUE       Same as --ccflag,
                                  but only precompile class source files
  --define VALUE                  Same as --ccflag, but -D is prefixed.
  --define-spvm VALUE             Same as --define,
                                  but only SPVM core source files
                                  and a bootstrap file
  --define-native VALUE           Same as --define,
                                  but only native class source files
                                  and native source files
                                  
  --define-native-class CLASS_NAME@VALUE       Same as --define-native,
                                               but only a class
                                           
  --define-precompile VALUE       Same as --define,
                                  but only precompile class source files
  --optimize LEVEL                Optimization level such as "-O3", "-O0 -g".
  --optimize-spvm LEVEL           Same as --optimize,
                                  but only SPVM core source files
                                  and a bootstrap file
  --optimize-native LEVEL         Same as --optimize,
                                  but only native class source files
                                  and native source files
                                  
  --optimize-native-class CLASS_NAME@LEVEL     Same as --optimize-native,
                                               but only a class
                                             
  --optimize-precompile LEVEL     Same as --optimize,
                                  but only precompile class source files
  --include-dir DIR               Same as --ccflag, but -I is prefixed.
  --include-dir-spvm DIR          Same as --include-dir,
                                  but only SPVM core source files
                                  and a bootstrap file
  --include-dir-native DIR        Same as --include-dir,
                                  but only native class source files
                                  and native source files
                                  
  --include-dir-native-class CLASS_NAME@DIR    Same as --include-dir-native,
                                               but only a class
                                           
  --include-dir-precompile DIR    Same as --include-dir,
                                  but only precompile class source files
  --build-spvm-archive            Generate an SPVM archive

Details

spvmcc Command

spvmcc [OPTIONS] SCRIPT_NAME

The spvmcc command generates an executable file from SPVM classes.

OPTIONS are options.

SCRIPT_NAME is a script path that contains a bootstrap method in an anon class.

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

The base name of SCRIPT_NAME must be a Script Base Name. Otherwise an exception is thrown.

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;

$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.

See also --resource-info option in spvmdeps command to dump resource information.

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.

SPVM Archive

An SPVM archive is a tarball (.tar.gz) containing SPVM class files and object files generated from native classes, precompilation classes, and resource classes.

spvmcc.json in an SPVM archive has archive information. This contains the application name, the mode, the version and class information.

The recommended file extension is .spvm-archive.tar.gz.

An SPVM archive does not contains external object files(.o), static library files(.a), dynamic library files(.so, .dll, etc), and SPVM anon class files.

An SPVM archive can be created by --build-spvm-archive option.

spvmcc --build-spvm-archive -o $exe_dir/myapp.spvm-archive.tar.gz myapp.spvm

An SPVM archive can be load by "load_spvm_archive" in SPVM::Builder::Config::Exe method.

By loading an SPVM archive, you can load its classes, and its object files are linked.

If an SPVM archive is loaded and --build-spvm-archive option is specified, the current application information is merged with the SPVM archive information, and then the merged SPVM archive is output.

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".

-I

-I DIR

Prepends DIR to class search directories

This option can be specified multiple times.

-I dir1 -I dir2

In this case, class search directories becomes the following.

[dir1, dir2, default_dirs]

--build-dir

--build-dir DIR

Sets SPVM_BUILD_DIR environment variable to DIR.

-B

-B DIR

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".

-w

-w

Enables warning flag.

Implementation:

Sets CommandInfo#WARNING class variable to 1.

--ccflag

--ccflag VALUE

A compiler flag.

This affects all source files.

This option can be repeated.

--ccflag-spvm

--ccflag-spvm VALUE

A compiler flag.

This affects SPVM core source files and a bootstrap file.

This option can be repeated.

--ccflag-native

--ccflag-native VALUE

A compiler flag.

This affects native class source files(such as MyClass.c) and native source files(such as MyClass.native/src/foo).

This option can be repeated.

--ccflag-native-class

--ccflag-native-class CLASS_NAME@VALUE

A compiler flag.

This affects a native class source file specified by CLASS_NAME(such as MyClass.c) and its native source files(such as MyClass.native/src/foo).

This option can be repeated.

Examples:

--ccflag-native-class MyClass@-Wall

--ccflag-precompile

--ccflag-precompile VALUE

A compiler flag.

This affects precompile class source files.

This option can be repeated.

--define

--define VALUE

A compiler flag, but -D is prefiex.

This affects all source files.

This option can be repeated.

--define-spvm

--define-spvm VALUE

A compiler flag, but -D is prefiex.

This affects SPVM core source files and a bootstrap file.

This option can be repeated.

--define-native

--define-native VALUE

A compiler flag, but -D is prefiex.

This affects native class source files(such as MyClass.c) and native source files(such as MyClass.native/src/foo).

This option can be repeated.

--define-native-class

--define-native-class VALUE

A compiler flag, but -D is prefiex.

This affects a native class source file specified by CLASS_NAME(such as MyClass.c) and its native source files(such as MyClass.native/src/foo).

This option can be repeated.

Examples:

# Expanded to -DDEBUG_MEMORY
--define-native-class MyClass@DEBUG_MEMORY

--define-precompile

--define-precompile VALUE

A compiler flag, but -D is prefiex.

This affects precompile class source files.

This option can be repeated.

--optimize

--optimize LEVEL

Optimization level.

This affects all source files.

Examples:

--optimize "-O0 -g"

--optimize-spvm

--optimize-spvm LEVEL

Optimization level.

This affects SPVM core source files and a bootstrap file.

--optimize-native

--optimize-native LEVEL

Optimization level.

This affects native class source files(such as MyClass.c) and native source files(such as MyClass.native/src/foo).

--optimize-native-class

--optimize-native-class LEVEL

Optimization level.

This affects a native class source file specified by CLASS_NAME(such as MyClass.c) and its native source files(such as MyClass.native/src/foo).

This option can be repeated.

Examples:

--optimize-native-class "MyClass@-O0 -g"

--optimize-precompile

--optimize-precompile LEVEL

Optimization level.

This affects precompile class source files.

--include-dir

--include-dir DIR

A compiler flag, but -I is prefiex.

This affects all source files.

This option can be repeated.

--include-dir-spvm

--include-dir-spvm DIR

A compiler flag, but -I is prefiex.

This affects SPVM core source files and a bootstrap file.

This option can be repeated.

--include-dir-native

--include-dir-native DIR

A compiler flag, but -I is prefiex.

This affects native class source files(such as MyClass.c) and native source files(such as MyClass.native/src/foo).

This option can be repeated.

--include-dir-native-class

--include-dir-native-class DIR

A compiler flag, but -I is prefiex.

This affects a native class source file specified by CLASS_NAME(such as MyClass.c) and its native source files(such as MyClass.native/src/foo).

This option can be repeated.

Examples:

--include-dir-native-class MyClass@/path/foo

--include-dir-precompile

--include-dir-precompile DIR

A compiler flag, but -I is prefiex.

This affects precompile class source files.

This option can be repeated.

--object-file

--object-file OBJECT_FILE

An additional object file OBJECT_FILE passed to the linker.

This option can be repeated.

--build-spvm-archive

--build-spvm-archive

Generate an SPVM archive into the path of -o option. The recomennded file extension of an SPVM archive is a tarball(.spvm-archive.tar.gz).

Copyright & License

Copyright 2023 Yuki Kimoto. All Rights Reserved.

MIT License.