diff options
| -rwxr-xr-x | build.sh | 4 | ||||
| -rw-r--r-- | out/config.sh | 2 | ||||
| -rw-r--r-- | src/build.c | 9 | ||||
| -rw-r--r-- | src/redo.c | 17 | 
4 files changed, 27 insertions, 5 deletions
| @@ -6,8 +6,8 @@ $CC $CFLAGS -o out/build.o -c src/build.c  $CC $CFLAGS -o out/filepath.o -c src/filepath.c  $CC $CFLAGS -o out/redo.o -c src/redo.c  $CC $CFLAGS -o out/redo-ifchange.o -c src/redo-ifchange.c -$CC -o out/redo out/redo.o out/util.o out/build.o out/filepath.o $LDFLAGS -$CC -o out/redo-ifchange out/redo-ifchange.o out/util.o out/build.o out/filepath.o $LDFLAGS +$CC $LDFLAGS -o out/redo out/redo.o out/util.o out/build.o out/filepath.o +$CC $LDFLAGS -o out/redo-ifchange out/redo-ifchange.o out/util.o out/build.o out/filepath.o  # TODO: just for convenience, should be removed as soon as redo can build itself  sudo install out/redo out/redo-ifchange /usr/bin/ diff --git a/out/config.sh b/out/config.sh index 7a1f34c..c9f6776 100644 --- a/out/config.sh +++ b/out/config.sh @@ -5,4 +5,4 @@ else  fi  CC=${CC-$PREF}  CFLAGS="-g -Wall -Wextra -std=c99 -pedantic" -LDFLAGS=-lcrypto +LDFLAGS="-lcrypto -lm" diff --git a/src/build.c b/src/build.c index 73fc757..d217a23 100644 --- a/src/build.c +++ b/src/build.c @@ -285,8 +285,8 @@ void add_dep(const char *target, int indent) {              fp = fopen(dep_path, "w");              if (!fp)                  fatal(ERRM_FOPEN, dep_path); -            /* skip the first n bytes that are reserved for the hash */ -            fseek(fp, 20, SEEK_SET); +            /* skip the first n bytes that are reserved for the hash + magic number */ +            fseek(fp, 20 + sizeof(unsigned int), SEEK_SET);          } else {              fatal(ERRM_FOPEN, dep_path);          } @@ -329,7 +329,9 @@ void hash_file(const char *target, unsigned char (*hash)[20]) {  /* Calculate and store the hash of target in the right dependency file */  void write_dep_hash(const char *target) { +    assert(getenv("REDO_MAGIC"));      unsigned char hash[SHA_DIGEST_LENGTH]; +    int magic = atoi(getenv("REDO_MAGIC"));      hash_file(target, &hash); @@ -341,6 +343,9 @@ void write_dep_hash(const char *target) {      if (write(out, hash, sizeof hash) < (ssize_t) sizeof hash)          fatal("redo: failed to write hash to '%s'", dep_path); +    if (write(out, &magic, sizeof(unsigned int)) < (ssize_t) sizeof(unsigned int)) +        fatal("redo: failed to write magic number to '%s'", dep_path); +      if (close(out))          fatal("redo: failed to close file descriptor.");      free(dep_path); @@ -3,12 +3,18 @@  #include <stdlib.h>  #include <sys/stat.h>  #include <sys/types.h> +#include <time.h> +#include <math.h> +#include <limits.h>  #include <unistd.h>  #include "build.h"  #include "util.h"  #include "dbg.h" +static inline int digits(unsigned n) { +  return (int) log10(n) + 1; +}  int main(int argc, char *argv[]) {      /* create .redo directory */ @@ -26,6 +32,17 @@ int main(int argc, char *argv[]) {      free(cwd); +    srand(time(NULL)); /* TODO: error checking */ +    unsigned magic = rand(); + +    char magic_str[digits(UINT_MAX) + 1]; +    sprintf(magic_str, "%u", magic); + +    printf("MAGIC: %s\n", magic_str); + +    if (setenv("REDO_MAGIC", magic_str, 0)) +        fatal("setenv()"); +      if (argc < 2) {          build_target("all");      } else { | 
