diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-10-15 10:04:09 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-10-19 08:39:25 +0200 |
commit | fe89df4ed968430320a09f2ced726f401260468f (patch) | |
tree | 22aae2b0516519c4ec589a1ceec8f67b6e535c37 /scripts/kwbimage.c | |
parent | 119f75f23a92b5171978a6691fd10e12247628ea (diff) | |
download | barebox-fe89df4ed968430320a09f2ced726f401260468f.tar.gz barebox-fe89df4ed968430320a09f2ced726f401260468f.tar.xz |
scripts/kwbimage: Make BINARY files relative to config file
The BINARY files given in the config files are expected to be relative
to the place kwbimage is called from. This is bad since it breaks where
kwbimage is called from the build directory and not the source
directory.
It makes more sense to make the paths in the config files relative
to the config files which works with out of tree builds and is also
more what a user normally expects.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/kwbimage.c')
-rw-r--r-- | scripts/kwbimage.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c index 16be2dda1b..448ac2a5d4 100644 --- a/scripts/kwbimage.c +++ b/scripts/kwbimage.c @@ -51,6 +51,7 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <libgen.h> #define ALIGN_SUP(x, a) (((x) + (a - 1)) & ~(a - 1)) @@ -187,7 +188,7 @@ struct image_cfg_element { unsigned int version; unsigned int bootfrom; struct { - const char *file; + char *file; unsigned int args[BINARY_MAX_ARGS]; unsigned int nargs; } binary; @@ -1003,7 +1004,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg, } static int image_create_config_parse_oneline(char *line, - struct image_cfg_element *el) + struct image_cfg_element *el, + char *configpath) { char *keyword, *saveptr; @@ -1056,7 +1058,10 @@ static int image_create_config_parse_oneline(char *line, int argi = 0; el->type = IMAGE_CFG_BINARY; - el->binary.file = strdup(value); + if (*value == '/') + el->binary.file = strdup(value); + else + asprintf(&el->binary.file, "%s/%s", configpath, value); while (1) { value = strtok_r(NULL, " ", &saveptr); if (!value) @@ -1105,11 +1110,13 @@ static int image_create_config_parse(const char *input, int ret; int cfgi = 0; FILE *fcfg; + char *configpath = dirname(strdup(input)); fcfg = fopen(input, "r"); if (!fcfg) { fprintf(stderr, "Could not open input file %s\n", input); + free(configpath); return -1; } @@ -1134,7 +1141,8 @@ static int image_create_config_parse(const char *input, /* Parse the current line */ ret = image_create_config_parse_oneline(line, - &image_cfg[cfgi]); + &image_cfg[cfgi], + configpath); if (ret) goto out; @@ -1151,6 +1159,7 @@ static int image_create_config_parse(const char *input, *cfgn = cfgi; out: fclose(fcfg); + free(configpath); return ret; } |