Commit f6c89bb1 authored by jan.koester's avatar jan.koester
Browse files

split patch

parent 58c9d5cc
Loading
Loading
Loading
Loading
+13 −0
Changes for parser.cpp: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,6 +28,18 @@ std::vector<std::string> Parser::split_words(const std::string& s) {
    return result;
}

std::string Parser::normalize_target(const std::string& s) {
    // Strip leading "./" segments (e.g. "./kernel/bounds.s" -> "kernel/bounds.s",
    // "./%.s" -> "%.s"). Leave a bare "." and "../" alone.
    std::string r = s;
    while (r.size() >= 2 && r[0] == '.' && r[1] == '/') {
        size_t i = 2;
        while (i < r.size() && r[i] == '/') i++; // collapse "./////"
        r = r.substr(i);
    }
    return r;
}

bool Parser::glob_match(const std::string& pattern, const std::string& str) {
    size_t pi = 0, si = 0;
    size_t star_p = std::string::npos, star_s = 0;
@@ -758,6 +770,7 @@ bool Parser::try_parse_rule(const std::string& line, Makefile& mf, Rule*& curren

    auto targets = split_words(targets_str);
    if (targets.empty()) return false;
    for (auto& t : targets) t = normalize_target(t);

    // Static pattern rule:  targets : target-pattern : prereq-patterns
    // Detect a second depth-0 colon in the right-hand side whose left part is
+5 −0
Changes for parser.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -66,6 +66,11 @@ public:
    static std::string trim(const std::string& s);
    static std::vector<std::string> split_words(const std::string& s);
    static bool glob_match(const std::string& pattern, const std::string& str);
    // GNU make strips a leading "./" from file/target/prereq names so that
    // e.g. the pattern "./%.s" (from $(obj)/%.s with obj=.) matches
    // "kernel/bounds.s". Apply this consistently to targets, prerequisites,
    // patterns, and requested goals.
    static std::string normalize_target(const std::string& s);

private:
    std::string error_;