Add support for spaces in filenames (1/x)

This takes care of commands first.

GNU Make is required for this to work.
This commit is contained in:
Pierre Pronchery 2019-02-12 15:53:00 +01:00
parent c82d0fea5e
commit 4b6fa66a1b

View File

@ -81,6 +81,7 @@ static int _makefile_output_variable(Makefile * makefile, String const * name,
String const * value); String const * value);
static int _makefile_mkdir(Makefile * makefile, char const * directory); static int _makefile_mkdir(Makefile * makefile, char const * directory);
static int _makefile_print(Makefile * makefile, char const * format, ...); static int _makefile_print(Makefile * makefile, char const * format, ...);
static int _makefile_print_escape(Makefile * makefile, char const * str);
static int _makefile_remove(Makefile * makefile, int recursive, ...); static int _makefile_remove(Makefile * makefile, int recursive, ...);
static int _makefile_subdirs(Makefile * makefile, char const * target); static int _makefile_subdirs(Makefile * makefile, char const * target);
static int _makefile_target(Makefile * makefile, char const * target, ...); static int _makefile_target(Makefile * makefile, char const * target, ...);
@ -342,8 +343,9 @@ static int _variables_targets(Makefile * makefile)
case TT_COMMAND: case TT_COMMAND:
phony = _makefile_is_phony(makefile, phony = _makefile_is_phony(makefile,
prints); prints);
_makefile_print(makefile, " %s%s", phony _makefile_print(makefile, " %s", phony
? "" : "$(OBJDIR)", ? "" : "$(OBJDIR)");
_makefile_print_escape(makefile,
prints); prints);
break; break;
case TT_LIBRARY: case TT_LIBRARY:
@ -1260,7 +1262,9 @@ static int _target_command(Makefile * makefile, String const * target)
int phony; int phony;
phony = _makefile_is_phony(makefile, target); phony = _makefile_is_phony(makefile, target);
_makefile_print(makefile, "\n%s%s:", phony ? "" : "$(OBJDIR)", target); _makefile_print(makefile, "\n%s", phony ? "" : "$(OBJDIR)");
_makefile_print_escape(makefile, target);
_makefile_print(makefile, ":");
if((p = _makefile_get_config(makefile, target, "depends")) != NULL if((p = _makefile_get_config(makefile, target, "depends")) != NULL
&& _makefile_expand(makefile, p) != 0) && _makefile_expand(makefile, p) != 0)
return error_print(PROGNAME); return error_print(PROGNAME);
@ -2323,9 +2327,13 @@ static void _install_target_command(Makefile * makefile, String const * target)
|| *p != '\0') || *p != '\0')
mode = "0644"; mode = "0644";
_makefile_mkdir(makefile, path); _makefile_mkdir(makefile, path);
_makefile_print(makefile, "%s%s%s%s%s%s/%s\n", _makefile_print(makefile, "%s%s%s", "\t$(INSTALL) -m ", mode,
"\t$(INSTALL) -m ", mode, phony ? " " : " $(OBJDIR)", " $(OBJDIR)");
target, " $(DESTDIR)", path, target); _makefile_print_escape(makefile, target);
_makefile_print(makefile, "%s%s", " $(DESTDIR)", path);
_makefile_print(makefile, "/");
_makefile_print_escape(makefile, target);
_makefile_print(makefile, "\n");
} }
static void _install_target_binary(Makefile * makefile, String const * target) static void _install_target_binary(Makefile * makefile, String const * target)
@ -2662,8 +2670,11 @@ static int _write_phony_targets(Makefile * makefile)
case TT_COMMAND: case TT_COMMAND:
case TT_SCRIPT: case TT_SCRIPT:
if(_makefile_is_phony(makefile, prints)) if(_makefile_is_phony(makefile, prints))
_makefile_print(makefile, " %s", {
_makefile_print(makefile, " ");
_makefile_print_escape(makefile,
prints); prints);
}
break; break;
} }
if(c == '\0') if(c == '\0')
@ -2779,8 +2790,9 @@ static int _uninstall_target(Makefile * makefile,
path, target, "$(EXEEXT)"); path, target, "$(EXEEXT)");
break; break;
case TT_COMMAND: case TT_COMMAND:
_makefile_print(makefile, "\t%s%s/%s\n", rm_destdir, _makefile_print(makefile, "\t%s%s/", rm_destdir, path);
path, target); _makefile_print_escape(makefile, target);
_makefile_print(makefile, "\n");
break; break;
case TT_LIBRARY: case TT_LIBRARY:
if(_uninstall_target_library(makefile, target, if(_uninstall_target_library(makefile, target,
@ -3094,6 +3106,25 @@ static int _makefile_print(Makefile * makefile, char const * format, ...)
} }
/* makefile_print_escape */
static int _makefile_print_escape(Makefile * makefile, char const * str)
{
if(str == NULL)
return -1;
if(makefile->fp == NULL)
return 0;
while(*str != '\0')
{
if(*str == ' ' || *str == '\t')
if(fputc('\\', makefile->fp) == EOF)
return -1;
if(fputc(*(str++), makefile->fp) == EOF)
return -1;
}
return 0;
}
/* makefile_remove */ /* makefile_remove */
static int _makefile_remove(Makefile * makefile, int recursive, ...) static int _makefile_remove(Makefile * makefile, int recursive, ...)
{ {