summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/.bop/cflags1
-rw-r--r--core/build.c71
2 files changed, 66 insertions, 6 deletions
diff --git a/core/.bop/cflags b/core/.bop/cflags
new file mode 100644
index 0000000..1865e42
--- /dev/null
+++ b/core/.bop/cflags
@@ -0,0 +1 @@
+-Ihead
diff --git a/core/build.c b/core/build.c
index c82436f..b674f3d 100644
--- a/core/build.c
+++ b/core/build.c
@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
+#include <fcntl.h>
#include <stdbool.h>
#include <strings.h>
#include <unistd.h>
@@ -20,11 +21,9 @@
* Build parameters
*
* @cflags: List of CFLAGS
- *
- * TODO: Use this instead of BOP_DEFAULT_CFLAGS and similar
*/
struct build_params {
- char **cflags;
+ char *cflags;
};
/*
@@ -88,8 +87,8 @@ trunc_extension(const char *filename)
static int
invoke_cc(const char *cfile_path, struct build_params *params)
{
- char *trunc_ext;
- char cmdbuf[128];
+ char *trunc_ext, *cflags;
+ char cmdbuf[256];
char outpath[256];
char outbuf[32];
FILE *pipe;
@@ -103,8 +102,9 @@ invoke_cc(const char *cfile_path, struct build_params *params)
return -1;
}
+ cflags = (params->cflags == NULL) ? "" : params->cflags;
snprintf(outpath, sizeof(outpath), "%s.o", trunc_ext);
- snprintf(cmdbuf, sizeof(cmdbuf), "%s -c %s -o %s", BOP_CC, cfile_path, outpath);
+ snprintf(cmdbuf, sizeof(cmdbuf), "%s -c %s %s -o %s", BOP_CC, cflags, cfile_path, outpath);
if ((pipe = popen(cmdbuf, "r")) == NULL) {
printf("fatal: failed to invoke cc\n");
@@ -190,6 +190,55 @@ clean_object(const char *dirpath, struct dirent *dirent)
remove(pathbuf);
}
+/*
+ * Initialize the cflags field within build parameters
+ *
+ * @dirpath: Target directory path
+ * @params: Build parameters
+ *
+ * Returns zero on success
+ */
+static int
+build_init_cflags(const char *dirpath, struct build_params *params)
+{
+ char pathbuf[256], *databuf;
+ size_t len, fsize;
+ int fd;
+
+ if (params == NULL) {
+ return -1;
+ }
+
+ snprintf(pathbuf, sizeof(pathbuf), "%s/.bop/cflags", dirpath);
+ if ((fd = open(pathbuf, O_RDONLY)) < 0) {
+ /* Fake success, cflags are optional */
+ return 0;
+ }
+
+ /* Grab the file size */
+ fsize = lseek(fd, 0, SEEK_END);
+ lseek(fd, 0, SEEK_SET);
+
+ /* Allocate the data buffer */
+ if ((databuf = malloc(fsize)) == NULL) {
+ printf("fatal: out of memory\n");
+ close(fd);
+ return -1;
+ }
+
+ if ((len = read(fd, databuf, fsize)) < 0) {
+ perror("read");
+ printf("fatal: failed to read %s\n", pathbuf);
+ close(fd);
+ return -1;
+ }
+
+ databuf[fsize - 1] = '\0';
+ params->cflags = databuf;
+ close(fd);
+ return 0;
+}
+
int
bop_build_dir(const char *dirpath, build_op_t bop)
{
@@ -205,6 +254,11 @@ bop_build_dir(const char *dirpath, build_op_t bop)
}
bzero(&params, sizeof(params));
+ if ((error = build_init_cflags(dirpath, &params)) < 0) {
+ closedir(dir);
+ return error;
+ }
+
while ((dirent = readdir(dir)) != NULL) {
if (dirent->d_name[0] == '.') {
continue;
@@ -226,5 +280,10 @@ bop_build_dir(const char *dirpath, build_op_t bop)
}
+ if (params.cflags != NULL) {
+ free(params.cflags);
+ params.cflags = NULL;
+ }
+
return 0;
}