Build script only works after multiple runs


Sorry for the not-so-specific title, but I’m really confused about this issue.

I’m building mpir (a windows-compatible gmp fork) on windows using their msbuild.bat as an external project. I’d like to build shared and static libraries, as well as in debug and release mode, hence I call the build file with different arguments multiple times.

Looking at an actual job, I see the following behaviour:
The first call fails with “-latest is not recognized …”, indicating that for some reason the variable vsw_exe was empty here, though it was set in the line before.
In the second call this seems to be fine, but still the result of this whole thing is not there yet: the output here indicates that msbdir is still empty.

From the third call on, everything is fine. Note that is does not depend on the arguments to the script: I can change the order and still the first two runs fail with the same errors. Also the arguments are not even used in the parts of the script that behave weirdly.

Right now I simply issue six calls to this script which eventually manages to build all four versions of this library… but there is something wrong here still…

Can anyone give me a hint what the issue may be? (or how to investigate further)