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

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

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

  template <const char* var, const char* def>
  const string*
  target_extension_var (const target_key& tk, scope& s)
  {
    // Include target type/pattern-specific variables.
    //
    if (auto l = s.lookup (tk, var))
    {
      // Help the user here and strip leading '.' from the extension.
      //
      const string& e (as<string> (*l));
      return &extension_pool.find (
        !e.empty () && e.front () == '.' ? string (e, 1) : e);
    }

    return def != nullptr ? &extension_pool.find (def) : nullptr;
  }
}