SPVM::B...::Config(3)
π NAME π
SPVM::B...::Config(3) β User Contributed Perl Documentation β okay so the actual class is SPVM::Builder::Config, and itβs literally the 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. Itβs giving βbackstage pass to the build system,β and honestly? Iconic. β¨
π οΈ USAGE π οΈ
Okay bestie, hereβs the whole vibe in code form β every line stays exactly as it should:
use SPVM::Builder::Config;
# Create a config
my $config = SPVM::Builder::Config->new(file => __FILE__);
# GNU C99
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
# C99
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
# C++
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
# C++11
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
# C++17
my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);
# Optimize
$config->optimize("-O2");
# Optimize with debug mode
$config->optimize("-O0 -g");
# Add ccflags
$config->add_ccflag("-DFOO");
$config->add_define("FOO");
# Add source files
$config->add_source_file("foo.c", "bar.c", "baz/baz.c");
# Add libraries
$config->add_lib("gdi32", "d2d1", "Dwrite");
# Add ldflags
$config->add_ldflag("-pthread");
# Use resource
$config->use_resource("Resource::MyResource");
π FIELDS π
π¦ ext
my $ext = $config->ext;
$config->ext($ext);
Gets and sets the ext field: the extension of a native class. Cute little file-suffix moment. π
Examples:
# MyClass.c
$config->ext('c');
# MyClass.cpp
$config->ext('cpp');
# MyClass.cc
$config->ext('cc');
# MyClass.cu
$config->ext('cu');
# MyClass.m
$config->ext('m');
πΈ cc
my $cc = $config->cc;
$config->cc($cc);
Gets and sets the cc field: a compiler name. The main-character compiler, basically. π
Examples:
# 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});
π include_dirs
my $include_dirs = $config->include_dirs;
$config->include_dirs($include_dirs);
Gets and sets the include_dirs field: an array reference containing header file search directories.
The values of this field are converted to -I options when the arguments of the compiler cc are created.
# -I /path1 -I /path2
$config->include_dirs(['/path1', '/path2']);
π§ spvm_core_include_dir
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: an SPVM core header file search directory.
The value of this field is converted to -I option when the arguments of the compiler cc are created.
This field is automatically set and users normally do not change it. β¨
π¦ native_include_dir
my $native_include_dir = $config->native_include_dir;
$config->native_include_dir($native_include_dir);
Gets and sets the native_include_dir field: a native header file search directory.
The value of this field is converted to -I option when the arguments of the compiler cc are created.
This field is automatically set and users normally do not change it. π«
π native_src_dir
my $native_src_dir = $config->native_src_dir;
$config->native_src_dir($native_src_dir);
Gets and sets the native_src_dir field: a native source file search directory.
This field is automatically set and users normally do not change it. π«Ά
π ccflags
my $ccflags = $config->ccflags;
$config->ccflags($ccflags);
Gets and sets the ccflags field: an array reference containing arguments of the compiler cc. Yes, the compilerβs little accessory bag. π
π₯ defines
my $defines = $config->defines;
$config->defines($defines);
Gets and sets the defines field: an array reference containing the values of -D arguments of the compiler cc.
β optimize
my $optimize = $config->optimize;
$config->optimize($optimize);
Gets and sets the optimize field: an argument of the compiler cc for optimization. Make it fast, make it cute, make it compile. π
Examples:
$config->optimize('-O3');
$config->optimize('-O2');
$config->optimize('-g3 -O0');
π dynamic_lib_ccflags
my $dynamic_lib_ccflags = $config->dynamic_lib_ccflags;
$config->dynamic_lib_ccflags($dynamic_lib_ccflags);
Gets and sets the dynamic_lib_ccflags field: an array reference containing arguments of the compiler cc for dynamic linking.
This field is automatically set and users normally do not change it. π
π§΅ thread_ccflags
my $thread_ccflags = $config->thread_ccflags;
$config->thread_ccflags($thread_ccflags);
Gets and sets the thread_ccflags field: an array reference containing arguments of the compiler cc for threads.
This field is automatically set and users normally do not change it. π§
πͺ mingw_ccflags
my $mingw_ccflags = $config->mingw_ccflags;
$config->mingw_ccflags($mingw_ccflags);
Gets and sets the mingw_ccflags field: an array reference containing arguments of the compiler cc for MinGW.
This field is automatically set and users normally do not change it. β¨
π― std
my $std = $config->std;
$config->std($std);
Gets and sets the std field: a language standard.
This field is converted to -std option when the arguments of the compiler cc are created.
Examples:
# -std=c99
$config->std('c99');
# -std=gnu99
$config->std('gnu99');
# -std=cpp
$config->std('cpp');
# -std=cpp11
$config->std('cpp11');
# -std=cpp17
$config->std('cpp17');
π source_files
my $source_files = $config->source_files;
$config->source_files($source_files);
Gets and sets the source_files field: an array reference containing relative paths of native source files from the native_src_dir field.
π before_compile_cbs
my $before_compile_cbs = $config->before_compile_cbs;
$config->before_compile_cbs($before_compile_cbs);
Gets and sets the before_compile_cbs field: an array reference containing callbacks called just before the compile command cc is executed.
These callbacks are executed only if an object file is actually generated.
The 1th argument of the callback is an SPVM::Builder::Config object.
The 2th argument of the callback is an SPVM::Builder::CompileInfo object.
π ld
my $ld = $config->ld;
$config->ld($ld);
Gets and sets the ld field: a linker name.
Examples:
$config->ld('gcc');
$config->ld('g++');
π lib_dirs
my $lib_dirs = $config->lib_dirs;
$config->lib_dirs($lib_dirs);
Gets and sets the lib_dirs field: an array reference containing library search directories.
The values of this field are converted to -L options when the arguments of the linker ld are created.
# -L /path1 -L /path2
$config->lib_dirs(['/path1', '/path2']);
π§Έ libs
my $libs = $config->libs;
$config->libs($libs);
Gets and sets the libs field: an array reference containing library names such as z, and png or SPVM::Builder::LibInfo objects.
The values of this field are converted to -l options when the arguments of the linker ld are created.
See βLibrary Path Resolutionβ about resolving library paths.
Examples:
# -l libz -l libpng
$config->libs(['z', 'png']);
π ldflags
my ldflags = $config->ldflags;
$config->ldflags(ldflags);
Gets and sets the ldflags field: an array reference containing arguments of the linker ld.
π« dynamic_lib_ldflags
my dynamic_lib_ldflags = $config->dynamic_lib_ldflags;
$config->dynamic_lib_ldflags(dynamic_lib_ldflags);
Gets and sets the dynamic_lib_ldflags field: an array reference containing arguments of the linker ld for dynamic libraries.
This field is automatically set and users normally do not change it. π
π§΅ thread_ldflags
my thread_ldflags = $config->thread_ldflags;
$config->thread_ldflags(thread_ldflags);
Gets and sets the thread_ldflags field: an array reference containing arguments of the linker ld for threads.
This field is automatically set and users normally do not change it. π«Ά
π§± static_lib_ldflag
my static_lib_ldflag = $config->static_lib_ldflag;
$config->static_lib_ldflag(static_lib_ldflag);
Gets and sets the static_lib_ldflag field: an array reference containing a pair of arguments to start statically linking and end it.
The library name added by the add_static_lib are surrounded by the values of the pair.
# -Wl,-Bstatic -llibfoo -Wl,-Bdynamic
$config->static_lib_ldflag(['-Wl,-Bstatic', '-Wl,-Bdynamic']);
$config->add_static_lib('foo');
This field is automatically set and users normally do not change it.
β οΈ This field only works correctly in Linux/Unix.
Mac does not support these options. If you want to search a static library, create a new library search directory, copy a static library to there, and add the new library search directory.
# /path_for_static_lib/libz.a
$config->add_lib_dir('/path_for_static_lib');
$config->add_lib('z');
MinGW on Windows supports these options, but instead of linking statically, it links dynamically with absolute paths. This is usually not the intended behavior. If you want to do static linking on Windows, you need to use -static option. π
β‘ ld_optimize
my $ld_optimize = $config->ld_optimize;
$config->ld_optimize($ld_optimize);
Gets and sets the ld_optimize field: an argument of the linker ld for optimization.
Examples:
$config->ld_optimize("-O3");
π¬ before_link_cbs
my $before_link_cbs = $config->before_link_cbs;
$config->before_link_cbs($before_link_cbs);
Gets and sets the before_link_cbs field: an array reference containing callbacks called just before the link command ld is executed.
These callbacks are executed only if a dynamic link library is actually generated.
The 1th argument of the callback is an SPVM::Builder::Config object.
The 2th argument of the callback is an SPVM::Builder::LinkInfo object.
π¨ force
my $force = $config->force;
$config->force($force);
Gets and sets the 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 performed.
π€« quiet
my $quiet = $config->quiet;
$config->quiet($quiet);
Gets and sets the 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.
π¦ class_name
my $class_name = $config->class_name;
$config->class_name($class_name);
Gets and sets the class_name field β literally the name of the class this config is configuring. It gets auto-set for you, so bestie you normally do not need to touch it. π
π file
my $file = $config->file;
$config->file($file);
Gets and sets the file field, aka the file path of this config. This one is set by the load_config method, and users should not set it. No cap, leave it alone. π«Ά
β¨ output_type
my $output_type = $config->output_type;
$config->output_type($output_type);
Gets and sets the output_type field, which is the type of the output file output_file that the linker ld generates.
- If this field is
dynamic_lib, the output file is a dynamic link library. - If this field is
static_lib, the output file is a static link library. - If this field is
exe, the output file is an executable file.
This field is automatically set, and users normally do not change it. π
πΈ resource_loader_config
my $resource_loader_config = $config->resource_loader_config;
$config->resource_loader_config($resource_loader_config);
Gets and sets the resource_loader_config field β the config file of the class that loaded a resource by the use_resource method. Auto-set, bestie, so you normally don't change it. π§
π category
my $category = $config->category;
$config->category($category);
Gets and sets the 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 normally do not change it. π
π₯ config_exe
my $config_exe = $config->config_exe;
$config->config_exe($config_exe);
Gets and sets the config_exe field.
If the spvmcc command generates an executable file, this field is set to an SPVM::Builder::Config::Exe object.
This field is automatically set, and users normally do not change it. β
π¦ cc_input_dir
my $cc_input_dir = $config->cc_input_dir;
$config->cc_input_dir($cc_input_dir);
Gets and sets the cc_input_dir field β an input directory for the compiler cc. Auto-set, so users normally do not change it. π
π cc_output_dir
my $cc_output_dir = $config->cc_output_dir;
$config->cc_output_dir($cc_output_dir);
Gets and sets the cc_output_dir field β an output directory for the compiler cc. Auto-set, so users normally do not change it. β¨
π output_dir
my $output_dir = $config->output_dir;
$config->output_dir($output_dir);
Gets and sets the output_dir field β an output directory for the linker ld. Auto-set, so users normally do not change it. π
π output_file
my $output_file = $config->output_file;
$config->output_file($output_file);
Gets and sets the output_file field β a path of a dynamic link library or an executable file generated by the linker ld. Auto-set, so users normally do not change it. π«Ά
π¦ is_resource
my $is_resource = $config->is_resource;
$config->is_resource($is_resource);
Gets and sets the is_resource field.
If this field is true, this config is for a resource class. π
π Class Methods π
β¨ new
my $config = SPVM::Builder::Config->new(%fields);
Creates a new SPVM::Builder::Config object with fields, and returns it. Iconic constructor behavior, honestly. π
Field Default Values β yes, all of them:
file- This value is set automatically.
cc- The
$Config{cc}of Config module.
- The
ccflags[]
defines[]
optimize"-O3"
dynamic_lib_ccflags- Windows:
[]
- Other OSs:
["-fPIC"]
- Windows:
thread_ccflags- Windows:
[]
- Other OSs:
["-pthread"]
- Windows:
mingw_ccflags- Windows:
['-D__USE_MINGW_ANSI_STDIO']
- Other OSs:
[]
- Windows:
include_dirs[]
spvm_core_include_dir- The SPVM core header file search directory.
native_include_dir- The directory described in "Native Header Files" in
SPVM::Document::NativeClass. - Examples:
MyClass.naitve/include
- The directory described in "Native Header Files" in
native_src_dir- The directory described in "Native Source Files" in
SPVM::Document::NativeClass. - Examples:
MyClass.naitve/src
- The directory described in "Native Source Files" in
source_files[]
before_compile_cbs[]
ld- The
$Config{ld}of Config module.
- The
ldflags[]
dynamic_lib_ldflags- Windows:
["-mdll", "-s"]
- Other OSs:
["-shared"]
- Windows:
thread_ldflags- Windows:
[]
- Other OSs:
["-pthread"]
- Windows:
static_lib_ldflag["-Wl,-Bstatic", "-Wl,-Bdynamic"]
ld_optimize"-O2"
lib_dirs[]
libs[]
before_link_cbs[]
output_type"dynamic_lib"
category"native"
- Other Fields
undef
πΈ new_c
my $config = SPVM::Builder::Config->new_c(file => __FILE__);
Calls the new method and sets the ext field to c, then returns the return value of the new method. Slay, C files. π
π§ new_gnu99
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
Calls the new_c method and sets the std field to gnu99, then returns the return value of the new_c method. π
β new_gnu11
my $config = SPVM::Builder::Config->new_gnu11(file => __FILE__);
Calls the new_c method and sets the std field to gnu11, then returns the return value of the new_c method. β¨
π¦ new_c99
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
Calls the new_c method and sets the std field to c99, then returns the return value of the new_c method. π
π₯ new_c11
my $config = SPVM::Builder::Config->new_c11(file => __FILE__);
Calls the new_c method and sets the std field to c11, then returns the return value of the new_c method. π
π new_cpp
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
Calls the new method and sets the ext field to cpp, sets the cc field to a C++ compiler, and sets the ld field to a C++ linker, then returns the return value of the new method.
If $Config{gccversion} contains clang, the cc field and ld field are set to clang++. Otherwise, the cc field and ld field are set to g++. Bestie, compiler drama handled. π«Ά
πΈ new_cpp11
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
Calls the new_cpp method and sets the std field to c++11, then returns the return value of the new_cpp method. π
π¦ new_cpp14
my $config = SPVM::Builder::Config->new_cpp14(file => __FILE__);
Calls the new_cpp method and sets the std field to c++14, then returns the return value of the new_cpp method. π
β¨ new_cpp17
my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);
Calls the new_cpp method and sets the std field to c++17, then returns the return value of the new_cpp method. π
π INSTANCE METHODS π
Okay bestie, these are the methods you call on a SPVM::Builder::Config object. One by one, no cap. π
π add_ccflag
$config->add_ccflag(@ccflags);
Adds @ccflags to the end of the ccflags field. Slay.
π add_define
$config->add_define(@defines);
Adds @defines to the end of the defines field. Periodt.
π add_ldflag
$config->add_ldflag(@ldflags);
Adds @ldflags to the end of the ldflags field. π
π add_include_dir
$config->add_include_dir(@include_dirs);
Adds @include_dirs to the end of the include_dirs field. Iconic.
π add_source_file
$config->add_source_file(@source_files);
Adds @source_files to the end of the source_files field.
Examples:
$config->add_source_file('foo.c', 'bar.c');
π add_before_compile_cb
$config->add_before_compile_cb(@before_compile_cbs);
Adds @before_compile_cbs to the end of the before_compile_cbs field.
Examples:
$config->add_before_compile_cb(sub {
my ($config, $compile_info) = @_;
my $cc_command = $compile_info->to_command;
# Do something
});
π add_lib_dir
$config->add_lib_dir(@lib_dirs);
Adds @lib_dirs to the end of the lib_dirs field. Obsessed.
π add_lib
$config->add_lib(@libs);
Adds @libs to the end of the libs field.
Examples:
$config->add_lib('gsl');
$config->add_lib('gsl', 'z');
$config->add_lib(
SPVM::Builder::LibInfo->new(config => $config, name => 'gsl'),
SPVM::Builder::LibInfo->new(config => $config, name => 'z', is_abs => 1),
);
π add_lib_abs
$config->add_lib_abs(@libs);
Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_abs field set to a true value.
If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name.
If the library is located in your user directory, it is good to use the add_lib_abs method instead of the add_lib method.
This is because if the generated dynamic link library has a relative path, that path cannot be resolved when it is loaded.
For system libraries, there is no problem because the linker knows the search directory for the library. So that part is chill. π¦
π add_static_lib
$config->add_static_lib(@libs);
Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_static field set to a true value.
If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name.
Examples:
$config->add_static_lib('gsl');
$config->add_static_lib('gsl', 'z');
π add_static_lib_abs
$config->add_static_lib_abs(@libs);
Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_static field and the SPVM::Builder::LibInfo#is_abs field set to a true value.
If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name. Main character energy. π
π add_before_link_cb
$config->add_before_link_cb(@before_link_cbs);
Adds @before_link_cbs to the end of the before_link_cbs field.
Examples:
$config->add_before_link_cb(sub {
my ($config, $link_info) = @_;
my $object_files = $link_info->object_files;
# Do something
});
π use_resource
my $resource = $config->use_resource($resource_name);
my $resource = $config->use_resource($resource_name, %options);
Loads a resource given a resource class name, and returns it. The return value is an SPVM::Builder::Resource object.
Examples:
$config->use_resource('Resource::MyResource');
π get_resource
my $resource = $config->get_resource($resource_name);
Gets a resource loaded by the use_resource method given a resource name, and returns it. The return value is an SPVM::Builder::Resource object.
π get_resource_names
my $resource_names = $config->get_resource_names;
Returns resource names loaded by the use_resource method. Iykyk. π
π load_config
my $config = $config->load_config($config_file);
Loads a config file given a config file path and an array reference 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 the load_config method. That's it, bestie. β¨
π clone
my $clone = $self->clone;
Clones an SPVM::Builder::Config object, and returns it. Dupe era. π
π§ LIBRARY PATH RESOLUTION π§
The following is the rule of library path resolution, and yes, this is important. Ngl, pay attention.
Library names are converted to SPVM::Builder::LibInfo objects.
If the SPVM::Builder::LibInfo#is_abs field is a false value, the linker ld resolves library paths.
If the SPVM::Builder::LibInfo#is_abs field is a true value, library paths are resolved by the following rules:
- A library is searched in the library search directories contained in the
lib_dirfield from the beginning. - If the
SPVM::Builder::LibInfo#is_staticfield is a false value, the search is performed in the order of a dynamic library, a static library. - If the
SPVM::Builder::LibInfo#is_staticfield is a true value, the search is performed only in static libraries. - If a library is found, the
-loption of the linkerldis created using the found absolute path.
Vibe check passed. π
π₯ EXAMPLES π₯
GNU C99:
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
C99:
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
C11:
my $config = SPVM::Builder::Config->new_c11(file => __FILE__);
C++:
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
C++11:
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
Output messages to stderr from the compiler and the linker:
$config->quiet(0);
Force the compilation and link:
$config->force(1);
Literally iconic examples. π
π COPYRIGHT & LICENSE π
Copyright (c) 2023 Yuki Kimoto
MIT License
π Thatβs the whole vibe, bestie. This page is from perl v5.42.2, dated 2026-02-03, and itβs literally SPVM::B...::Config(3) β periodt. π«Ά
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms