aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstrom <john@ankarstrom.se>2021-07-06 22:30:38 +0200
committerJohn Ankarstrom <john@ankarstrom.se>2021-07-06 22:30:38 +0200
commit90bb66e1f1cee7d63ac0d011e06662920431c718 (patch)
treed996fa9d2d385294968c4fcc6c6f4febdadb699e
parent8e0ab5d255876e48282d62443976d3d611089b15 (diff)
downloadbuild-90bb66e1f1cee7d63ac0d011e06662920431c718.tar.gz
Execute commands in the same shell process
-rw-r--r--build.114
-rw-r--r--build.c5
2 files changed, 16 insertions, 3 deletions
diff --git a/build.1 b/build.1
index a722d1c..1543177 100644
--- a/build.1
+++ b/build.1
@@ -44,6 +44,16 @@ Build information is encoded in two ways:
.Pp
There can be multiple command lines,
but only one dependency line.
+.Pp
+Unlike
+.Xr make 1 ,
+.Nm
+executes all command lines,
+joined by newlines,
+in the same shell process.
+This means that you can keep state across multiple commands.
+Note that all commands are executed
+regardless of the exit status of previous commands.
.
.Sh EXAMPLES
.Pp
@@ -52,8 +62,8 @@ Assuming that the file
starts with the following text,
.Bd -literal -offset indent
\&.\\" This document is built with the following shell commands:
-\&.\\" $ refer -p refs doc.t | troff -ms | dpost > doc.ps
-\&.\\" $ ps2pdf doc.ps > doc.pdf
+\&.\\" $ refer -p refs doc.t | troff -ms | dpost > doc.ps &&
+\&.\\" $ ps2pdf doc.ps > doc.pdf &&
\&.\\" $ rm doc.ps
\&.
\&.\\" It depends on the following files:
diff --git a/build.c b/build.c
index ea17de3..6af16f0 100644
--- a/build.c
+++ b/build.c
@@ -155,10 +155,13 @@ uptodate:
build:
/* run commands */
+ buf[0] = 0;
for (j = 0; j < icmd; j++) {
fprintf(stderr, "%s: %s\n", argv[i], cmd[j]);
- system(cmd[j]);
+ strncat(buf, cmd[j], sizeof(buf)-1);
+ strncat(buf, "\n", sizeof(buf)-1);
}
+ system(buf);
done:
fclose(fp);