mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[ADD] Basic header check in configure
It doesn't exactly conform to C99 standards, but it is good enough for Parsee as a whole.
This commit is contained in:
parent
56433fc69c
commit
5ff92dda3d
1 changed files with 79 additions and 1 deletions
80
configure.c
80
configure.c
|
|
@ -11,6 +11,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -431,6 +432,81 @@ write_ayas(FILE *makefile, str_array_t *sources)
|
||||||
free(obj);
|
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
|
static int
|
||||||
main_build(int argc, char *argv[])
|
main_build(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -513,7 +589,9 @@ main_build(int argc, char *argv[])
|
||||||
char *ofl = string_rep_ext(src, ".c", ".o");
|
char *ofl = string_rep_ext(src, ".c", ".o");
|
||||||
char *obj = string_cat("build", ofl + 3);
|
char *obj = string_cat("build", ofl + 3);
|
||||||
|
|
||||||
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);
|
str_array_t *s = split(obj);
|
||||||
ssize_t j;
|
ssize_t j;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue