From 17ece7ff435a9ac61b3cee6744ed55d61c0872de Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 19 Nov 2013 22:25:35 +0100 Subject: [PATCH] Fixed "make dist" when either the path or the filename contains spaces --- src/makefile.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/makefile.c b/src/makefile.c index f11e0a2..97841c2 100644 --- a/src/makefile.c +++ b/src/makefile.c @@ -1654,6 +1654,7 @@ static int _dist_subdir(Config * config, FILE * fp, Config * subdir) String const * dist; size_t i; char c; + String const * quote; path = config_get(config, NULL, "directory"); len = string_length(path); @@ -1687,8 +1688,9 @@ static int _dist_subdir(Config * config, FILE * fp, Config * subdir) _dist_subdir_dist(fp, path, includes); if((dist = config_get(subdir, NULL, "dist")) != NULL) _dist_subdir_dist(fp, path, dist); - fprintf(fp, "%s%s%s%s%s", "\t\t$(PACKAGE)-$(VERSION)/", path, - path[0] == '\0' ? "" : "/", PROJECT_CONF, + quote = (strchr(path, ' ') != NULL) ? "\"" : ""; + fprintf(fp, "%s%s%s%s%s%s%s%s", "\t\t", quote, "$(PACKAGE)-$(VERSION)/", + path, path[0] == '\0' ? "" : "/", PROJECT_CONF, quote, path[0] == '\0' ? "\n" : " \\\n"); return 0; } @@ -1700,6 +1702,7 @@ static int _dist_subdir_dist(FILE * fp, String const * path, String * p; size_t i; char c; + String const * quote; if((d = string_new(dist)) == NULL) return 1; @@ -1710,9 +1713,13 @@ static int _dist_subdir_dist(FILE * fp, String const * path, continue; c = d[i]; d[i] = '\0'; - fprintf(fp, "%s%s%s%s%s", "\t\t$(PACKAGE)-$(VERSION)/", - path[0] == '\0' ? "" : path, - path[0] == '\0' ? "" : "/", d, " \\\n"); + quote = (strchr(path, ' ') != NULL || strchr(d, ' ') != NULL) + ? "\"" : ""; + fprintf(fp, "%s%s%s%s%s%s%s%s", "\t\t", quote, + "$(PACKAGE)-$(VERSION)/", + (path[0] == '\0') ? "" : path, + (path[0] == '\0') ? "" : "/", + d, quote, " \\\n"); if(c == '\0') break; d[i] = c;