Due to .for loop, opt_VARS are expanded early during bsd.options.mk evaluation, which makes it impossible to use some vars which are set/modifies afterwards (such as PREFIX or PKGDIR)
Fix this by changing opt_VARS handling logic:
- Loop not by words (each word here is single VAR=val / VAR+=val tuple) but by unique left sides of assignments (VAR, VAR+ here)
- Using the left side, extract all corresponding right sides and append/assign them to a variable
This way right sides are not expanded preliminary and opt_VARS work as expected.
This also allows either logic for duplicated assignments:
opt_VAR= FOO=one FOO=two
currently leads to FOO=two, however if :[-1] is removed from the patch, this will lead to FOO=one two.
The current approach seems more consistent though, and there is still a way to assign multiple values with FOO="one two"