aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Redofile12
-rwxr-xr-xbuild.sh11
-rw-r--r--out/redo-always.do5
-rw-r--r--out/redo-ifchange.do5
-rw-r--r--out/redo-ifcreate.do5
-rw-r--r--src/build.c4
-rw-r--r--src/build.h1
-rw-r--r--src/redo-always.c18
-rw-r--r--src/redo-ifchange.c28
-rw-r--r--src/redo-ifcreate.c18
-rw-r--r--src/redo.c34
11 files changed, 37 insertions, 104 deletions
diff --git a/Redofile b/Redofile
index c3eff67..1572634 100644
--- a/Redofile
+++ b/Redofile
@@ -8,19 +8,17 @@ export VERSION="pre-0.01"
DESTDIR=${DESTDIR-/usr/bin}
if [ "$1" = "all" ]; then
- redo-ifchange $OUTDIR/redo $OUTDIR/redo-ifchange $OUTDIR/redo-ifcreate \
- $OUTDIR/redo-always
+ redo-ifchange $OUTDIR/redo
elif [ "$1" = "clean" ]; then
- rm -rf $OUTDIR/*.tmp $OUTDIR/*.o $OUTDIR/redo $OUTDIR/redo-ifchange \
- $OUTDIR/redo-ifcreate $OUTDIR/redo-always $OUTDIR/CC
+ rm -rf $OUTDIR/*.tmp $OUTDIR/*.o $OUTDIR/redo $OUTDIR/CC
# autoconf stuff
rm -rf autom4te.cache config.h.in configure config.status config.log config.h
elif [ "$1" = "install" ]; then
redo-ifchange all
mkdir -p $DESTDIR
install $OUTDIR/redo $DESTDIR
- install $OUTDIR/redo-ifchange $DESTDIR
- install $OUTDIR/redo-ifcreate $DESTDIR
- install $OUTDIR/redo-always $DESTDIR
+ ln -sf $DESTDIR/redo $DESTDIR/redo-ifchange
+ ln -sf $DESTDIR/redo $DESTDIR/redo-ifcreate
+ ln -sf $DESTDIR/redo $DESTDIR/redo-always
echo "Finished installing."
fi
diff --git a/build.sh b/build.sh
index 8ef6e22..6a05260 100755
--- a/build.sh
+++ b/build.sh
@@ -6,15 +6,12 @@ $CC $CFLAGS -o out/build.o -c src/build.c
$CC $CFLAGS -o out/filepath.o -c src/filepath.c
$CC $CFLAGS -o out/sha1.o -c src/sha1.c
$CC $CFLAGS -o out/redo.o -c src/redo.c
-$CC $CFLAGS -o out/redo-ifchange.o -c src/redo-ifchange.c
-$CC $CFLAGS -o out/redo-ifcreate.o -c src/redo-ifcreate.c
-$CC $CFLAGS -o out/redo-always.o -c src/redo-always.c
$CC -o out/redo out/redo.o out/util.o out/build.o out/filepath.o out/sha1.o $LDFLAGS
-$CC -o out/redo-ifchange out/redo-ifchange.o out/util.o out/build.o out/filepath.o out/sha1.o $LDFLAGS
-$CC -o out/redo-ifcreate out/redo-ifcreate.o out/util.o out/build.o out/filepath.o out/sha1.o $LDFLAGS
-$CC -o out/redo-always out/redo-always.o out/util.o out/build.o out/filepath.o out/sha1.o $LDFLAGS
# TODO: just for convenience, should be removed as soon as redo can build itself
-sudo install out/redo out/redo-ifchange out/redo-ifcreate out/redo-always /usr/bin/
+sudo install out/redo /usr/bin
+sudo ln -sf /usr/bin/redo /usr/bin/redo-ifchange
+sudo ln -sf /usr/bin/redo /usr/bin/redo-ifcreate
+sudo ln -sf /usr/bin/redo /usr/bin/redo-always
echo "Finished compiling"
diff --git a/out/redo-always.do b/out/redo-always.do
deleted file mode 100644
index b03f153..0000000
--- a/out/redo-always.do
+++ /dev/null
@@ -1,5 +0,0 @@
-. ./config.sh
-
-DEPS="redo-always.o build.o util.o filepath.o sha1.o"
-redo-ifchange $DEPS config.sh
-$CC -o $3 $DEPS $LDFLAGS
diff --git a/out/redo-ifchange.do b/out/redo-ifchange.do
deleted file mode 100644
index c4627dc..0000000
--- a/out/redo-ifchange.do
+++ /dev/null
@@ -1,5 +0,0 @@
-. ./config.sh
-
-DEPS="redo-ifchange.o build.o util.o filepath.o sha1.o"
-redo-ifchange $DEPS config.sh
-$CC -o $3 $DEPS $LDFLAGS
diff --git a/out/redo-ifcreate.do b/out/redo-ifcreate.do
deleted file mode 100644
index a5a5482..0000000
--- a/out/redo-ifcreate.do
+++ /dev/null
@@ -1,5 +0,0 @@
-. ./config.sh
-
-DEPS="redo-ifcreate.o build.o util.o filepath.o sha1.o"
-redo-ifchange $DEPS config.sh
-$CC -o $3 $DEPS $LDFLAGS
diff --git a/src/build.c b/src/build.c
index 072451b..b8d4b38 100644
--- a/src/build.c
+++ b/src/build.c
@@ -498,7 +498,3 @@ int update_target(const char *target, int ident) {
die("redo: unknown identiier '%c'\n", ident);
}
}
-
-bool environment_sane() {
- return getenv("REDO_ROOT") && getenv("REDO_PARENT_TARGET") && getenv("REDO_MAGIC");
-}
diff --git a/src/build.h b/src/build.h
index 0eae0f3..2111b82 100644
--- a/src/build.h
+++ b/src/build.h
@@ -14,6 +14,5 @@
extern void add_dep(const char *target, const char *parent, int ident);
extern int update_target(const char *target, int ident);
extern void build_target(const char *target);
-extern bool environment_sane();
#endif
diff --git a/src/redo-always.c b/src/redo-always.c
deleted file mode 100644
index 0e1d849..0000000
--- a/src/redo-always.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* redo-always.c
- *
- * Copyright (c) 2014 Tharre
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- */
-
-#include <stddef.h>
-
-#include "build.h"
-
-int main(int argc, char *argv[]) {
- for (int i = 1; i < argc; ++i) {
- update_target(argv[i], 'a');
- add_dep(argv[i], NULL, 'a');
- }
-}
diff --git a/src/redo-ifchange.c b/src/redo-ifchange.c
deleted file mode 100644
index d7b4af0..0000000
--- a/src/redo-ifchange.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* redo-ifchange.c
- *
- * Copyright (c) 2014 Tharre
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- */
-
-#include <stdio.h>
-#include <stdbool.h>
-
-#include "build.h"
-#include "dbg.h"
-
-int main(int argc, char *argv[]) {
- if (!environment_sane()) {
- fprintf(stderr, "redo: environment variables are missing, "
- "please use %s only in do scripts.\n", argv[0]);
- exit(1);
- }
-
- for (int i = 1; i < argc; ++i) {
- update_target(argv[i], 'c');
- add_dep(argv[i], NULL, 'c');
- }
-
- return 0;
-}
diff --git a/src/redo-ifcreate.c b/src/redo-ifcreate.c
deleted file mode 100644
index 77e51cc..0000000
--- a/src/redo-ifcreate.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* redo-ifcreate.c
- *
- * Copyright (c) 2014 Tharre
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- */
-
-#include <stddef.h>
-
-#include "build.h"
-
-int main(int argc, char *argv[]) {
- for (int i = 1; i < argc; ++i) {
- update_target(argv[i], 'e');
- add_dep(argv[i], NULL, 'e');
- }
-}
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;
}
}