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 
20 namespace mcld {
21 
22 class MCLDFile;
23 class 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  */
34 class SearchDirs : private Uncopyable
35 {
36 public:
37   typedef std::vector<MCLDDirectory*> DirList;
38   typedef DirList::iterator iterator;
39   typedef DirList::const_iterator const_iterator;
40 
41 public:
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 
setSysRoot(const sys::fs::Path & pSysRoot)55   void setSysRoot(const sys::fs::Path& pSysRoot) { m_SysRoot = pSysRoot; }
sysroot()56   const sys::fs::Path& sysroot() const { return m_SysRoot; }
57 
58   // -----  iterators  ----- //
begin()59   const_iterator begin() const { return m_DirList.begin(); }
begin()60   iterator       begin()       { return m_DirList.begin(); }
end()61   const_iterator end  () const { return m_DirList.end();   }
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 
71 private:
72   DirList m_DirList;
73   sys::fs::Path m_SysRoot;
74 };
75 
76 } // namespace of mcld
77 
78 #endif
79 
80