xref: /dflybsd-src/contrib/binutils-2.34/gold/dirsearch.h (revision b52ef7118d1621abed722c5bbbd542210290ecef)
1*fae548d3Szrj // dirsearch.h -- directory searching for gold  -*- C++ -*-
2*fae548d3Szrj 
3*fae548d3Szrj // Copyright (C) 2006-2020 Free Software Foundation, Inc.
4*fae548d3Szrj // Written by Ian Lance Taylor <iant@google.com>.
5*fae548d3Szrj 
6*fae548d3Szrj // This file is part of gold.
7*fae548d3Szrj 
8*fae548d3Szrj // This program is free software; you can redistribute it and/or modify
9*fae548d3Szrj // it under the terms of the GNU General Public License as published by
10*fae548d3Szrj // the Free Software Foundation; either version 3 of the License, or
11*fae548d3Szrj // (at your option) any later version.
12*fae548d3Szrj 
13*fae548d3Szrj // This program is distributed in the hope that it will be useful,
14*fae548d3Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
15*fae548d3Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*fae548d3Szrj // GNU General Public License for more details.
17*fae548d3Szrj 
18*fae548d3Szrj // You should have received a copy of the GNU General Public License
19*fae548d3Szrj // along with this program; if not, write to the Free Software
20*fae548d3Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21*fae548d3Szrj // MA 02110-1301, USA.
22*fae548d3Szrj 
23*fae548d3Szrj #ifndef GOLD_DIRSEARCH_H
24*fae548d3Szrj #define GOLD_DIRSEARCH_H
25*fae548d3Szrj 
26*fae548d3Szrj #include <string>
27*fae548d3Szrj #include <list>
28*fae548d3Szrj 
29*fae548d3Szrj #include "options.h"
30*fae548d3Szrj #include "token.h"
31*fae548d3Szrj 
32*fae548d3Szrj namespace gold
33*fae548d3Szrj {
34*fae548d3Szrj 
35*fae548d3Szrj class General_options;
36*fae548d3Szrj class Workqueue;
37*fae548d3Szrj 
38*fae548d3Szrj // A simple interface to manage directories to be searched for
39*fae548d3Szrj // libraries.
40*fae548d3Szrj 
41*fae548d3Szrj class Dirsearch
42*fae548d3Szrj {
43*fae548d3Szrj  public:
Dirsearch()44*fae548d3Szrj   Dirsearch()
45*fae548d3Szrj     : directories_(NULL), token_(true)
46*fae548d3Szrj   { }
47*fae548d3Szrj 
48*fae548d3Szrj   // Set the list of directories to search.
49*fae548d3Szrj   void
50*fae548d3Szrj   initialize(Workqueue*, const General_options::Dir_list*);
51*fae548d3Szrj 
52*fae548d3Szrj   // Search for a file, giving one or two names to search for (the
53*fae548d3Szrj   // second one may be empty).  Return a full path name for the file,
54*fae548d3Szrj   // or the empty string if it could not be found.  This may only be
55*fae548d3Szrj   // called if the token is not blocked.  Set *IS_IN_SYSROOT if the
56*fae548d3Szrj   // file was found in a directory which is in the sysroot.  *PINDEX
57*fae548d3Szrj   // should be set to zero the first time this is called; it will be
58*fae548d3Szrj   // updated with the index of the directory where the file is found,
59*fae548d3Szrj   // and that value plus one may be used to find the next file with
60*fae548d3Szrj   // the same name(s).
61*fae548d3Szrj   std::string
62*fae548d3Szrj   find(const std::vector<std::string>& names, bool* is_in_sysroot,
63*fae548d3Szrj        int* pindex, std::string *found_name) const;
64*fae548d3Szrj 
65*fae548d3Szrj   // Return the blocker token which controls access.
66*fae548d3Szrj   Task_token*
token()67*fae548d3Szrj   token()
68*fae548d3Szrj   { return &this->token_; }
69*fae548d3Szrj 
70*fae548d3Szrj   // Search for a file in a directory list.  This is a low-level function and
71*fae548d3Szrj   // therefore can be used before options and parameters are set.
72*fae548d3Szrj   static std::string
73*fae548d3Szrj   find_file_in_dir_list(const std::string& name,
74*fae548d3Szrj                         const General_options::Dir_list& directories,
75*fae548d3Szrj                         const std::string& extra_search_dir);
76*fae548d3Szrj 
77*fae548d3Szrj  private:
78*fae548d3Szrj   // We can not copy this class.
79*fae548d3Szrj   Dirsearch(const Dirsearch&);
80*fae548d3Szrj   Dirsearch& operator=(const Dirsearch&);
81*fae548d3Szrj 
82*fae548d3Szrj   // Directories to search.
83*fae548d3Szrj   const General_options::Dir_list* directories_;
84*fae548d3Szrj   // Blocker token to control access from tasks.
85*fae548d3Szrj   Task_token token_;
86*fae548d3Szrj };
87*fae548d3Szrj 
88*fae548d3Szrj } // End namespace gold.
89*fae548d3Szrj 
90*fae548d3Szrj #endif // !defined(GOLD_DIRSEARCH_H)
91