The SPVM::Builder::Config - Config of Compiler and Linker
The SPVM::Builder::Config class has methods to manipulate a config to compile source files and generate a dynamic link.
use SPVM::Builder::Config; # Create a config my $config = SPVM::Builder::Config->new(file => __FILE__); # C99 my $config = SPVM::Builder::Config->new_c99(file => __FILE__); # GNU C99 my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__); # C++ my $config = SPVM::Builder::Config->new_cpp(file => __FILE__); # C++11 my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__); # Optimize $config->optimize('-O2'); # Optimize with debug mode $config->optimize('-O0 -g'); # Adds source files $config->add_source_file('foo.c', 'bar.c', 'baz/baz.c'); # Uses resource $config->use_resource('TestCase::Resource::Zlib'); $config->use_resource('TestCase::Resource::Foo1', mode => 'mode1', argv => ['args1', 'args2']); # Gets resouce information my $resource = $config->get_resource('TestCase::Resource::Zlib');
my $ext = $config->ext; $config->ext($ext);
Gets and sets the ext field.
ext
This field is the extension of a native class.
Examples:
# Foo/Bar.c $config->ext('c'); # Foo/Bar.cpp $config->ext('cpp');
my $cc = $config->cc; $config->cc($cc);
Gets and sets the cc field.
cc
This field is a compiler name.
# gcc $config->cc('gcc'); # g++ for C++ $config->cc('g++'); # nvcc for CUDA/GUP $config->cc('nvcc'); # cc that compiled this Perl use Config; $config->cc($Config{cc});
my $include_dirs = $config->include_dirs; $config->include_dirs($include_dirs);
Gets and sets the include_dirs field.
include_dirs
This field is an array reference of including directories of the compiler.
This is same as -I option of gcc.
-I
gcc
my $spvm_core_include_dir = $config->spvm_core_include_dir; $config->spvm_core_include_dir($spvm_core_include_dir);
Gets and sets the spvm_core_include_dir field.
spvm_core_include_dir
This is the header including directory of the SPVM core.
my $native_include_dir = $config->native_include_dir; $config->native_include_dir($native_include_dir);
Gets and sets the native_include_dir field.
native_include_dir
This field is the path of the header including directory of this native class.
my $native_src_dir = $config->native_src_dir; $config->native_src_dir($native_src_dir);
Gets and sets the native_src_dir field.
native_src_dir
This field is the path of the source directory of this native class.
my $ccflags = $config->ccflags; $config->ccflags($ccflags);
Gets and sets the ccflags field.
ccflags
This field is an array reference that contains compiler flags.
my $dynamic_lib_ccflags = $config->dynamic_lib_ccflags; $config->dynamic_lib_ccflags($dynamic_lib_ccflags);
Gets and sets the dynamic_lib_ccflags field.
dynamic_lib_ccflags
This field is an array reference that contains compiler flags for information when the linker generates a dynamic link.
my $std = $config->std; $config->std($std);
Gets and sets the std field.
std
This field is the value for -std option of the compiler.
-std
$config->std('c99'); $config->std('gnu99'); $config->std('cpp'); $config->std('cpp11'); $config->std('cpp17');
my $optimize = $config->optimize; $config->optimize($optimize);
Gets and sets the optimize field.
optimize
This field is the option for optimization of the compiler.
$config->optimize('-O3'); $config->optimize('-O2'); $config->optimize('-g3 -O0');
my $source_files = $config->source_files; $config->source_files($source_files);
Gets and sets the source_files field.
source_files
This field is a array reference that contains source files.
The file name is the relative pass from "native_src_dir".
$config->source_files(['foo.c', 'bar.c']);
my $before_compile_cbs = $config->before_compile_cbs; $config->before_compile_cbs($before_compile_cbs);
Gets and sets the before_compile_cbs field.
before_compile_cbs
This field is an array reference that contains the callbacks called before a compilation.
$config->add_before_compile_cb(sub { my ($config, $compile_info) = @_; my $cc = $compile_info->cc; # Do something });
my $before_link_cbs = $config->before_link_cbs; $config->before_link_cbs($before_link_cbs);
Gets and sets the before_link_cbs field.
before_link_cbs
This field is an array reference that contains the callbacks called before a link.
$config->add_before_link_cb(sub { my ($config, $link_info) = @_; my $object_files = $link_info->object_files; # Do something });
my $ld = $config->ld; $config->ld($ld);
Gets and sets the ld field.
ld
This field is a linker name.
my $lib_dirs = $config->lib_dirs; $config->lib_dirs($lib_dirs);
Gets and sets the lib_dirs field.
lib_dirs
This field is an array reference that contains the directories that libraries are searched for by the linker. This is same as -L option of gcc.
-L
my $libs = $config->libs; $config->libs($libs);
Gets and sets the libs field.
libs
This field is an array reference that contains library names or SPVM::Builder::LibInfo objects. These libraries are linked by "link" in SPVM::Builder::CC method.
my ldflags = $config->ldflags; $config->ldflags(ldflags);
Gets and sets the ldflags field.
ldflags
This field is an array reference that contains linker flags.
my dynamic_lib_ldflags = $config->dynamic_lib_ldflags; $config->dynamic_lib_ldflags(dynamic_lib_ldflags);
Gets and sets the dynamic_lib_ldflags field.
dynamic_lib_ldflags
This field is an array reference that contains linker flags for a dynamic link.
my $ld_optimize = $config->ld_optimize; $config->ld_optimize($ld_optimize);
Gets and sets the ld_optimize field.
ld_optimize
This field is the option for optimization of the linker such as -O3, -O2, -g3 -O0.
-O3
-O2
-g3 -O0
$config->ld_optimize("-O3");
my $force = $config->force; $config->force($force);
Gets and sets the force field.
force
If this field is a true value, the compilation and link are forced without caching.
If this field is a false value, they are not forced.
If this field is undef, whether they are forced or not is determined by other conditions.
my $quiet = $config->quiet; $config->quiet($quiet);
Gets and sets the quiet field.
quiet
If this field is a true value, messages of the compiler and linker are output.
If this field is a false value, the messages are not output.
If this field is undef, whether the messages are output or not is determined by other conditions.
my $class_name = $config->class_name; $config->class_name($class_name);
Gets and sets the class_name field.
class_name
This field is the class to use this config.
my $file = $config->file; $config->file($file);
Gets and sets the file field.
file
This field is the path of the config file.
my $file_optional = $config->file_optional; $config->file_optional($file_optional);
Gets and sets the file_optional field.
file_optional
If this field is false and the file that is given by the file field is not found, an exception is thrown.
my $output_type = $config->output_type; $config->output_type($output_type);
Gets and sets the output_type field.
output_type
This field is the output type of the linker. "dynamic_lib", "static_lib" and "exe" are available.
"dynamic_lib"
"static_lib"
"exe"
my $disable_resource = $config->disable_resource; $config->disable_resource($disable_resource);
Gets and sets the disable_resource field.
disable_resource
If this value is true, All resources loaded by the "use_resource" method is disabled.
my $config = SPVM::Builder::Config->new(%fields);
Create a SPVM::Builder::Config object with fields.
SPVM::Builder::Config
Exceptions:
If the "file_optional" field is not set to a true value, the "file" field must be passed. Otherwise an exception is thrown.
Default Field Values:
If a field is not defined, the field is set to the following default value.
"class_name"
undef
"file"
"file_optional"
0
"ext"
"quiet"
"force"
"cc"
The $Config{cc} of the Config class.
$Config{cc}
"ccflags"
[]
"dynamic_lib_ccflags"
If $Config{cccdlflags} contains -fPIC, the following value is its default value.
$Config{cccdlflags}
-fPIC
["-fPIC"]
Otherwise the following value is its default value.
"std"
"optimize"
"-O3"
"include_dirs"
"spvm_core_include_dir"
The header including directory of the SPVM core is created from the class file of the loaded SPVM::Builder::Config class.
The value looks like path/SPVM/Builder/include.
path/SPVM/Builder/include
"native_include_dir"
If the "file" field is defined, the path of the header including directory is created from the "file" field.
The value looks like path/Foo.native/include.
path/Foo.native/include
"native_src_dir"
If the "file" field is defined, the path of the source directory is created from the "file" field.
The value looks like path/Foo.native/src.
path/Foo.native/src
"source_files"
"before_compile_cbs"
"ld"
The $Config{ld} of the Config class.
$Config{ld}
"ldflags"
"dynamic_lib_ldflags"
Windows:
["-mdll", "-s"]
Other OSs:
['-shared']
"ld_optimize"
"-O2"
"lib_dirs"
"libs"
"before_link_cbs"
"output_type"
my $config = SPVM::Builder::Config->new(file => __FILE__);
my $config = SPVM::Builder::Config->new_c(file => __FILE__);
Calls the "new" method and sets th "ext" field to c.
c
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
Calls the "new_c" method and sets the "std" field to c99.
c99
my $config = SPVM::Builder::Config->new_c11(file => __FILE__);
Calls the "new_c" method and sets the "std" field to c11.
c11
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
Calls the "new_c" method and sets the "std" field to gnu99.
gnu99
my $config = SPVM::Builder::Config->new_gnu11(file => __FILE__);
Calls the "new_c" method and sets the "std" field to gnu11.
gnu11
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
Calls the "new" method and sets the "ext" field to cpp and sets the "cc" field to a C++ compiler and sets the "ld" field to a C++ linker.
cpp
C++
If $Config{gccversion} of the Config class matches the regex /\bclang\b/i, the "cc" field and the "ld" field are set to clang++.
$Config{gccversion}
/\bclang\b/i
clang++
Otherwise the "cc" field and the "ld" field are set to set to g++.
g++
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
Calls the "new_cpp" method and sets the "std" field to c++11.
c++11
my $config = SPVM::Builder::Config->new_cpp14(file => __FILE__);
Calls the "new_cpp" method and sets the "std" field to c++14.
c++14
my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);
Calls the "new_cpp" method and sets the "std" field to c++17.
c++17
$config->add_ccflag(@ccflags);
Adds values after the last element of "ccflags" field.
$config->add_ldflag(@ldflags);
Adds values after the last element of "ldflags" field.
$config->add_include_dir(@include_dirs);
Adds values after the last element of "include_dirs" field.
$config->add_lib_dir(@lib_dirs);
Adds values after the last element of lib_dirs field.
$config->add_source_file(@source_files);
Adds elements after the last element of "source_files" field.
$config->add_before_compile_cb(@before_compile_cbs);
Adds elements after the last element of "before_compile_cbs" field.
$config->add_before_link_cb(@before_link_cbs);
Adds elements after the last element of "before_link_cbs" field.
$config->add_lib(@libs);
Adds library names or SPVM::Builder::LibInfo objects after the last element of "libs" field.
$config->add_lib('gsl'); $config->add_lib('gsl', 'z'); $config->add_lib( SPVM::Builder::LibInfo->new(name => 'gsl'), SPVM::Builder::LibInfo->new(name => 'z', abs => 1), );
$config->add_static_lib(@libs);
static field is set to a true value.
static
$config->add_static_lib('gsl'); $config->add_static_lib('gsl', 'z'); $config->add_static_lib( SPVM::Builder::LibInfo->new(name => 'gsl'), SPVM::Builder::LibInfo->new(name => 'z', abs => 1), );
my $resource = $config->use_resource($resource_name); my $resource = $config->use_resource($resource_name, %options);
Loads a resource by the resource name $resource_name using the SPVM::Builder::Resource method in the SPVM::Builder::Resource class, and returns a SPVM::Builder::Resource object. my $resource = SPVM::Builder::Resource->new(class_name => $resource_name); $config->use_resource($resource);
If the options %options are given, they are used as the options of the SPVM::Builder::Resource method in the SPVM::Builder::Resource class.
my $resource = SPVM::Builder::Resource->new( class_name => 'Resource::Zlib', mode => 'production', argv => ['foo', 'bar'], ); $config->use_resource($resource);
$config->use_resource('Resource::Zlib');
my $resource_names = $config->get_resource_names;
Gets resource names loaded by the L/"use_resource/"> method.
my $config = $config->load_config($config_file, @argv);
Loads a config file, and returns a SPVM::Builder::Config object. The argument @argv is set to the @ARGV of the config file.
my $config = $config->load_base_config($config_file, @argv);
Loads a base config file like Foo.config. This method is the alias for the following method call using "load_mode_config".
Foo.config
my $config = $config->load_mode_config($config_file, undef, @argv);
my $config = $config->load_mode_config($config_file, $mode, @argv);
Loads a mode config file like Foo.mode.config.
Foo.mode.config
At first, removes the string matching the regex (\.[^\.]+)?\.config$ from the base name of the config file $config_file.
(\.[^\.]+)?\.config$
Next, if the mode $mode is defined, .$mode.config is added to the $config_file. Otherwise .config is added.
.$mode.config
.config
Last, "load_config" is called with the modified name of the config file.
Gets the config files loaded by the "load_config" method.
my $clone = $self->clone;
Clones the SPVM::Builder::Config object, and returns it.
Copyright (c) 2023 Yuki Kimoto
MIT License
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.