+// Add the sysroot, if any, to the search paths.
+
+void
+General_options::add_sysroot()
+{
+ if (this->sysroot_.empty())
+ {
+ this->sysroot_ = get_default_sysroot();
+ if (this->sysroot_.empty())
+ return;
+ }
+
+ const char* sysroot = this->sysroot_.c_str();
+ char* canonical_sysroot = lrealpath(sysroot);
+
+ for (Dir_list::iterator p = this->search_path_.begin();
+ p != this->search_path_.end();
+ ++p)
+ p->add_sysroot(sysroot, canonical_sysroot);
+
+ free(canonical_sysroot);
+}
+
+// Search_directory methods.
+
+// This is called if we have a sysroot. Apply the sysroot if
+// appropriate. Record whether the directory is in the sysroot.
+
+void
+Search_directory::add_sysroot(const char* sysroot,
+ const char* canonical_sysroot)
+{
+ gold_assert(*sysroot != '\0');
+ if (this->put_in_sysroot_)
+ {
+ if (!IS_DIR_SEPARATOR(this->name_[0])
+ && !IS_DIR_SEPARATOR(sysroot[strlen(sysroot) - 1]))
+ this->name_ = '/' + this->name_;
+ this->name_ = sysroot + this->name_;
+ this->is_in_sysroot_ = true;
+ }
+ else
+ {
+ // Check whether this entry is in the sysroot. To do this
+ // correctly, we need to use canonical names. Otherwise we will
+ // get confused by the ../../.. paths that gcc tends to use.
+ char* canonical_name = lrealpath(this->name_.c_str());
+ int canonical_name_len = strlen(canonical_name);
+ int canonical_sysroot_len = strlen(canonical_sysroot);
+ if (canonical_name_len > canonical_sysroot_len
+ && IS_DIR_SEPARATOR(canonical_name[canonical_sysroot_len]))
+ {
+ canonical_name[canonical_sysroot_len] = '\0';
+ if (FILENAME_CMP(canonical_name, canonical_sysroot) == 0)
+ this->is_in_sysroot_ = true;
+ }
+ free(canonical_name);
+ }
+}
+
+// Input_arguments methods.
+
+// Add a file to the list.
+
+void
+Input_arguments::add_file(const Input_file_argument& file)
+{
+ if (!this->in_group_)
+ this->input_argument_list_.push_back(Input_argument(file));
+ else
+ {
+ gold_assert(!this->input_argument_list_.empty());
+ gold_assert(this->input_argument_list_.back().is_group());
+ this->input_argument_list_.back().group()->add_file(file);
+ }
+}
+
+// Start a group.
+
+void
+Input_arguments::start_group()
+{
+ gold_assert(!this->in_group_);
+ Input_file_group* group = new Input_file_group();
+ this->input_argument_list_.push_back(Input_argument(group));
+ this->in_group_ = true;
+}
+
+// End a group.
+
+void
+Input_arguments::end_group()
+{
+ gold_assert(this->in_group_);
+ this->in_group_ = false;
+}
+
+// Command_line options.