From 3b56319cb635c71768106c01b04c5fd719b93242 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 3 Dec 2014 14:02:56 +0200 Subject: Initial build tool sketch (simulation) To build: g++-4.9 -std=c++11 -g -I.. -o bd bd.cxx --- build/bd.cxx | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ build/target | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 build/bd.cxx create mode 100644 build/target (limited to 'build') 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 +#include + +#include + +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 +#include +#include + +namespace build +{ + class target; + typedef std::vector> 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; + }; +} -- cgit v1.1