aboutsummaryrefslogtreecommitdiff
path: root/tools/mhmake/src/rule.h
blob: 04827b1298925cb7459ea6686fccbb1c8831da41 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*  This file is part of mhmake.
 *
 *  Copyright (C) 2001-2010 marha@sourceforge.net
 *
 *  Mhmake is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Mhmake is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Mhmake.  If not, see <http://www.gnu.org/licenses/>.
*/

/* $Rev$ */

#ifndef __RULE_H__
#define __RULE_H__

#include "refptr.h"
#include "md5.h"
class mhmakefileparser;
class fileinfo;

class rule: public refbase
{
  vector<string> m_Commands;
  string m_Stem;   // Contains the stem in case the rule is part of an implicit rule (filled in in the implicit search)
  mhmakefileparser* m_pMakefile;
  vector< fileinfo* > m_Targets;  /* Targets that are build with this rule, do not use refptr here because otherwise we get circular references */
public:
  rule(mhmakefileparser *pMakefile): m_pMakefile(pMakefile)
  {
  }

  void AddCommand(const string &Command)
  {
    if (!Command.empty())
      m_Commands.push_back(Command);
  }
  vector<string>& GetCommands()
  {
    return m_Commands;
  }
  void PrintCommands(fileinfo *pTarget=NULL) const;

  void SetStem(const string &Stem)
  {
    m_Stem=Stem;
  }
  const string &GetStem() const
  {
    return m_Stem;
  }
  void SetMakefile(mhmakefileparser *pMakefile)
  {
    m_pMakefile=pMakefile;
  }
  mhmakefileparser *GetMakefile()
  {
    return m_pMakefile;
  }
  bool operator != (const rule &Rule);

  void AddTarget(fileinfo *pTarget)
  {
    m_Targets.push_back(pTarget);
  }
  void SetTargetsIsBuild(uint32 Md5_32);
  void SetTargetsIsBuilding(const fileinfo *pSrc);
};

typedef vector<pair<vector<fileinfo*>,refptr<rule> > > implicitruledep_t;
typedef pair<fileinfo *, implicitruledep_t > implicitrule_t;

class IMPLICITRULE
{
  static set<rule*> m_ImplicitRuleRecurseDetStack;
  static vector<implicitrule_t> m_ImplicitRules;  // Use a vector and not a map because the order of the implicit rules is important
public:
  static void AddImplicitRule(fileinfo *pTarget,const vector<fileinfo*> &Deps,refptr<rule> pRule);
  static void SearchImplicitRule(const fileinfo *pTarget, implicitruledep_t &Result);
  static void PrintImplicitRules();
  static bool PushRule(rule *pRule)
  {
    set<rule*>::iterator pFound=m_ImplicitRuleRecurseDetStack.find(pRule);
    if (pFound==m_ImplicitRuleRecurseDetStack.end())
    {
      m_ImplicitRuleRecurseDetStack.insert(pRule);
      return false;
    }
    else
    {
      return true;
    }
  }
  static void PopRule(rule *pRule)
  {
    m_ImplicitRuleRecurseDetStack.erase(pRule);
  }
};

extern refptr<rule> NullRule;

#endif