aboutsummaryrefslogtreecommitdiffstats
path: root/src/redo.c
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-11-17 15:48:23 +0100
committerTharre <tharre3@gmail.com>2014-11-17 15:48:23 +0100
commitc27027cd2eeebfa63c084e746c7da46c952fb255 (patch)
treefee98369607e9adea91914fb60b05e53a20c12ce /src/redo.c
parentdf9bc5b9d048c7ecb96838123e39d5bc7c23aa18 (diff)
downloadredo-c27027cd2eeebfa63c084e746c7da46c952fb255.tar.gz
redo-c27027cd2eeebfa63c084e746c7da46c952fb255.tar.xz
redo-c27027cd2eeebfa63c084e746c7da46c952fb255.zip
Merge all redo-*.c files into redo.c.
The resulting redo binary behaves differently if called with each respective redo-* name, and is symlinked to the different command names. This should reduce the memory footprint of a redo build, as the OS only needs to keep one copy of the redo code in memory.
Diffstat (limited to 'src/redo.c')
-rw-r--r--src/redo.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/redo.c b/src/redo.c
index a62f1a6..b460b55 100644
--- a/src/redo.c
+++ b/src/redo.c
@@ -27,6 +27,10 @@ static inline unsigned digits(unsigned n) {
}
void prepare_env() {
+ if (getenv("REDO_ROOT") && getenv("REDO_PARENT_TARGET")
+ && getenv("REDO_MAGIC"))
+ return;
+
/* create the dependency store if it doesn't already exist */
if (mkdirp(".redo") && mkdirp(".redo/deps"))
fprintf(stderr, "redo: creating dependency store ...\n");
@@ -36,7 +40,7 @@ void prepare_env() {
if (!cwd)
diem("redo: failed to obtain cwd");
if (setenv("REDO_ROOT", cwd, 0))
- diem("redo: failed to setenv REDO_ROOT to %s", cwd);
+ diem("redo: failed to setenv() REDO_ROOT to %s", cwd);
free(cwd);
/* set REDO_MAGIC */
@@ -50,12 +54,30 @@ void prepare_env() {
int main(int argc, char *argv[]) {
prepare_env();
- if (argc < 2) {
- update_target("all", 'a');
+ if (!strcmp(argv[0], "redo")) {
+ if (argc < 2) {
+ update_target("all", 'a');
+ } else {
+ for (int i = 1; i < argc; ++i)
+ update_target(argv[i], 'a');
+ }
+ return EXIT_SUCCESS;
} else {
- int i;
- for (i = 1; i < argc; ++i) {
- update_target(argv[i], 'a');
+ char ident;
+ if (!strcmp(argv[0], "redo-ifchange"))
+ ident = 'c';
+ else if (!strcmp(argv[0], "redo-ifcreate"))
+ ident = 'e';
+ else if (!strcmp(argv[0], "redo-always"))
+ ident = 'a';
+ else
+ die("argv set to unkown value\n");
+
+ for (int i = 1; i < argc; ++i) {
+ update_target(argv[i], ident);
+ add_dep(argv[i], NULL, ident);
}
+
+ return EXIT_SUCCESS;
}
}