libraries + self building + work on extensions
This commit is contained in:
parent
b6ee9d0dc3
commit
3ddb2943bc
17
HConfig
17
HConfig
|
@ -1,6 +1,5 @@
|
||||||
grbc_want_version("1.0")
|
grbc_want_version("1.0")
|
||||||
grbc_load_platform("platform.hcfg")
|
grbc_load_platform("platform.hcfg")
|
||||||
grbc_load_profile("profile.hcfg")
|
|
||||||
|
|
||||||
local grbc_lib = grbc_library(LibraryConfig.new({
|
local grbc_lib = grbc_library(LibraryConfig.new({
|
||||||
name = "libgrbc",
|
name = "libgrbc",
|
||||||
|
@ -13,9 +12,10 @@ local grbc_lib = grbc_library(LibraryConfig.new({
|
||||||
grbc_file("src/utils.cc"),
|
grbc_file("src/utils.cc"),
|
||||||
grbc_file("src/generator.cc"),
|
grbc_file("src/generator.cc"),
|
||||||
grbc_file("src/target_lib.cc"),
|
grbc_file("src/target_lib.cc"),
|
||||||
grbc_file("src/package.cc")
|
grbc_file("src/package.cc"),
|
||||||
|
grbc_file("src/ext.cc")
|
||||||
},
|
},
|
||||||
lib_type = LibraryType.Static,
|
lib_type = LibraryType.Shared,
|
||||||
|
|
||||||
requirements = {},
|
requirements = {},
|
||||||
compile_flags = {},
|
compile_flags = {},
|
||||||
|
@ -28,7 +28,10 @@ local grbc_lib = grbc_library(LibraryConfig.new({
|
||||||
package_config = PackageConfig.new({
|
package_config = PackageConfig.new({
|
||||||
name = "libgrbc",
|
name = "libgrbc",
|
||||||
libraries = {},
|
libraries = {},
|
||||||
include_dirs = {},
|
include_dirs = {
|
||||||
|
grbc_file("include"),
|
||||||
|
grbc_file("vendor/sol2/include")
|
||||||
|
},
|
||||||
compile_flags = {},
|
compile_flags = {},
|
||||||
linker_flags = {},
|
linker_flags = {},
|
||||||
})
|
})
|
||||||
|
@ -51,13 +54,9 @@ local grbc_exe = grbc_executable(ExecutableConfig.new({
|
||||||
grbc_pkg("libgrbc")
|
grbc_pkg("libgrbc")
|
||||||
},
|
},
|
||||||
compile_flags = {
|
compile_flags = {
|
||||||
grbc_compiler_define("HCONFIG", "")
|
|
||||||
},
|
},
|
||||||
linker_flags = {},
|
linker_flags = {},
|
||||||
include_dirs = {
|
include_dirs = {}
|
||||||
grbc_file("include"),
|
|
||||||
grbc_file("vendor/sol2/include")
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
-- Output the final build script
|
-- Output the final build script
|
||||||
|
|
35
build.ninja
35
build.ninja
|
@ -43,55 +43,62 @@ rule archive
|
||||||
## Compile: src/file.cc ##
|
## Compile: src/file.cc ##
|
||||||
|
|
||||||
build $builddir/src/file.o: cxx src/file.cc
|
build $builddir/src/file.o: cxx src/file.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/ninja.cc ##
|
## Compile: src/ninja.cc ##
|
||||||
|
|
||||||
build $builddir/src/ninja.o: cxx src/ninja.cc
|
build $builddir/src/ninja.o: cxx src/ninja.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/platform.cc ##
|
## Compile: src/platform.cc ##
|
||||||
|
|
||||||
build $builddir/src/platform.o: cxx src/platform.cc
|
build $builddir/src/platform.o: cxx src/platform.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/target_exe.cc ##
|
## Compile: src/target_exe.cc ##
|
||||||
|
|
||||||
build $builddir/src/target_exe.o: cxx src/target_exe.cc
|
build $builddir/src/target_exe.o: cxx src/target_exe.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/utils.cc ##
|
## Compile: src/utils.cc ##
|
||||||
|
|
||||||
build $builddir/src/utils.o: cxx src/utils.cc
|
build $builddir/src/utils.o: cxx src/utils.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/generator.cc ##
|
## Compile: src/generator.cc ##
|
||||||
|
|
||||||
build $builddir/src/generator.o: cxx src/generator.cc
|
build $builddir/src/generator.o: cxx src/generator.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/target_lib.cc ##
|
## Compile: src/target_lib.cc ##
|
||||||
|
|
||||||
build $builddir/src/target_lib.o: cxx src/target_lib.cc
|
build $builddir/src/target_lib.o: cxx src/target_lib.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Compile: src/package.cc ##
|
## Compile: src/package.cc ##
|
||||||
|
|
||||||
build $builddir/src/package.o: cxx src/package.cc
|
build $builddir/src/package.o: cxx src/package.cc
|
||||||
p_cflags = -Iinclude -Ivendor/sol2/include
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Link: libgrbc.a ##
|
## Compile: src/ext.cc ##
|
||||||
|
|
||||||
build $builddir/libgrbc.a: archive $builddir/src/file.o $builddir/src/ninja.o $builddir/src/platform.o $builddir/src/target_exe.o $builddir/src/utils.o $builddir/src/generator.o $builddir/src/target_lib.o $builddir/src/package.o
|
build $builddir/src/ext.o: cxx src/ext.cc
|
||||||
|
p_cflags = -fPIC -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
|
## Link: libgrbc.so ##
|
||||||
|
|
||||||
|
build $builddir/libgrbc.so: link_cxx $builddir/src/file.o $builddir/src/ninja.o $builddir/src/platform.o $builddir/src/target_exe.o $builddir/src/utils.o $builddir/src/generator.o $builddir/src/target_lib.o $builddir/src/package.o $builddir/src/ext.o
|
||||||
|
p_linker_flags = -shared -Lbuild -Wl,-rpath,build:.
|
||||||
|
p_cflags =
|
||||||
|
|
||||||
## Compile: src/main.cc ##
|
## Compile: src/main.cc ##
|
||||||
|
|
||||||
build $builddir/src/main.o: cxx src/main.cc
|
build $builddir/src/main.o: cxx src/main.cc
|
||||||
p_cflags = -fdiagnostics-color=always -DHCONFIG= -Iinclude -Ivendor/sol2/include
|
p_cflags = -Iinclude -Ivendor/sol2/include
|
||||||
|
|
||||||
## Link: grbc ##
|
## Link: grbc ##
|
||||||
|
|
||||||
build $builddir/grbc: link_cxx $builddir/src/main.o
|
build $builddir/grbc: link_cxx $builddir/src/main.o | $builddir/libgrbc.so
|
||||||
p_linker_flags = -llua -lm -ldl build/libgrbc.a
|
p_linker_flags = -llua -lm -ldl build/libgrbc.so -Lbuild -Wl,-rpath,build:.
|
||||||
p_cflags =
|
p_cflags =
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define GRBC_EXT_pkg_config_NAME "GRBC_EXT_pkg_config"
|
#define GRBC_EXT_pkg_config_NAME "GRBC_EXT_pkg_config"
|
||||||
|
|
||||||
|
struct Extension {
|
||||||
|
std::string name;
|
||||||
|
};
|
|
@ -25,6 +25,7 @@ struct GeneratorCompileCommand {
|
||||||
|
|
||||||
struct GeneratorLinkTargetCommand {
|
struct GeneratorLinkTargetCommand {
|
||||||
std::vector<std::string> object_files;
|
std::vector<std::string> object_files;
|
||||||
|
std::vector<std::string> libraries; // Libraries which need to be built before this
|
||||||
std::string linker_flags;
|
std::string linker_flags;
|
||||||
|
|
||||||
std::string output_name;
|
std::string output_name;
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct Package {
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
std::string file_name;
|
||||||
|
|
||||||
std::string compiler_flags;
|
std::string compiler_flags;
|
||||||
|
|
||||||
std::string linker_flags;
|
std::string linker_flags;
|
||||||
|
|
|
@ -14,6 +14,9 @@ struct GState {
|
||||||
|
|
||||||
std::unordered_map<std::string, Package> packages;
|
std::unordered_map<std::string, Package> packages;
|
||||||
|
|
||||||
|
std::string global_compiler_flags = " ";
|
||||||
|
std::string global_linker_flags = " ";
|
||||||
|
|
||||||
std::string ninja_output;
|
std::string ninja_output;
|
||||||
|
|
||||||
static GState& get() {
|
static GState& get() {
|
||||||
|
|
|
@ -26,6 +26,9 @@ struct Package {
|
||||||
/// Name of the package
|
/// Name of the package
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
|
/// File path to the compiled library
|
||||||
|
string file_name;
|
||||||
|
|
||||||
/// Compiler flags used in this package
|
/// Compiler flags used in this package
|
||||||
string compile_flags;
|
string compile_flags;
|
||||||
|
|
||||||
|
|
1
src/ext.cc
Normal file
1
src/ext.cc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#include "grbc/ext.h"
|
|
@ -5,6 +5,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
void grbc_build(const std::string &generator_id) {
|
void grbc_build(const std::string &generator_id) {
|
||||||
|
GState::get().global_linker_flags += "-L" + grbc_get_config().build_dir + " -Wl,-rpath," + grbc_get_config().build_dir + ":. ";
|
||||||
|
|
||||||
log_msg(("finding generator with name: " + generator_id).c_str());
|
log_msg(("finding generator with name: " + generator_id).c_str());
|
||||||
|
|
||||||
for (auto &gen : GState::get().generators) {
|
for (auto &gen : GState::get().generators) {
|
||||||
|
|
25
src/ninja.cc
25
src/ninja.cc
|
@ -74,7 +74,7 @@ ninja_build_rule_compile_file(const GeneratorCompileCommand &compile_cmd) {
|
||||||
|
|
||||||
result += "build $builddir/" + compile_cmd.object_file + ": " +
|
result += "build $builddir/" + compile_cmd.object_file + ": " +
|
||||||
compiler_rule + " " + compile_cmd.source_file + "\n";
|
compiler_rule + " " + compile_cmd.source_file + "\n";
|
||||||
result += " p_cflags = " + compile_cmd.compiler_flags + "\n\n";
|
result += " p_cflags = " + compile_cmd.compiler_flags + GState::get().global_compiler_flags + "\n\n";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,8 @@ ninja_build_rule_link_lib_target(const GeneratorLinkTargetCommand &link_cmd) {
|
||||||
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
||||||
file_list + "\n";
|
file_list + "\n";
|
||||||
|
|
||||||
result += " p_linker_flags = " + link_cmd.linker_flags + " -shared\n";
|
result += " p_linker_flags = " + link_cmd.linker_flags + " -shared" + GState::get().global_linker_flags + "\n";
|
||||||
result += " p_cflags = \n\n";
|
result += " p_cflags = " + GState::get().global_compiler_flags + "\n\n";
|
||||||
} else {
|
} else {
|
||||||
result += "build $builddir/" + link_cmd.output_name + ": archive " +
|
result += "build $builddir/" + link_cmd.output_name + ": archive " +
|
||||||
file_list + "\n\n";
|
file_list + "\n\n";
|
||||||
|
@ -124,12 +124,25 @@ ninja_build_rule_link_exe_target(const GeneratorLinkTargetCommand &link_cmd) {
|
||||||
file_list += "$builddir/" + file + " ";
|
file_list += "$builddir/" + file + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lib_list;
|
||||||
|
|
||||||
|
if (!link_cmd.libraries.empty()) {
|
||||||
|
lib_list = "| ";
|
||||||
|
for (auto &lib : link_cmd.libraries) {
|
||||||
|
if (lib.empty()) continue;
|
||||||
|
|
||||||
|
lib_list += "$builddir/" + lib + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
lib_list.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
file_list.pop_back();
|
file_list.pop_back();
|
||||||
|
|
||||||
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
result += "build $builddir/" + link_cmd.output_name + ": link_cxx " +
|
||||||
file_list + "\n";
|
file_list + " " + lib_list + "\n";
|
||||||
result += " p_linker_flags = " + link_cmd.linker_flags + "\n";
|
result += " p_linker_flags = " + link_cmd.linker_flags + GState::get().global_linker_flags + "\n";
|
||||||
result += " p_cflags = \n\n";
|
result += " p_cflags = " + GState::get().global_compiler_flags + "\n\n";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@ Package grbc_bake_package_config(const PackageConfig &config) {
|
||||||
pkg.compiler_flags += compiler_flag + " ";
|
pkg.compiler_flags += compiler_flag + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &include_dir : config.include_dirs) {
|
||||||
|
pkg.compiler_flags += "-I" + include_dir + " ";
|
||||||
|
}
|
||||||
|
|
||||||
// Remove trailing whitespace
|
// Remove trailing whitespace
|
||||||
|
|
||||||
if (pkg.compiler_flags.back() == ' ')
|
if (pkg.compiler_flags.back() == ' ')
|
||||||
|
|
|
@ -43,8 +43,8 @@ std::string grbc_find_compiler(const std::string &compiler_name) {
|
||||||
if (std::filesystem::exists(
|
if (std::filesystem::exists(
|
||||||
std::filesystem::path(current_path) /
|
std::filesystem::path(current_path) /
|
||||||
std::filesystem::path(compiler_name + ".exe"))) {
|
std::filesystem::path(compiler_name + ".exe"))) {
|
||||||
return std::filesystem::path(current_path) /
|
return (std::filesystem::path(current_path) /
|
||||||
std::filesystem::path(compiler_name + ".exe");
|
std::filesystem::path(compiler_name + ".exe")).generic_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,12 @@ TargetInfo grbc_executable(const ExecutableConfig &executable_config) {
|
||||||
|
|
||||||
compiler_args += grbc_include_dirs_to_cflags(executable_config.include_dirs);
|
compiler_args += grbc_include_dirs_to_cflags(executable_config.include_dirs);
|
||||||
|
|
||||||
|
std::vector<std::string> libraries;
|
||||||
|
|
||||||
|
for (auto &lib : executable_config.requirements) {
|
||||||
|
libraries.push_back(lib.file_name);
|
||||||
|
}
|
||||||
|
|
||||||
GeneratorTarget target{};
|
GeneratorTarget target{};
|
||||||
|
|
||||||
std::vector<std::string> object_files;
|
std::vector<std::string> object_files;
|
||||||
|
@ -53,6 +59,7 @@ TargetInfo grbc_executable(const ExecutableConfig &executable_config) {
|
||||||
executable_link_cmd.object_files = object_files;
|
executable_link_cmd.object_files = object_files;
|
||||||
executable_link_cmd.output_name = exe_name;
|
executable_link_cmd.output_name = exe_name;
|
||||||
executable_link_cmd.target_type = GeneratorTargetType_Executable;
|
executable_link_cmd.target_type = GeneratorTargetType_Executable;
|
||||||
|
executable_link_cmd.libraries = libraries;
|
||||||
|
|
||||||
target.link_target_commands.push_back(executable_link_cmd);
|
target.link_target_commands.push_back(executable_link_cmd);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,10 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
||||||
compiler_args += compiler_arg + " ";
|
compiler_args += compiler_arg + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (library_config.lib_type == LibraryType_Shared) {
|
||||||
|
compiler_args += "-fPIC ";
|
||||||
|
}
|
||||||
|
|
||||||
// Include directories
|
// Include directories
|
||||||
|
|
||||||
compiler_args += grbc_include_dirs_to_cflags(library_config.include_dirs);
|
compiler_args += grbc_include_dirs_to_cflags(library_config.include_dirs);
|
||||||
|
@ -44,21 +48,27 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
||||||
target.compile_commands.push_back(compile_cmd);
|
target.compile_commands.push_back(compile_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Libraries which need to be built before us
|
||||||
|
|
||||||
|
std::vector<std::string> libraries;
|
||||||
|
|
||||||
|
for (auto &lib : library_config.requirements) {
|
||||||
|
libraries.push_back(lib.file_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Generate package config
|
// Generate package config
|
||||||
PackageConfig pkg_cfg{};
|
PackageConfig pkg_cfg{};
|
||||||
pkg_cfg.name = library_config.name;
|
pkg_cfg.name = library_config.name;
|
||||||
pkg_cfg.libraries = library_config.package_config.libraries;
|
pkg_cfg.libraries = library_config.package_config.libraries;
|
||||||
pkg_cfg.include_dirs = library_config.include_dirs;
|
pkg_cfg.include_dirs = library_config.include_dirs;
|
||||||
|
|
||||||
if (library_config.lib_type == LibraryType_Static) {
|
pkg_cfg.linker_flags.push_back(grbc_get_config().build_dir + "/" + lib_name);
|
||||||
pkg_cfg.linker_flags.push_back(grbc_get_config().build_dir + "/" + lib_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Shared library linker flags
|
|
||||||
|
|
||||||
if (!pkg_cfg.name.empty()) {
|
if (!pkg_cfg.name.empty()) {
|
||||||
GState::get().packages.insert(
|
Package pkg = grbc_bake_package_config(pkg_cfg);
|
||||||
{pkg_cfg.name, grbc_bake_package_config(pkg_cfg)});
|
pkg.file_name = lib_name;
|
||||||
|
|
||||||
|
GState::get().packages.insert({pkg_cfg.name, pkg});
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratorLinkTargetCommand link_target{};
|
GeneratorLinkTargetCommand link_target{};
|
||||||
|
@ -72,6 +82,7 @@ TargetInfo grbc_library(const LibraryConfig &library_config) {
|
||||||
link_target.object_files = object_files;
|
link_target.object_files = object_files;
|
||||||
link_target.linker_flags = linker_args;
|
link_target.linker_flags = linker_args;
|
||||||
link_target.output_name = lib_name;
|
link_target.output_name = lib_name;
|
||||||
|
link_target.libraries = libraries;
|
||||||
|
|
||||||
target.link_target_commands.push_back(link_target);
|
target.link_target_commands.push_back(link_target);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue