aboutsummaryrefslogtreecommitdiff
path: root/build2/bash/init.cxx
blob: 83bfdb9814597bd40c2c00858514479ba0c72930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// file      : build2/bash/init.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build2/bash/init.hxx>

#include <libbuild2/scope.hxx>
#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/diagnostics.hxx>

#include <build2/install/utility.hxx>

#include <build2/bash/rule.hxx>
#include <build2/bash/target.hxx>
#include <build2/bash/utility.hxx>

using namespace std;

namespace build2
{
  namespace bash
  {
    static const in_rule in_rule_;
    static const install_rule install_rule_ (in_rule_);

    bool
    init (scope& rs,
          scope& bs,
          const location& l,
          unique_ptr<module_base>&,
          bool,
          bool,
          const variable_map&)
    {
      tracer trace ("bash::init");
      l5 ([&]{trace << "for " << bs;});

      // Load in.base (in.* varibales, in{} target type).
      //
      if (!cast_false<bool> (rs["in.base.loaded"]))
        load_module (rs, rs, "in.base", l);

      bool install_loaded (cast_false<bool> (rs["install.loaded"]));

      // Register target types and configure default installability.
      //
      bs.target_types.insert<bash> ();

      if (install_loaded)
      {
        using namespace install;

        // Install into bin/<project>/ by default stripping the .bash
        // extension from <project> if present.
        //
        const project_name& p (cast<project_name> (rs.vars[var_project]));

        install_path<bash> (bs, dir_path ("bin") /= project_base (p));
        install_mode<bash> (bs, "644");
      }

      // Register rules.
      //
      {
        auto& r (bs.rules);

        r.insert<exe> (perform_update_id,   "bash.in", in_rule_);
        r.insert<exe> (perform_clean_id,    "bash.in", in_rule_);
        r.insert<exe> (configure_update_id, "bash.in", in_rule_);

        r.insert<bash> (perform_update_id,   "bash.in", in_rule_);
        r.insert<bash> (perform_clean_id,    "bash.in", in_rule_);
        r.insert<bash> (configure_update_id, "bash.in", in_rule_);

        if (install_loaded)
        {
          r.insert<exe>  (perform_install_id,   "bash.install",   install_rule_);
          r.insert<exe>  (perform_uninstall_id, "bash.uninstall", install_rule_);

          r.insert<bash> (perform_install_id,   "bash.install",   install_rule_);
          r.insert<bash> (perform_uninstall_id, "bash.uninstall", install_rule_);
        }
      }

      return true;
    }
  }
}