Name
SPVM::Builder::Config - Config for Compiling and Linking Native Classes
Description
The SPVM::Builder::Config class has methods to get and set config for compiling and linking native classes.
Fields
class_name
my $class_name = $config->class_name;
$config->class_name($class_name);
Gets and sets class_name field, the name of the class configured by this config.
This field is automatically set and users nomally do not change it.
file
my $file = $config->file;
$config->file($file);
Gets and sets file field, the file path of this config.
This field is set by "load_config" method and users should not set it.
category
my $category = $config->category;
$config->category($category);
Gets and sets category field.
If this field is precompile, this config is for precompilation,
If this field is native, this config is for a native class.
This field is automatically set and users nomally do not change it.
is_resource
my $is_resource = $config->is_resource;
$config->is_resource($is_resource);
Gets and sets is_resource field.
If this field is true, this config is for a resource class.
force
my $force = $config->force;
$config->force($force);
Gets and sets force field.
If this field is a true value, the compilation and linking are forced.
If this field is a false value except for undef, the compilation and linking are performed following the rule of the dependency resolution.
If this field is undef, this config does not specify whether the compilation and linking are perfomed.
quiet
my $quiet = $config->quiet;
$config->quiet($quiet);
Gets and sets quiet field.
If this field is a true value, the messages from the compiler and the linker are output to stderr.
If this field is a false value except for undef, the messages from the compiler and the linker are not output.
If this field is undef, this config does specify whether the messages from the compiler and the linker are output.
long_option_sep
my $long_option_sep = $config->long_option_sep;
$config->long_option_sep($long_option_sep);
Gets and sets long_option_sep field, a string that is a separator between an option name and its value.
mode
my $mode = $config->mode;
$config->mode($mode);
Gets and sets mode field.
config_global
my $config_global = $config->config_global;
$config->config_global($config_global);
Gets and sets config_global field.
If spvmcc command generates an excutable file, this field is set to an SPVM::Builder::Config::Exe object.
This field is automatically set and users nomally do not change it.
Class Methods
new
my $config = SPVM::Builder::Config::Base->new(%fields);
Creates a new SPVM::Builder::Config::Base object with fields, and returns it.
Field Default Values:
-
This value is set automatically.
-
"native" -
"="
Instance Methods
create_option
my $option = $config->create_option("-std", "c11");
Builds a command line option from the option name and the value.
If the length of the option name (excluding leading - and /) is 1, the option name and the value are connected without a separator.
# Results in "-Ic:/path"
my $option = $config->create_option("-I", "c:/path");
If the length of the option name is greater than 1, they are connected using "long_option_sep".
# Results in "-std=c11" (if long_option_sep is "=")
my $option = $config->create_option("-std", "c11");
This method is useful for supporting different compiler conventions such as GCC/Clang and MSVC.
create_option_short
my $option = $config->create_option_short("-I", "c:/path");
Builds a command line option by connecting the option name and the value directly without a separator.
# Results in "-Ic:/path"
my $option = $config->create_option_short("-I", "c:/path");
# Results in "-Foc:/path" (Useful for MSVC even if the option name length > 1)
my $option = $config->create_option_short("-Fo", "c:/path");
create_option_long
my $option = $config->create_option_long("-std", "c11");
Builds a command line option by connecting the option name and the value using "long_option_sep".
# Results in "-std=c11" (if long_option_sep is "=")
my $option = $config->create_option_long("-std", "c11");
# Results in "-out:c:/path" (if long_option_sep is ":")
my $option = $config->create_option_long("-out", "c:/path");
load_config
my $config = $config->load_config($config_file);
Loads a config file given a config file path and an array refernce containing config arguments, and returns an SPVM::Builder::Config object.
Examples:
my $config = $config->load_config(__FILE__);
get_loaded_config_files
Returns the config files loaded by "load_config" method.
load_base_config
my $config = $config->load_base_config($config_file);
Creates the base config file path from the config file path $config_file, and calls load_config method given the base config file path and config arguments, and returns its return value.
A base config file is the config file that removes its mode.
# Config file
MyClass.mode.config
# Base config file
MyClass.config
Examples:
my $config = SPVM::Builder::Config::Global->load_base_config(__FILE__);
load_mode_config
my $config = $config->load_mode_config($config_file, $mode);
Creates a mode config file path from the config file path $config_file, and calls load_config method given the mode config file path and config arguments, and returns its return value.
my $config = SPVM::Builder::Config::Global->load_mode_config(__FILE__, "production");
""mode"" field is set to $mode.
clone
my $clone = $self->clone;
Clones SPVM::Builder::Config object, and returns it.
Config Mode
A config can have its mode if the config is one for an executable file generated by spvmcc command.
The mode is written in the format .MODE_NAME just before .config extension of a config file.
MODE_NAME must consist of a-zA-Z0-9_.
Examples:
# production mode
MyClass.production.config
# devel mode
MyClass.devel.config
Use "mode" field to get the config mode.
my $mode = $config->mode;
The spvmcc command has --mode option for giving a config mode.
spvmcc -o myapp --mode production myapp.spvm
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License