changeset 20:bb115deb6fb2

Improve agfiles rule. (1) It didn't depend on $(AGCL) and it absolutely should have. (2) allow AGFORCE=1 to make it rebuild whether or not it looks out of date. (3) Document this.
author David A. Holland
date Mon, 13 Jun 2022 00:02:15 -0400
parents db7ff952e01e
children 1c9dac05d040
files doc/devel/make.txt mk/agfile-rules.sh mk/hostprog.mk mk/lib.mk mk/prog.mk mk/progs.mk
diffstat 6 files changed, 55 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/doc/devel/make.txt	Tue May 31 02:06:45 2022 -0400
+++ b/doc/devel/make.txt	Mon Jun 13 00:02:15 2022 -0400
@@ -19,6 +19,7 @@
 
 	SAFE=1		Compile with "safe" AnaGram (see below)
 	UNSAFE=1	Compile with "unsafe" AnaGram (see below)
+	AGFORCE=1	Force the agfiles target to rebuild.
 
 If you add a file to the build, rerun "make rules" in the affected
 build directories. If you add a whole directory, you need to rerun the
@@ -34,6 +35,12 @@
 away the depend files (depend.mk and *.u or *.d) to keep make from
 complaining that it doesn't exist.
 
+Note that the 'agfiles' target will only rebuild the AnaGram output if
+it appears to be out of date, unless you specify AGFORCE=1. If you
+aren't certain whether it really rebuilt, check the date stamp in the
+output header file.
+
+
 Bootstrapping notes:
 
 AnaGram is partly written using itself. This creates the potential for
@@ -46,7 +53,9 @@
 If you *are* developing, the following precautions are taken:
 
    - By default, the build runs $(TOP)/bin/agcl, which you should
-     update by hand as you see fit.
+     update by hand as you see fit. Note: update it from the copy
+     the build produces in anagram/run, not the one in anagram/agcl.
+     The latter doesn't have the checksums in it and won't run.
 
    - If you set SAFE (e.g., make SAFE=1) the build system will run
      $(TOP)/bin/safe-agcl instead, the idea being that you can be
@@ -67,10 +76,10 @@
 executable.
 
 Also note that if you are developing you should always configure with
---enable-maintainer-mode, and this *requires* $(TOP)/bin/agcl to exist
-in order to test-compile the examples. This also creates a minor
-bootstrap problem: if you don't already have an agcl to place in
-$(TOP)/bin, you have to compile one. The easiest way is as follows:
+--enable-maintainer-mode, and this *requires* $(TOP)/bin/agcl to
+exist. This also creates a minor bootstrap problem: if you don't
+already have an agcl to place in $(TOP)/bin, you have to compile
+one. The easiest way is as follows:
 
    path-to-source/configure native
    make rules
@@ -81,3 +90,13 @@
    make rules
    make
 
+And finally, note that the 'agfiles' target depends make-style, that
+is, by timestamp, on the agcl executable selected. If reverting to an
+older version, including via SAFE=1, it is a good idea to also
+AGFORCE=1 on the make command line, or run the 'agclean' target
+first. (There is also no such dependency when maintainer mode is not
+enabled, because that would preclude building from scratch.)
+
+The premise is that changes to the sources are much more common than
+material changes to the output that require rebuilding the parsers
+used in AnaGram itself.
--- a/mk/agfile-rules.sh	Tue May 31 02:06:45 2022 -0400
+++ b/mk/agfile-rules.sh	Mon Jun 13 00:02:15 2022 -0400
@@ -1,15 +1,22 @@
 #!/bin/sh
 # agfile-rules.sh - generate make rules for AG files
-# usage: agfile-rules.sh here|srcdir "syns" "output-extension" > rules.mk
+# usage:
+#    agfile-rules.sh where syns ext maint > rules.mk
+#
 
