diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-03 14:02:56 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-12-03 14:02:56 +0200 |
commit | 3b56319cb635c71768106c01b04c5fd719b93242 (patch) | |
tree | c79ffb6791661d8859855fdaecbdbb2a4674a192 | |
parent | a693507feb11950899b3fcfcd9ee230fd7baa61f (diff) |
Initial build tool sketch (simulation)
To build:
g++-4.9 -std=c++11 -g -I.. -o bd bd.cxx
-rw-r--r-- | build/bd.cxx | 63 | ||||
-rw-r--r-- | build/target | 69 |
2 files changed, 132 insertions, 0 deletions
diff --git a/build/bd.cxx b/build/bd.cxx new file mode 100644 index 0000000..918434a --- /dev/null +++ b/build/bd.cxx @@ -0,0 +1,63 @@ +// file : build/bd.cxx +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <vector> +#include <iostream> + +#include <build/target> + +using namespace std; + +namespace build +{ + bool + update (target& t) + { + const targets& ps (t.prerequisites ()); + + for (target& p: ps) + if (!update (p)) + return false; + + //@@ TODO: check for existance, compare timestamps. + + auto r (t.rule ()); + return r != 0 ? r (t, t.prerequisites ()) : true; + } +} + +using namespace build; + +bool +cxx_compile_rule (target& t, const targets& p) +{ + //@@ TODO: actually execute + + cerr << "c++ " << t.name () << endl; + return true; +} + +bool +cxx_link_rule (target& t, const targets& p) +{ + cerr << "ld " << t.name () << endl; + return true; +} + +int +main (int argc, char* argv[]) +{ + exe bd ("bd"); + obj bd_o ("bd.o"); + bd.prerequisite (bd_o); + bd.rule (&cxx_link_rule); + + cxx bd_cxx ("bd.cxx"); + hxx target ("target"); + bd_o.prerequisite (bd_cxx); + bd_o.prerequisite (target); + bd_o.rule (&cxx_compile_rule); + + update (bd); +} diff --git a/build/target b/build/target new file mode 100644 index 0000000..e6f05a5 --- /dev/null +++ b/build/target @@ -0,0 +1,69 @@ +// file : build/target -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <string> +#include <vector> +#include <functional> + +namespace build +{ + class target; + typedef std::vector<std::reference_wrapper<target>> targets; + + class target + { + public: + target (std::string n): name_ (n) {} + + const std::string& + name () const {return name_;} + + const targets& + prerequisites () const {return prerequisites_;} + + targets& + prerequisites () {return prerequisites_;} + + void + prerequisite (target& t) {prerequisites_.push_back (t);} + + public: + typedef bool (*rule_type) (target&, const targets&); + + rule_type + rule () const {return rule_;} + + void + rule (rule_type r) {rule_ = r;} + + private: + target (const target&) = delete; + target& operator= (const target&) = delete; + + private: + std::string name_; + targets prerequisites_; + rule_type rule_ {0}; + }; + + class exe: public target + { + using target::target; + }; + + class obj: public target + { + using target::target; + }; + + class hxx: public target + { + using target::target; + }; + + class cxx: public target + { + using target::target; + }; +} |