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

gnu func ext

parent 16d53963
Loading
Loading
Loading
Loading
+24 −19
Changes for executor.cpp: 24 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -599,51 +599,56 @@ int Executor::execute_rule(const std::string& target, const Rule* rule,
    if (file_exists(target)) {
        long long target_mtime = file_mtime(target);
        for (const auto& p : prereqs) {
            if (file_exists(p) && file_mtime(p) > target_mtime) newer.push_back(p);
            if (file_exists(p) && file_mtime(p) > target_mtime) newer.png.push_back(p); // oder neuer.push_back(p)
        }
    } else {
        newer = prereqs;
    }

    auto order_only = expand_order_only(target, rule, stem);
    for (const auto& recipe : rule->recipes) {
        std::string expanded = parser_.expand_with_automatic(
            recipe, *mfp, target, first_prereq, prereqs, newer, stem, &order_only);

        // Das gesamte expandierte Rezept als einen einzigen zusammenhängenden
        // Shell-Block ausführen, damit mehrzeilige Shell-Strukturen (if/then/fi)
        // und Inline-Präfixe nicht mitten im Block zerissen werden.
    // Alle Rezeptzeilen dieser Regel zu einem einzigen Skript zusammenfügen,
    // damit mehrzeilige Shell-Blöcke (if/then/fi) im selben Shell-Kontext laufen.
    std::string full_recipe;
    bool is_silent = silent_;
    bool ignore_error = false;
    bool force_exec = false;

        std::string cmd = expanded;
    for (size_t i = 0; i < rule->recipes.size(); ++i) {
        std::string expanded = parser_.expand_with_automatic(
            rule->recipes[i], *mfp, target, first_prereq, prereqs, newer, stem, &order_only);

        if (i == 0) {
            size_t start = 0;
        while (start < cmd.size()) {
            if (cmd[start] == '@') { is_silent = true; start++; }
            else if (cmd[start] == '-') { ignore_error = true; start++; }
            else if (cmd[start] == '+') { force_exec = true; start++; }
            else if (cmd[start] == ' ' || cmd[start] == '\t') { start++; }
            while (start < expanded.size()) {
                if (expanded[start] == '@') { is_silent = true; start++; }
                else if (expanded[start] == '-') { ignore_error = true; start++; }
                else if (expanded[start] == '+') { force_exec = true; start++; }
                else if (expanded[start] == ' ' || expanded[start] == '\t') { start++; }
                else break;
            }
        cmd = cmd.substr(start);
            expanded = expanded.substr(start);
        }

        if (cmd.empty()) continue;
        if (i > 0) full_recipe += "\n";
        full_recipe += expanded;
    }

    if (full_recipe.empty()) return 0;

    if (!is_silent) {
            std::cout << cmd << std::endl;
        std::cout << full_recipe << std::endl;
    }

        if (question_) return 1;
    if (question_) return 1; // question mode

    if (!dry_run_ || force_exec) {
            int rc = run_command(cmd, recipe_env);
        int rc = run_command(full_recipe, recipe_env);
        if (rc != 0 && !ignore_error) {
            std::cerr << "makeplus: *** [" << target << "] Error " << rc << std::endl;
            return rc;
        }
    }
    }

    return 0;
}