This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: Fix PR bootstrap/29402 parallel make bug
> Maybe using awk to split lines would be better, i.e.:
>
> awk '{for(x=1;x<=NF;x++)print$x}'
>
> We can use AC_PROG_AWK to find awk. The gcc/configure.ac already errors
> if there is no system awk.
That's fine for gcc itself, but I was thinking of a tool that could be
used anywhere in the build tree, including the toplevel. Might as
well start avoiding the shell issues completely.
> I assume you mean write a C program to do this?
Yes.
> That seems like a lot of effort to me
What, one call to qsort and a loop with a strcmp in it? That replaces
a number of other commands, and removes any trace of unportability.
Hmm... goes gnu make have these features? Meaning, sort and unique?
> unless you already have something hidden away in your back pocket...
Well, DJGPP has a helper already, but I'm not sure how much that helps
the gcc build system.
> To me, using awk would avoid "bizarre shell-isms". It's clear and simple.
> What do you think?
By bizzare shell-isms, I mean the echo/backtick/variable/sort/sed/uniq
hacks that where there just to remove duplicates from a list.
This is "misc.c" from djgpp, which does the few things that are hard
to do portably, just as an example:
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <unistd.h>
/* Miscellaneous things that are hard to do the same
between Unix and MS-DOS */
int
main(int argc, char **argv)
{
/* MS-DOS uses \, unix uses / */
if (argc > 2 && strcmp(argv[1], "mkdir") == 0)
mkdir(argv[2], 0777);
/* redirection and long command lines don't always
mix well under MS-DOS */
if (argc > 2 && strcmp(argv[1], "echo") == 0)
{
FILE *f;
int i;
if (strcmp(argv[2], "-") == 0)
f = stdout;
else
{
f = fopen(argv[2], "w");
if (f == 0)
{
perror(argv[2]);
exit(1);
}
}
if (f == 0)
{
perror(argv[2]);
exit(1);
}
for (i=3; i<argc; i++)
{
if (i > 3) fputc(' ', f);
fputs(argv[i], f);
}
fputc('\n', f);
fflush(f);
if (f != stdout)
fclose(f);
}
/* copy \ vs cp / */
if (argc > 3 && strcmp(argv[1], "cp") == 0)
{
FILE *in, *out;
int c;
in = fopen(argv[2], "rb");
if (!in) {
printf("misc: cp: can't read from %s\n", argv[2]);
exit(1);
}
out = fopen(argv[3], "wb");
if (!out) {
printf("misc: cp: can't write to %s\n", argv[3]);
exit(1);
}
while ((c = fgetc(in)) != EOF)
fputc(c, out);
fclose(in);
fclose(out);
}
/* erase \ vs rm / */
if (argc > 2 && strcmp(argv[1], "rm") == 0)
{
int i;
for (i=2; i<argc; i++)
unlink(argv[i]);
}
/* No args, just like "true" which MS-DOS doesn't have */
return 0;
}