aboutsummaryrefslogtreecommitdiff
path: root/build/target.txx
blob: a2930185f1e22ecc6486d8954429b7a69d85a641 (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
// file      : build/target.txx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build/scope>
#include <build/context>     // extension_pool
#include <build/diagnostics>
#include <build/prerequisite>

namespace build
{
  template <const char* ext>
  const std::string&
  target_extension_fix (const target_key&, scope&)
  {
    return extension_pool.find (ext);
  }

  template <const char* var>
  const std::string&
  target_extension_var (const target_key& tk, scope& s)
  {
    auto l (s[var]);

    if (!l)
    {
      diag_record dr;
      dr << fail << "no default extension in variable " << var
         << info << "required to derive file name for ";

      // This is a bit hacky: we may be dealing with a target (see
      // file::derive_path()) or prerequsite (see search_existing_file()).
      // So we are going to check if dir is absolute. If it is, then
      // we assume this is a target, otherwise -- prerequsite.
      //
      if (tk.dir->absolute ())
        dr << "target " << tk;
      else
      {
        const std::string* proj (nullptr); // Used for local prerequisites.
        dr << "prerequisite " << prerequisite_key {&proj, tk, &s};
      }
    }

    return extension_pool.find (as<std::string> (*l));
  }
}