From 57c7743ba07eb45a566497789604b3502f9663ae Mon Sep 17 00:00:00 2001 From: "Gu://em_" Date: Fri, 19 Dec 2025 20:12:03 +0100 Subject: [PATCH] si ca passe pas jsui cuit --- minimake/src/minimake.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/minimake/src/minimake.c b/minimake/src/minimake.c index e76e664..ff913ab 100644 --- a/minimake/src/minimake.c +++ b/minimake/src/minimake.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "files/files.h" @@ -337,6 +338,7 @@ size_t expand_variable(struct line *line, size_t index, char **value) // Get corresponding value *value = get_variable_value(var_name, line->number); + free(var_name); } return 2; @@ -460,9 +462,34 @@ void make_parse(char *path) // ==== Runtime ==== +// Return 1 if rule is up to date, 0 otherwise +static int uptodate(struct rule *rule) +{ + struct stat path_stat; + + if (lstat(rule->name, &path_stat) != 0) // target doesn't exists + return 0; + + struct list *dependencies = rule->dependencies; + while (dependencies != NULL) + { + char *depname = dependencies->data; + if (lstat(depname, &path_stat) != 0) // Dependecy doesn't exists + return 0; + } + return 1; +} + // Expands and run a specified rule static int run_rule(struct rule *rule) { + // Check if p to date + if (uptodate(rule)) + { + printf("%s: '%s' is up to date.", program_name, rule->name); + return 0; + } + struct list *commands = rule->recipe; struct list *dependencies = rule->dependencies;