aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-08-24 22:10:09 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-08-28 15:01:48 +0300
commitf7adb1ce7a13753a6acf5c9eeb9577ecdada630c (patch)
tree5bd0bb1488c0a6fb35788ea815cbd7533a0de72a
parent4bdf53837e010073de802070d4e6087410662d3e (diff)
Move c build system module to separate library
-rw-r--r--bootstrap-mingw.bat2
-rw-r--r--bootstrap-msvc.bat2
-rw-r--r--bootstrap.gmake2
-rwxr-xr-xbootstrap.sh2
-rw-r--r--build2/b.cxx7
-rw-r--r--build2/buildfile5
-rw-r--r--build2/c/init.hxx46
-rw-r--r--libbuild2/buildfile2
-rw-r--r--libbuild2/c/buildfile90
-rw-r--r--libbuild2/c/export.hxx38
-rw-r--r--libbuild2/c/init.cxx (renamed from build2/c/init.cxx)23
-rw-r--r--libbuild2/c/init.hxx32
-rw-r--r--libbuild2/c/target.hxx (renamed from build2/c/target.hxx)8
-rw-r--r--libbuild2/module.cxx1
-rw-r--r--tests/libbuild2/buildfile2
-rw-r--r--tests/libbuild2/driver.cxx2
16 files changed, 196 insertions, 68 deletions
diff --git a/bootstrap-mingw.bat b/bootstrap-mingw.bat
index fc3c9ff..43cc84f 100644
--- a/bootstrap-mingw.bat
+++ b/bootstrap-mingw.bat
@@ -61,7 +61,6 @@ if "_%libbutl%_" == "__" (
rem All the source directories.
rem
set "src=build2"
-set "src=%src% build2\c"
set "src=%src% build2\cxx"
set "src=%src% libbuild2"
@@ -71,6 +70,7 @@ set "src=%src% libbuild2\test"
set "src=%src% libbuild2\test\script"
set "src=%src% libbuild2\install"
set "src=%src% libbuild2\bin"
+set "src=%src% libbuild2\c"
set "src=%src% libbuild2\cc"
set "src=%src% libbuild2\version"
set "src=%src% libbuild2\in"
diff --git a/bootstrap-msvc.bat b/bootstrap-msvc.bat
index 7526b0c..8da8769 100644
--- a/bootstrap-msvc.bat
+++ b/bootstrap-msvc.bat
@@ -92,7 +92,6 @@ if "_%libbutl%_" == "__" (
rem All the source directories.
rem
set "src=build2"
-set "src=%src% build2\c"
set "src=%src% build2\cxx"
set "src=%src% libbuild2"
@@ -102,6 +101,7 @@ set "src=%src% libbuild2\test"
set "src=%src% libbuild2\test\script"
set "src=%src% libbuild2\install"
set "src=%src% libbuild2\bin"
+set "src=%src% libbuild2\c"
set "src=%src% libbuild2\cc"
set "src=%src% libbuild2\version"
set "src=%src% libbuild2\in"
diff --git a/bootstrap.gmake b/bootstrap.gmake
index 0cafedf..0e3126e 100644
--- a/bootstrap.gmake
+++ b/bootstrap.gmake
@@ -130,7 +130,6 @@ endif
# Note: list nested subdirectories first (used in clean).
#
build2_sub := \
-c \
cxx
libbuild2_sub := \
@@ -140,6 +139,7 @@ test/script \
test \
install \
bin \
+c \
cc \
version \
in
diff --git a/bootstrap.sh b/bootstrap.sh
index f227d82..368a549 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -117,7 +117,6 @@ if test -z "$libbutl"; then
fi
src="build2/*.cxx"
-src="$src build2/c/*.cxx"
src="$src build2/cxx/*.cxx"
src="$src libbuild2/*.cxx"
@@ -127,6 +126,7 @@ src="$src libbuild2/test/*.cxx"
src="$src libbuild2/test/script/*.cxx"
src="$src libbuild2/install/*.cxx"
src="$src libbuild2/bin/*.cxx"
+src="$src libbuild2/c/*.cxx"
src="$src libbuild2/cc/*.cxx"
src="$src libbuild2/version/*.cxx"
src="$src libbuild2/in/*.cxx"
diff --git a/build2/b.cxx b/build2/b.cxx
index be67a8c..1fd6b5a 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -54,6 +54,7 @@
#include <libbuild2/in/init.hxx>
#include <libbuild2/bin/init.hxx>
+#include <libbuild2/c/init.hxx>
#include <libbuild2/cc/init.hxx>
#include <libbuild2/version/init.hxx>
@@ -63,7 +64,6 @@
# include <build2/cli/init.hxx>
#endif
-#include <build2/c/init.hxx>
#include <build2/cxx/init.hxx>
using namespace butl;
@@ -521,13 +521,10 @@ main (int argc, char* argv[])
load (&bin::build2_bin_load);
load (&cc::build2_cc_load);
+ load (&c::build2_c_load);
load (&version::build2_version_load);
load (&in::build2_in_load);
- TMP_LOAD (c_guess, "c.guess", c::guess_init);
- TMP_LOAD (c_config, "c.config", c::config_init);
- TMP_LOAD (c, "c", c::init);
-
TMP_LOAD (cxx_guess, "cxx.guess", cxx::guess_init);
TMP_LOAD (cxx_config, "cxx.config", cxx::config_init);
TMP_LOAD (cxx, "cxx", cxx::init);
diff --git a/build2/buildfile b/build2/buildfile
index cfc46e5..7f4187e 100644
--- a/build2/buildfile
+++ b/build2/buildfile
@@ -7,7 +7,7 @@ import libs = libbutl%lib{butl}
include ../libbuild2/
libs += ../libbuild2/lib{build2}
-for m: bash bin cc in version
+for m: bash bin c cc in version
{
include ../libbuild2/$m/
libs += ../libbuild2/$m/lib{build2-$m}
@@ -48,9 +48,6 @@ obj{b}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"
#
if ($cxx.target == $build.host)
{
- c/obj{init}: cxx.poptions += \
- -DBUILD2_NATIVE_C=\"$regex.replace($recall($c.path), '\\', '\\\\')\"
-
cxx/obj{init}: cxx.poptions += \
-DBUILD2_NATIVE_CXX=\"$regex.replace($recall($cxx.path), '\\', '\\\\')\"
}
diff --git a/build2/c/init.hxx b/build2/c/init.hxx
deleted file mode 100644
index 77119a9..0000000
--- a/build2/c/init.hxx
+++ /dev/null
@@ -1,46 +0,0 @@
-// file : build2/c/init.hxx -*- C++ -*-
-// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
-// license : MIT; see accompanying LICENSE file
-
-#ifndef BUILD2_C_INIT_HXX
-#define BUILD2_C_INIT_HXX
-
-#include <libbuild2/types.hxx>
-#include <libbuild2/utility.hxx>
-
-#include <libbuild2/module.hxx>
-
-namespace build2
-{
- namespace c
- {
- bool
- guess_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
-
- bool
- config_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
-
- bool
- init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
- }
-}
-
-#endif // BUILD2_C_INIT_HXX
diff --git a/libbuild2/buildfile b/libbuild2/buildfile
index aad4e78..75731fc 100644
--- a/libbuild2/buildfile
+++ b/libbuild2/buildfile
@@ -5,7 +5,7 @@
# NOTE: remember to update bundled_modules in libbuild2/modules.cxx if adding
# a new module.
#
-./: lib{build2} bash/ bin/ cc/ in/ version/
+./: lib{build2} bash/ bin/ c/ cc/ in/ version/
import int_libs = libbutl%lib{butl}
diff --git a/libbuild2/c/buildfile b/libbuild2/c/buildfile
new file mode 100644
index 0000000..39a5d7a
--- /dev/null
+++ b/libbuild2/c/buildfile
@@ -0,0 +1,90 @@
+# file : libbuild2/c/buildfile
+# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import int_libs = libbutl%lib{butl}
+
+include ../
+int_libs += ../lib{build2}
+
+include ../cc/
+int_libs += ../cc/lib{build2-cc}
+
+./: lib{build2-c}: libul{build2-c}: {hxx ixx txx cxx}{** -**.test...} \
+ $int_libs
+
+# Unit tests.
+#
+exe{*.test}:
+{
+ test = true
+ install = false
+}
+
+for t: cxx{**.test...}
+{
+ d = $directory($t)
+ n = $name($t)...
+
+ ./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n}
+ $d/exe{$n}: libul{build2-c}: bin.whole = false
+}
+
+# Build options.
+#
+obja{*}: cxx.poptions += -DLIBBUILD2_C_STATIC_BUILD
+objs{*}: cxx.poptions += -DLIBBUILD2_C_SHARED_BUILD
+
+# Note that we used to compare complete target triplets but that proved too
+# strict (see libbuild2/buildfile for details).
+#
+cross = ($cxx.target.cpu != $build.host.cpu || \
+ $cxx.target.system != $build.host.system)
+
+# Pass native C compiler path (not forgetting to escape backslashes on
+# Windows). It is used as defaults for BUILD2_DEFAULT_C.
+#
+if! $cross
+{
+ obj{init}: cxx.poptions += \
+ -DBUILD2_NATIVE_C=\"$regex.replace($recall($c.path), '\\', '\\\\')\"
+
+ obja{init}: cxx.poptions += -DLIBBUILD2_C_STATIC_BUILD
+ objs{init}: cxx.poptions += -DLIBBUILD2_C_SHARED_BUILD
+}
+
+# Export options.
+#
+lib{build2-c}:
+{
+ cxx.export.poptions = "-I$out_root" "-I$src_root"
+ cxx.export.libs = $int_libs
+}
+
+liba{build2-c}: cxx.export.poptions += -DLIBBUILD2_C_STATIC
+libs{build2-c}: cxx.export.poptions += -DLIBBUILD2_C_SHARED
+
+# For pre-releases use the complete version to make sure they cannot be used
+# in place of another pre-release or the final version. See the version module
+# for details on the version.* variable values.
+#
+# And because this is a build system module, we also embed the same value as
+# the interface version (note that we cannot use build.version.interface for
+# bundled modules because we could be built with a different version of the
+# build system).
+#
+ver = ($version.pre_release \
+ ? "$version.project_id" \
+ : "$version.major.$version.minor")
+
+lib{build2-c}: bin.lib.version = @"-$ver"
+libs{build2-c}: bin.lib.load_suffix = "-$ver"
+
+# Install into the libbuild2/c/ subdirectory of, say, /usr/include/
+# recreating subdirectories.
+#
+{hxx ixx txx}{*}:
+{
+ install = include/libbuild2/c/
+ install.subdirs = true
+}
diff --git a/libbuild2/c/export.hxx b/libbuild2/c/export.hxx
new file mode 100644
index 0000000..6fe3203
--- /dev/null
+++ b/libbuild2/c/export.hxx
@@ -0,0 +1,38 @@
+// file : libbuild2/c/export.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#pragma once
+
+// Normally we don't export class templates (but do complete specializations),
+// inline functions, and classes with only inline member functions. Exporting
+// classes that inherit from non-exported/imported bases (e.g., std::string)
+// will end up badly. The only known workarounds are to not inherit or to not
+// export. Also, MinGW GCC doesn't like seeing non-exported functions being
+// used before their inline definition. The workaround is to reorder code. In
+// the end it's all trial and error.
+
+#if defined(LIBBUILD2_C_STATIC) // Using static.
+# define LIBBUILD2_C_SYMEXPORT
+#elif defined(LIBBUILD2_C_STATIC_BUILD) // Building static.
+# define LIBBUILD2_C_SYMEXPORT
+#elif defined(LIBBUILD2_C_SHARED) // Using shared.
+# ifdef _WIN32
+# define LIBBUILD2_C_SYMEXPORT __declspec(dllimport)
+# else
+# define LIBBUILD2_C_SYMEXPORT
+# endif
+#elif defined(LIBBUILD2_C_SHARED_BUILD) // Building shared.
+# ifdef _WIN32
+# define LIBBUILD2_C_SYMEXPORT __declspec(dllexport)
+# else
+# define LIBBUILD2_C_SYMEXPORT
+# endif
+#else
+// If none of the above macros are defined, then we assume we are being used
+// by some third-party build system that cannot/doesn't signal the library
+// type. Note that this fallback works for both static and shared but in case
+// of shared will be sub-optimal compared to having dllimport.
+//
+# define LIBBUILD2_C_SYMEXPORT // Using static or shared.
+#endif
diff --git a/build2/c/init.cxx b/libbuild2/c/init.cxx
index 6d271a7..43d647f 100644
--- a/build2/c/init.cxx
+++ b/libbuild2/c/init.cxx
@@ -1,8 +1,8 @@
-// file : build2/c/init.cxx -*- C++ -*-
+// file : libbuild2/c/init.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <build2/c/init.hxx>
+#include <libbuild2/c/init.hxx>
#include <libbuild2/scope.hxx>
#include <libbuild2/diagnostics.hxx>
@@ -10,7 +10,7 @@
#include <libbuild2/cc/guess.hxx>
#include <libbuild2/cc/module.hxx>
-#include <build2/c/target.hxx>
+#include <libbuild2/c/target.hxx>
#ifndef BUILD2_DEFAULT_C
# ifdef BUILD2_NATIVE_C
@@ -354,5 +354,22 @@ namespace build2
m->init (rs, loc, hints);
return true;
}
+
+ static const module_functions mod_functions[] =
+ {
+ // NOTE: don't forget to also update the documentation in init.hxx if
+ // changing anything here.
+
+ {"c.guess", nullptr, guess_init},
+ {"c.config", nullptr, config_init},
+ {"c", nullptr, init},
+ {nullptr, nullptr, nullptr}
+ };
+
+ const module_functions*
+ build2_c_load ()
+ {
+ return mod_functions;
+ }
}
}
diff --git a/libbuild2/c/init.hxx b/libbuild2/c/init.hxx
new file mode 100644
index 0000000..92d12a3
--- /dev/null
+++ b/libbuild2/c/init.hxx
@@ -0,0 +1,32 @@
+// file : libbuild2/c/init.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef LIBBUILD2_C_INIT_HXX
+#define LIBBUILD2_C_INIT_HXX
+
+#include <libbuild2/types.hxx>
+#include <libbuild2/utility.hxx>
+
+#include <libbuild2/module.hxx>
+
+#include <libbuild2/c/export.hxx>
+
+namespace build2
+{
+ namespace c
+ {
+ // Module `c` does not require bootstrapping.
+ //
+ // Submodules:
+ //
+ // `c.guess` -- registers and sets some variables.
+ // `c.config` -- loads c.guess and sets more variables.
+ // `c` -- loads c.config and registers target types and rules.
+ //
+ extern "C" LIBBUILD2_C_SYMEXPORT const module_functions*
+ build2_c_load ();
+ }
+}
+
+#endif // LIBBUILD2_C_INIT_HXX
diff --git a/build2/c/target.hxx b/libbuild2/c/target.hxx
index 88e2ef4..b35beab 100644
--- a/build2/c/target.hxx
+++ b/libbuild2/c/target.hxx
@@ -1,9 +1,9 @@
-// file : build2/c/target.hxx -*- C++ -*-
+// file : libbuild2/c/target.hxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#ifndef BUILD2_C_TARGET_HXX
-#define BUILD2_C_TARGET_HXX
+#ifndef LIBBUILD2_C_TARGET_HXX
+#define LIBBUILD2_C_TARGET_HXX
#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>
@@ -19,4 +19,4 @@ namespace build2
}
}
-#endif // BUILD2_C_TARGET_HXX
+#endif // LIBBUILD2_C_TARGET_HXX
diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx
index 4e7080a..37bc817 100644
--- a/libbuild2/module.cxx
+++ b/libbuild2/module.cxx
@@ -39,6 +39,7 @@ namespace build2
static const char* bundled_modules[] = {
"bash",
"bin",
+ "c",
"cc",
"in",
"version"
diff --git a/tests/libbuild2/buildfile b/tests/libbuild2/buildfile
index 1a2d594..1d7faf7 100644
--- a/tests/libbuild2/buildfile
+++ b/tests/libbuild2/buildfile
@@ -4,7 +4,7 @@
import libs = build2%lib{build2}
-for m: bash bin cc in version
+for m: bash bin c cc in version
import libs += build2%lib{build2-$m}
exe{driver}: {hxx cxx}{*} $libs testscript
diff --git a/tests/libbuild2/driver.cxx b/tests/libbuild2/driver.cxx
index 679b0a4..e17cdc5 100644
--- a/tests/libbuild2/driver.cxx
+++ b/tests/libbuild2/driver.cxx
@@ -10,6 +10,7 @@
#include <libbuild2/in/init.hxx>
#include <libbuild2/bin/init.hxx>
+#include <libbuild2/c/init.hxx>
#include <libbuild2/cc/init.hxx>
#include <libbuild2/bash/init.hxx>
#include <libbuild2/version/init.hxx>
@@ -26,6 +27,7 @@ main (int, char* argv[])
bin::build2_bin_load ();
cc::build2_cc_load ();
+ c::build2_c_load ();
version::build2_version_load ();
in::build2_in_load ();
bash::build2_bash_load ();