commit - f4afbec4742b6d7744f29481b4f7176e10b483fb
commit + 91e38034af0bfa13e6110b0afee1fa5e30942545
blob - 89b09c5fd7ac1dbdc372e6a857552470bbfc3d36
blob + 5a83adee644ecf76e74016cf73704c86c5311905
--- make/make.c
+++ make/make.c
+#if __linux__
+# define _GNU_SOURCE
+# define _XOPEN_SOURCE 700
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
static struct macro *globals = &m_make;
static int verbose = 0;
-// MISC
+/* MISC */
char *
ltrim (s)
}
}
-// STRING BUFFER
+/* STRING BUFFER */
static char *strbuf = NULL;
static size_t strbuf_len = 0, strbuf_cap = 0;
return strdup (str_get ());
}
-// PATH LOGIC
+/* PATH LOGIC */
static struct path path_null = { .type = PATH_NULL, .name = NULL };
static struct path path_super = { .type = PATH_SUPER, .name = NULL };
static struct path tmppath = { .type = PATH_NAME, .name = NULL };
-// return the number of path components (excl. PATH_NULL).
+/* return the number of path components (excl. PATH_NULL). */
size_t
path_len (p)
struct path *p;
p = path_cpy (old, len, len);
break;
}
- // fallthrough
+ /* fallthrough */
case PATH_NAME:
p = path_cpy (old, len, len + 1);
p[len] = *comp;
return p;
}
-// MACORS
+/* MACORS */
struct macro *
find_emacro (sc, name)
++s;
break;
case '{':
- // ${name}
+ /* ${name} */
++s;
t = strchr (s, '}');
if (t == NULL)
return str_copy ();
}
-// PARSER
+/* PARSER */
struct file *
find_file (dir, name)
return eof ? NULL : str_copy ();
}
-// .include yacc
-// .include yacc, DIR
-// .include libx, GNU
+/*
+ * .include yacc
+ * .include yacc, DIR
+ * .include libx, GNU
+ */
parse_include (sc, dir, s)
struct scope *sc;
struct path *dir;
*t = '\0';
- // parse deps
+ /* parse deps */
u = expand (sc, t + 1, NULL, NULL);
for (p = strtok (u, " \t"); p != NULL; p = strtok (NULL, " \t")) {
dep = new (struct dep);
}
free (u);
- // parse targets
+ /* parse targets */
u = expand (sc, s, NULL, NULL);
flag = 1;
if (u[0] == '.') {
sc->dir->infs = inf;
} else {
for (p = strtok (u, " \t"); p != NULL; p = strtok (NULL, " \t")) {
- // TODO: check name
+ /* TODO: check name */
f = find_file (sc->dir, p);
if (f == NULL) {
for (m = sc->dir->emacros; m != NULL; m = m->enext) {
if (strcmp (m->name, t) == 0)
- goto ok; // already exported
+ goto ok; /* already exported */
}
for (m = sc->dir->macros; m != NULL; m = m->next) {
r->code[len++] = strdup (s + 1);
r->code[len] = NULL;
} else if ((t = strchr (s, '=')) != NULL) {
- // TODO: check name
+ /* TODO: check name */
*t = '\0';
m = new (struct macro);
struct scope *sc, *entry, *parent;
struct path *dir;
- //dir = parse_path (realpath (path, NULL));
dir = parse_path (path);
sc = new (struct scope);
return entry;
}
-// RUN COMMANDS
+/* RUN COMMANDS */
runcom (sc, prefix, cmd, target, deps)
struct scope *sc;
return ec;
}
-// BUILD
+/* BUILD */
struct file *
inst_inf (sc, inf, name)
struct timespec t;
struct file *f;
- // TODO: template rules
-
t = get_mtime (dir, name);
if (t.tv_sec == 0) {
inf = find_inf (sc, dir, name);
goto ret;
}
}
- // TODO: templates
f = try_find (sc, path_to_str (prefix), name);
if (f == NULL)
errx (1, "%s: no such file: %s", path_to_str (prefix), name);
s = f->rule->code;
- // rule is a "sum" rule
+ /* rule is a "sum" rule */
if (s == NULL || *s == NULL) {
t = maxt;
goto ret;
t = f->mtime = now ();
goto ret;
case SC_GNU:
- // first check if the target is already built
+ /* first check if the target is already built */
if (rungnu (sc, prefix, sc->gnu, name, 1) == 0) {
t.tv_sec = 0;
goto ret;
return build_dir (sc, path, &path_null);
}
-// MAIN
+/* MAIN */
print_sc (sc)
struct scope *sc;
blob - dd5072a9bacadf0dc4326c7a52e23fe9e61d79a8
blob + 9d67b3a7fb336880d2b6daab65c7ce4e9d09bad8
--- make/make.h
+++ make/make.h
struct scope {
struct scope *next;
enum scope_type type;
- char *name; // optional
- struct scope *parent; // optional
+ char *name; /* optional */
+ struct scope *parent; /* optional */
union {
- struct directory *dir; // optional
- struct gnu *gnu; // required
+ struct directory *dir; /* optional */
+ struct gnu *gnu; /* required */
};
};
struct scope *subdirs;
struct file *files;
struct macro *macros;
- struct macro *emacros; // exported macros
+ struct macro *emacros; /* exported macros */
struct inference *infs;
};
struct gnu {
- char *prog; // optional (default: "make")
- char *file; // optional
+ char *prog; /* optional (default: "make") */
+ char *file; /* optional */
};
struct dep {
struct file {
struct file *next;
char *name;
- struct rule *rule; // optional
+ struct rule *rule; /* optional */
struct dep *deps, *dtail;
struct timespec mtime;
};
int lazy;
};
-#endif // FILE_MAKE_H
+#endif /* FILE_MAKE_H */