15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- SearchDirs.h -------------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_MC_SEARCHDIRS_H_
1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_MC_SEARCHDIRS_H_
1137b74a387bb3993387029859c2d9d051c41c724eStephen Hines
1237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/MC/Input.h"
1337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/Path.h"
1437b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/Compiler.h"
1522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <llvm/ADT/StringRef.h>
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <string>
1937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include <vector>
2022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaonamespace mcld {
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass MCLDDirectory;
2437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass MCLDFile;
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class SearchDirs
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief SearchDirs contains the list of paths that MCLinker will search for
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  archive libraries and control scripts.
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  SearchDirs is customized for linking. It handles -L on the command line
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  and SEARCH_DIR macro in the link script.
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see MCLDDirectory.
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
3537b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass SearchDirs {
3637b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef std::vector<MCLDDirectory*> DirList;
385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef DirList::iterator iterator;
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef DirList::const_iterator const_iterator;
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
4137b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  SearchDirs();
4322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
4437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  explicit SearchDirs(const sys::fs::Path& pSysRoot);
4522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~SearchDirs();
475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
48affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  // find - give a namespec, return a real path of the shared object.
4937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  sys::fs::Path* find(const std::string& pNamespec,
5037b74a387bb3993387029859c2d9d051c41c724eStephen Hines                      mcld::Input::Type pPreferType);
515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
5237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const sys::fs::Path* find(const std::string& pNamespec,
5337b74a387bb3993387029859c2d9d051c41c724eStephen Hines                            mcld::Input::Type pPreferType) const;
545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
5522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  void setSysRoot(const sys::fs::Path& pSysRoot) { m_SysRoot = pSysRoot; }
5622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  const sys::fs::Path& sysroot() const { return m_SysRoot; }
575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
5822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  // -----  iterators  ----- //
5922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  const_iterator begin() const { return m_DirList.begin(); }
6037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator begin() { return m_DirList.begin(); }
6137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const_iterator end() const { return m_DirList.end(); }
6237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator end() { return m_DirList.end(); }
635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // -----  modifiers  ----- //
656f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines  bool insert(const char* pDirectory);
666f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines
6722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  bool insert(const std::string& pDirectory);
6822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
6922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  bool insert(const sys::fs::Path& pDirectory);
705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
7137b74a387bb3993387029859c2d9d051c41c724eStephen Hines private:
725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  DirList m_DirList;
7322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  sys::fs::Path m_SysRoot;
745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
7537b74a387bb3993387029859c2d9d051c41c724eStephen Hines private:
7637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  DISALLOW_COPY_AND_ASSIGN(SearchDirs);
7737b74a387bb3993387029859c2d9d051c41c724eStephen Hines};
785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
7937b74a387bb3993387029859c2d9d051c41c724eStephen Hines}  // namespace mcld
805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
8137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // MCLD_MC_SEARCHDIRS_H_
82