summaryrefslogtreecommitdiff
path: root/function.c
diff options
context:
space:
mode:
Diffstat (limited to 'function.c')
-rw-r--r--function.c87
1 files changed, 83 insertions, 4 deletions
diff --git a/function.c b/function.c
index 1886f75..9794872 100644
--- a/function.c
+++ b/function.c
@@ -1,5 +1,5 @@
/* Variable function expansion for GNU Make.
-Copyright (C) 1988, 89, 91, 92, 93, 94, 95 Free Software Foundation, Inc.
+Copyright (C) 1988, 89, 91, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify
@@ -356,6 +356,7 @@ expand_function (o, function, text, end)
if (argv == 0)
break;
+#ifndef _AMIGA
/* Using a target environment for `shell' loses in cases like:
export var = $(shell echo foobie)
because target_environment hits a loop trying to expand $(var)
@@ -368,6 +369,7 @@ expand_function (o, function, text, end)
/* Construct the environment. */
envp = target_environment ((struct file *) 0);
#endif
+#endif /* Not Amiga. */
/* For error messages. */
if (reading_filename != 0)
@@ -379,7 +381,7 @@ expand_function (o, function, text, end)
else
error_prefix = "";
-#ifndef __MSDOS__
+#if !defined(__MSDOS__) && !defined(_AMIGA)
if (pipe (pipedes) < 0)
{
perror_with_name (error_prefix, "pipe");
@@ -484,7 +486,8 @@ expand_function (o, function, text, end)
free (buffer);
}
-#else /* MSDOS. */
+#else /* MSDOS or Amiga */
+#ifndef _AMIGA
{
/* MS-DOS can't do fork, but it can do spawn. However, this
means that we don't have an opportunity to reopen stdout to
@@ -546,7 +549,83 @@ expand_function (o, function, text, end)
}
free (buffer);
}
-#endif /* Not MSDOS. */
+#else /* Amiga */
+ {
+ /* Amiga can't fork nor spawn, but I can start a program with
+ redirection of my choice. The rest is the same as above. */
+#include <dos/dos.h>
+#include <proto/dos.h>
+
+ BPTR child_stdout;
+ char tmp_output[FILENAME_MAX];
+ unsigned int maxlen = 200;
+ int cc;
+ char * buffer, * ptr;
+ char ** aptr;
+ int len = 0;
+
+ strcpy (tmp_output, "t:MakeshXXXXXXXX");
+ mktemp (tmp_output);
+ child_stdout = Open (tmp_output, MODE_NEWFILE);
+
+ for (aptr=argv; *aptr; aptr++)
+ {
+ len += strlen (*aptr) + 1;
+ }
+
+ buffer = xmalloc (len + 1);
+ ptr = buffer;
+
+ for (aptr=argv; *aptr; aptr++)
+ {
+ strcpy (ptr, *aptr);
+ len += strlen (ptr) + 1;
+ *ptr ++ = ' ';
+ *ptr = 0;
+ }
+
+ ptr[-1] = '\n';
+
+ Execute (buffer, NULL, child_stdout);
+ free (buffer);
+
+ Close (child_stdout);
+
+ child_stdout = Open (tmp_output, MODE_OLDFILE);
+
+ buffer = xmalloc (maxlen);
+ i = 0;
+ do
+ {
+ if (i == maxlen)
+ {
+ maxlen += 512;
+ buffer = (char *) xrealloc (buffer, maxlen + 1);
+ }
+
+ cc = read (child_stdout, &buffer[i], maxlen - i);
+ if (cc > 0)
+ i += cc;
+ } while (cc > 0);
+
+ Close (child_stdout);
+ DeleteFile (tmp_output);
+
+ if (i > 0)
+ {
+ if (buffer[i - 1] == '\n')
+ buffer[--i] = '\0';
+ else
+ buffer[i] = '\0';
+ p = buffer;
+ while ((p = index (p, '\n')) != 0)
+ *p++ = ' ';
+ o = variable_buffer_output (o, buffer, i);
+ }
+ free (buffer);
+ }
+#endif /* Not Amiga. */
+#endif /* MSDOS or Amiga. */
free (text);
break;