SearchDirs.h revision 533eae20118036f425f27bf0536ef0ccbb090b65
1//===- SearchDirs.h -------------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef MCLD_MC_SEARCHDIRS_H
10#define MCLD_MC_SEARCHDIRS_H
11#include <mcld/ADT/Uncopyable.h>
12#include <mcld/MC/Input.h>
13#include <mcld/Support/Path.h>
14
15#include <llvm/ADT/StringRef.h>
16
17#include <vector>
18#include <string>
19
20namespace mcld {
21
22class MCLDFile;
23class MCLDDirectory;
24
25/** \class SearchDirs
26 *  \brief SearchDirs contains the list of paths that MCLinker will search for
27 *  archive libraries and control scripts.
28 *
29 *  SearchDirs is customized for linking. It handles -L on the command line
30 *  and SEARCH_DIR macro in the link script.
31 *
32 *  @see MCLDDirectory.
33 */
34class SearchDirs : private Uncopyable
35{
36public:
37  typedef std::vector<MCLDDirectory*> DirList;
38  typedef DirList::iterator iterator;
39  typedef DirList::const_iterator const_iterator;
40
41public:
42  SearchDirs();
43
44  SearchDirs(const sys::fs::Path& pSysRoot);
45
46  ~SearchDirs();
47
48  // find - give a namespec, return a real path of the shared object.
49  sys::fs::Path*
50  find(const std::string& pNamespec, mcld::Input::Type pPreferType);
51
52  const sys::fs::Path*
53  find(const std::string& pNamespec, mcld::Input::Type pPreferType) const;
54
55  void setSysRoot(const sys::fs::Path& pSysRoot) { m_SysRoot = pSysRoot; }
56  const sys::fs::Path& sysroot() const { return m_SysRoot; }
57
58  // -----  iterators  ----- //
59  const_iterator begin() const { return m_DirList.begin(); }
60  iterator       begin()       { return m_DirList.begin(); }
61  const_iterator end  () const { return m_DirList.end();   }
62  iterator       end  ()       { return m_DirList.end();   }
63
64  // -----  modifiers  ----- //
65  bool insert(const char* pDirectory);
66
67  bool insert(const std::string& pDirectory);
68
69  bool insert(const sys::fs::Path& pDirectory);
70
71private:
72  DirList m_DirList;
73  sys::fs::Path m_SysRoot;
74};
75
76} // namespace of mcld
77
78#endif
79
80