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