From 627991f892f431988c6a683b1305aee5510920dd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 19 Jan 2016 13:32:30 +0200 Subject: Basic "Hello World" C++ library with build2 --- .gitignore | 4 ++++ build/.gitignore | 1 + build/bootstrap.build | 9 +++++++++ build/export.build | 6 ++++++ build/root.build | 10 ++++++++++ buildfile | 3 +++ hello/buildfile | 8 ++++++++ hello/hello | 11 +++++++++++ hello/hello.cxx | 16 ++++++++++++++++ manifest | 10 ++++++++++ tests/.gitignore | 1 + tests/build/.gitignore | 1 + tests/build/bootstrap.build | 5 +++++ tests/build/root.build | 10 ++++++++++ tests/buildfile | 3 +++ tests/test/buildfile | 4 ++++ tests/test/driver.cxx | 11 +++++++++++ tests/test/test.out | 1 + version | 1 + 19 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 build/.gitignore create mode 100644 build/bootstrap.build create mode 100644 build/export.build create mode 100644 build/root.build create mode 100644 buildfile create mode 100644 hello/buildfile create mode 100644 hello/hello create mode 100644 hello/hello.cxx create mode 100644 manifest create mode 100644 tests/.gitignore create mode 100644 tests/build/.gitignore create mode 100644 tests/build/bootstrap.build create mode 100644 tests/build/root.build create mode 100644 tests/buildfile create mode 100644 tests/test/buildfile create mode 100644 tests/test/driver.cxx create mode 100644 tests/test/test.out create mode 100644 version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..274fdd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.so +*.a +core diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/build/bootstrap.build b/build/bootstrap.build new file mode 100644 index 0000000..ba26f3b --- /dev/null +++ b/build/bootstrap.build @@ -0,0 +1,9 @@ +project = libhello +version = 1.0.0 + +using config +using dist +using test +using install + +dist.package = $project-$version diff --git a/build/export.build b/build/export.build new file mode 100644 index 0000000..1eb73b7 --- /dev/null +++ b/build/export.build @@ -0,0 +1,6 @@ +$out_root/: +{ + include hello/ +} + +export $out_root/hello/lib{hello} diff --git a/build/root.build b/build/root.build new file mode 100644 index 0000000..ebe16d5 --- /dev/null +++ b/build/root.build @@ -0,0 +1,10 @@ +using cxx + +hxx{*}: extension = +cxx{*}: extension = cxx + +cxx.std = 11 + +# Don't install tests. +# +tests/: install = false diff --git a/buildfile b/buildfile new file mode 100644 index 0000000..f846f89 --- /dev/null +++ b/buildfile @@ -0,0 +1,3 @@ +d = hello/ tests/ +./: $d doc{version} file{manifest} +include $d diff --git a/hello/buildfile b/hello/buildfile new file mode 100644 index 0000000..4903a33 --- /dev/null +++ b/hello/buildfile @@ -0,0 +1,8 @@ +lib{hello}: {hxx cxx}{hello} + +cxx.poptions += -I$src_root +lib{hello}: cxx.export.poptions = -I$src_root + +# Install into the hello/ subdirectory of, say, /usr/include/. +# +install.include = $install.include/hello diff --git a/hello/hello b/hello/hello new file mode 100644 index 0000000..4f85114 --- /dev/null +++ b/hello/hello @@ -0,0 +1,11 @@ +// file: hello/hello -*- C++ -*- + +#pragma once + +#include + +namespace hello +{ + void + say (const std::string& name); +} diff --git a/hello/hello.cxx b/hello/hello.cxx new file mode 100644 index 0000000..65d0aa7 --- /dev/null +++ b/hello/hello.cxx @@ -0,0 +1,16 @@ +// file: hello/hello.cxx -*- C++ -*- + +#include + +#include + +using namespace std; + +namespace hello +{ + void + say (const string& n) + { + cout << "Hello, " << n << '!' << endl; + } +} diff --git a/manifest b/manifest new file mode 100644 index 0000000..3a11ba8 --- /dev/null +++ b/manifest @@ -0,0 +1,10 @@ +: 1 +name: libhello +version: 1.0.0 +summary: The "Hello World" example library +license: MIT +tags: c++, hello, world, example +description: A simple library that implements the "Hello World" example in\ + C++. Its primary goal is to show a canonical build2/bpkg project/package. +url: http://www.example.org/libhello +email: hello-users@example.org diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..e54525b --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +driver diff --git a/tests/build/.gitignore b/tests/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/tests/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build new file mode 100644 index 0000000..2c2de24 --- /dev/null +++ b/tests/build/bootstrap.build @@ -0,0 +1,5 @@ +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/tests/build/root.build b/tests/build/root.build new file mode 100644 index 0000000..672eda8 --- /dev/null +++ b/tests/build/root.build @@ -0,0 +1,10 @@ +using cxx + +hxx{*}: extension = +cxx{*}: extension = cxx + +cxx.std = 11 + +# Every exe{} in this subproject is by default a test. +# +test.exe = true diff --git a/tests/buildfile b/tests/buildfile new file mode 100644 index 0000000..4dcbe2a --- /dev/null +++ b/tests/buildfile @@ -0,0 +1,3 @@ +d = test/ +./: $d +include $d diff --git a/tests/test/buildfile b/tests/test/buildfile new file mode 100644 index 0000000..a46969d --- /dev/null +++ b/tests/test/buildfile @@ -0,0 +1,4 @@ +import libs = libhello%lib{hello} + +exe{driver}: cxx{driver} $libs +exe{driver}: test.output = test.out diff --git a/tests/test/driver.cxx b/tests/test/driver.cxx new file mode 100644 index 0000000..59bfb2d --- /dev/null +++ b/tests/test/driver.cxx @@ -0,0 +1,11 @@ +// file: tests/test/driver.cxx -*- C++ -*- + +#include + +int +main () +{ + using hello::say; + + say ("World"); +} diff --git a/tests/test/test.out b/tests/test/test.out new file mode 100644 index 0000000..8ab686e --- /dev/null +++ b/tests/test/test.out @@ -0,0 +1 @@ +Hello, World! diff --git a/version b/version new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.0.0 -- cgit v1.1