On Mon, Jan 25, 2021 at 03:15:47PM -0800, Paul Eggert wrote: > On 1/25/21 2:59 PM, Gavin Smith wrote: > > Does this > > work or does GNU make have other ways of doing this? (It would be > > better if it could be done without communicating via files.) Is there > > any way to set a Makefile variable from within a rule and then depend upon > > that variable being set in other rules? > > GNU Make supports variables defined via ::=, and an earlier section of a GNU > makefile could compute CC and assign to it that way. This would handle the > simple case you gave. Unfortunately there are other cases that would require > intermediate files with current GNU Make. Still, the overhead in using files > would be worth it (at least for me) if we could use make -j. > > The ::= feature was added to POSIX ten years ago or so, so it could even be > used in Makefiles intended to be portable to other new-enough > POSIX-compatible platforms. It wouldn't work on older platforms, though.
Another issue is how to record the results of tests from a a Makefile. With autoconf, autoconf variables are recorded with AC_CONFIG_FILES and AC_CONFIG_HEADERS. Presumably the same would have to be done, substituting in an output file with the values of these variables. However, there can be many hundreds of them (just look at a Makefile.in file). As far as I can tell, there isn't an easy way to export hundreds of Makefile variables to a process. Is there some feature or trick I'm missing? You could build up a long command line, but it could end up being extremely long. The code below shows how this could be done with GNU Make (for just 3 variables). The substitution step would need to be done after all the variables had been set, unless there was some kind of locking/synchronisation to allow Makefile rules to record configuration variables in parallel. It's possible to create a small file for every variable but this would lead to hundreds of small files being created. VARS::= VARS::=$(VARS) A=$$(A) set-A: $(eval A ::= $(shell echo 1)) VARS::=$(VARS) B=$$(B) set-B: $(eval B ::= $(shell echo 2)) VARS::=$(VARS) C=$$(C) set-C: $(eval C ::= $(shell echo 3)) finish-configure: set-A set-B set-C $(eval EXVARS=$(VARS)) export $(EXVARS) ; echo "$$A $$B $$C"