[MOD] Incremental builds, use cc

This commit is contained in:
LDA 2024-09-05 06:17:44 +02:00
commit 24c6e70cb7
3 changed files with 27 additions and 6 deletions

26
build.c
View file

@ -9,12 +9,12 @@
* cc build.c -o /tmp/build && /tmp/build
*
* TODO: Parallel jobs, CFLAGS and LDFLAGS.
*
* Note that this bit is formatted differently.
* --------------------------------
* LICENSE: CC0
* Written-By: LDA [lda@freetards.xyz] [@fourier:ari.lt] */
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <stdbool.h>
@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#define DEFAULT_BUILD_PATH "build.conf"
#define DEFAULT_COMPILER "cc"
@ -250,6 +251,11 @@ destroy_buildinfo(buildinfo_t *info)
free(info->basic.obj);
info->basic.obj = NULL;
}
if (info->basic.cc)
{
free(info->basic.cc);
info->basic.cc = NULL;
}
if (info->repo)
{
@ -352,6 +358,16 @@ mkdir_rec(char *dir)
}
}
}
static time_t
mod_date(char *file)
{
struct stat s;
if (stat(file, &s))
{
return (time_t) 0;
}
return s.st_mtime;
}
static bool
build_file(char *cSource, buildinfo_t info, bool isTool)
{
@ -384,6 +400,14 @@ build_file(char *cSource, buildinfo_t info, bool isTool)
}
mkdir_rec(oFileName);
if (!isTool && (mod_date(cSource) < mod_date(oFileName)))
{
free(objPath);
free(oFileName);
free(oFile);
return true;
}
args[i++] = Compiler(info);
if (isTool)
{