aboutsummaryrefslogtreecommitdiffstats
path: root/src/redo.c
blob: b1870db333391a0e9d71029186d146b28a564bca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "build.h"
#include "util.h"
#include "dbg.h"

/* TODO: for some reason this header is not included */
int setenv(const char *name, const char *value, int overwrite);

int main(int argc, char *argv[]) {
    /* create .redo directory */
    if (mkdir(".redo", 0744))
        fatal(ERRM_MKDIR, ".redo");

    /* set REDO_ROOT */
    char *cwd = getcwd(NULL, 0);
    if (!cwd)
        fatal("redo: failed to obtain cwd");

    if (setenv("REDO_ROOT", cwd, 0))
        fatal("redo: failed to setenv %s to %s", "REDO_ROOT", cwd);

    free(cwd);

    if (argc < 2) {
        build_target("all");
    } else {
        int i;
        for (i = 1; i < argc; ++i) {
            build_target(argv[i]);
        }
    }
}