-# stores PLDISTRO in a file
-# this is done at stage1. later run wont get confused
-savedpldistro.mk:
- echo "PLDISTRO:=$(PLDISTRO)" > $@
- echo "PLDISTROTAGS:=$(PLDISTROTAGS)" >> $@
- echo "build-SVNPATH:=$(build-SVNPATH)" >> $@
- echo "PERSONALITY:=$(PERSONALITY)" >> $@
- echo "MAILTO:=$(MAILTO)" >> $@
- echo "BASE:=$(BASE)" >> $@
- echo "WEBPATH:=$(WEBPATH)" >> $@
- echo "TESTBUILDURL:=$(TESTBUILDURL)" >> $@
- echo "WEBROOT:=$(WEBROOT)" >> $@
- echo "alias m=\"make PLDISTRO=$(PLDISTRO) PLDISTROTAGS=$(PLDISTROTAGS)\"" > aliases
- echo "alias m1=\"make stage1=true PLDISTRO=$(PLDISTRO) PLDISTROTAGS=$(PLDISTROTAGS)\"" >> aliases
-
-savedpldistro: savedpldistro.mk
-.PHONY: savedpldistro
+# stores env variables in a file
+# this is done at stage1. later run won't get confused
+STATIC_VARS=PLDISTRO PLDISTROTAGS build-GITPATH PERSONALITY MAILTO BASE WEBPATH TESTBUILDURL WEBROOT
+# find out names for variables set on the command line
+define assigned_varname
+$(if $(findstring =,$(1)),$(firstword $(subst =, ,$(1))) )
+endef
+ASSIGNED=$(filter-out stage1 stage1iter,$(foreach flag,$(MAKEFLAGS),$(call assigned_varname,$(flag))))
+SAVED_VARS=$(sort $(STATIC_VARS) $(ASSIGNED))
+envfrompreviousrun.mk:
+ @echo "# do not edit" > $@
+ @$(foreach var,$(SAVED_VARS),echo "$(var):=$($(var))" >> $@ ;)
+ @echo "# do not edit" > aliases
+ @echo -n "alias m=\"make " >> aliases
+ @$(foreach var,$(SAVED_VARS),echo -n " $(var)=$($(var))" >> aliases ;)
+ @echo "\"" >> aliases
+ @echo "alias m1=\"m stage1=true\"" >> aliases
+
+envfrompreviousrun: envfrompreviousrun.mk
+.PHONY: envfrompreviousrun