-if [ $# != 3 ]; then
-    echo "$0: usage: $0 here|srcdir 'syns' 'output-extension'" 1>&2
+if [ $# != 4 ]; then
+    echo "$0: usage: $0 where syns ext maint" 1>&2
+    echo "    where:      here | srcdir" 1>&2
+    echo "    syns:       list of .syn files" 1>&2
+    echo "    ext:        output extension, e.g. '.c'" 1>&2
+    echo "    maint:      maintainer | nonmaintainer" 1>&2
     exit 1
 fi
 
 WHERE="$1"
 SYNS="$2"
 EXT="$3"
+MAINT="$4"
 
 case "$WHERE" in
     here|srcdir) ;;
@@ -23,6 +30,11 @@
     exit 0
 fi
 
+echo 'agforce: ;'
+echo 'DOAGFORCE='
+echo 'DOAGFORCE0='
+echo 'DOAGFORCE1=agforce'
+
 for S in $SYNS; do
     echo $S | awk '
 	{
@@ -31,6 +43,7 @@
 	    sub("\\.syn$", "", base);
 	    cout=base ext;
 	    hout=base ".h";
+	    synsrc="$(SRCDIR)/" syn;
 
 	    if (where == "srcdir") {
 		dcout = "$(SRCDIR)/" cout;
@@ -41,8 +54,17 @@
 		dhout = hout;
 	    }
 
+	    if (maint == "maintainer") {
+	        tool = " $(AGCL)";
+	    }
+	    else {
+		tool = "";
+	    }
+
+	    force = "$(DOAGFORCE$(AGFORCE))"
+
 	    printf "agfiles: %s %s\n", dcout, dhout;
-	    printf "%s %s: $(SRCDIR)/%s\n", dcout, dhout, syn;
+	    printf "%s %s: %s %s %s\n", dcout, dhout, synsrc, tool, force;
 	    printf "\t@echo \"        [AGCL]    %-12s $(AGCLQUAL)\"\n", syn;
 
 	    printf "\t@$(AGCL) $(SRCDIR)/%s\n", syn;
@@ -51,7 +73,7 @@
 		printf "\t@mv %s %s\n", hout, dhout;
 	    }
 	}
-    ' "ext=$EXT" "where=$WHERE"
+    ' "ext=$EXT" "where=$WHERE" "maint=$MAINT"
 done
 
 echo $SYNS | tr ' ' '\n' | sed 's/.syn$//' | awk '
--- a/mk/hostprog.mk	Tue May 31 02:06:45 2022 -0400
+++ b/mk/hostprog.mk	Mon Jun 13 00:02:15 2022 -0400
@@ -36,7 +36,7 @@
 rules:
 	@$(TOP)/mk/hostprog-rules.sh '$(SRCS)' > rules.mk
 	@$(TOP)/mk/agfile-rules.sh $(AGFILEDEST) '$(SYNS)' '$(SYNOUTPUTEXT)' \
-	    >> rules.mk
+	    $(MAINTAINER) >> rules.mk
 #	@echo '        [RULES]'
 
 depend:
--- a/mk/lib.mk	Tue May 31 02:06:45 2022 -0400
+++ b/mk/lib.mk	Mon Jun 13 00:02:15 2022 -0400
@@ -51,7 +51,7 @@
 	@$(TOP)/mk/include-defs.sh '$(INCDIRS)' > rules.mk
 	@$(TOP)/mk/compile-rules.sh '$(SRCS)' '$(RCFILES)' >> rules.mk
 	@$(TOP)/mk/agfile-rules.sh $(AGFILEDEST) '$(SYNS)' '$(SYNOUTPUTEXT)' \
-	    >> rules.mk
+	    $(MAINTAINER) >> rules.mk
 #	@echo '        [RULES]'
 
 depend:
--- a/mk/prog.mk	Tue May 31 02:06:45 2022 -0400
+++ b/mk/prog.mk	Mon Jun 13 00:02:15 2022 -0400
@@ -40,7 +40,7 @@
 	@$(TOP)/mk/include-defs.sh '$(INCDIRS)' > rules.mk
 	@$(TOP)/mk/compile-rules.sh '$(SRCS)' '$(RCFILES)' >> rules.mk
 	@$(TOP)/mk/agfile-rules.sh $(AGFILEDEST) '$(SYNS)' '$(SYNOUTPUTEXT)' \
-	    >> rules.mk
+	    $(MAINTAINER) >> rules.mk
 #	@echo '        [RULES]'
 
 depend:
--- a/mk/progs.mk	Tue May 31 02:06:45 2022 -0400
+++ b/mk/progs.mk	Mon Jun 13 00:02:15 2022 -0400
@@ -32,7 +32,7 @@
 	@$(TOP)/mk/progs-rules.sh '$(SRCS)' >> rules.mk
 	@$(TOP)/mk/compile-rules.sh '$(SRCS)' '' >> rules.mk
 	@$(TOP)/mk/agfile-rules.sh $(AGFILEDEST) '$(SYNS)' '$(SYNOUTPUTEXT)' \
-	    >> rules.mk
+	    $(MAINTAINER) >> rules.mk
 #	@echo '        [RULES]'
 
 depend: