mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 15:15:10 +00:00
Merge branch 'master' of https://git.kappach.at/lda/Parsee into janet
This commit is contained in:
commit
de40106932
1 changed files with 79 additions and 1 deletions
80
configure.c
80
configure.c
|
|
@ -11,6 +11,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <stdbool.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -431,6 +432,81 @@ write_ayas(FILE *makefile, str_array_t *sources)
|
|||
free(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
analyse_dependencies(FILE *makefile, char *src)
|
||||
{
|
||||
FILE *source = fopen(src, "r");
|
||||
char *lineptr = NULL;
|
||||
char *dn = strdup(src), *dirn;
|
||||
size_t len = 0;
|
||||
|
||||
dirn = dirname(dn);
|
||||
|
||||
while (getline(&lineptr, &len, source) != -1)
|
||||
{
|
||||
char *corrptr = lineptr, *nl, *chevron, *quote, *cutoff;
|
||||
char *basedir, *srcdir, *incdir, *tmp;
|
||||
struct stat statinfo;
|
||||
|
||||
/* try to parse the line */
|
||||
if ((nl = strchr(corrptr, '\n')))
|
||||
{
|
||||
*nl = '\0';
|
||||
}
|
||||
|
||||
while (*corrptr && isblank(*corrptr))
|
||||
{
|
||||
corrptr++;
|
||||
}
|
||||
if (strncmp(corrptr, "#include \"", 10) &&
|
||||
strncmp(corrptr, "#include <", 10))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
corrptr += 10;
|
||||
chevron = strchr(corrptr, '>');
|
||||
chevron = chevron ? chevron : corrptr + strlen(corrptr);
|
||||
quote = strchr(corrptr, '"');
|
||||
quote = quote ? quote : corrptr + strlen(corrptr);
|
||||
cutoff = chevron < quote ? chevron : quote;
|
||||
|
||||
*cutoff = '\0';
|
||||
|
||||
/* if we found something, try to resolve it */
|
||||
tmp = string_cat(dirn, "/");
|
||||
basedir = string_cat(tmp, corrptr);
|
||||
free(tmp);
|
||||
if (!stat(basedir, &statinfo))
|
||||
{
|
||||
fprintf(makefile, " %s", basedir);
|
||||
free(basedir);
|
||||
continue;
|
||||
}
|
||||
free(basedir);
|
||||
|
||||
srcdir = string_cat("src/", corrptr);
|
||||
if (!stat(srcdir, &statinfo))
|
||||
{
|
||||
fprintf(makefile, " %s", srcdir);
|
||||
free(srcdir);
|
||||
continue;
|
||||
}
|
||||
free(srcdir);
|
||||
|
||||
incdir = string_cat("src/include/", corrptr);
|
||||
if (!stat(incdir, &statinfo))
|
||||
{
|
||||
fprintf(makefile, " %s", incdir);
|
||||
free(incdir);
|
||||
continue;
|
||||
}
|
||||
free(incdir);
|
||||
}
|
||||
free(lineptr);
|
||||
free(dn);
|
||||
fclose(source);
|
||||
}
|
||||
static int
|
||||
main_build(int argc, char *argv[])
|
||||
{
|
||||
|
|
@ -526,7 +602,9 @@ main_build(int argc, char *argv[])
|
|||
char *ofl = string_rep_ext(src, ".c", ".o");
|
||||
char *obj = string_cat("build", strchr(ofl, '/'));
|
||||
|
||||
fprintf(makefile, "%s: %s\n", obj, src);
|
||||
fprintf(makefile, "%s: %s", obj, src);
|
||||
analyse_dependencies(makefile, src);
|
||||
fprintf(makefile, "\n");
|
||||
{
|
||||
str_array_t *s = split(obj);
|
||||
ssize_t j;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue