On Linux one could do bla=$(free | grep Mem | awk '{ printf "%d\n", $2/1024/1024 }'),  but I don't know if 'free' is portable. 

Anyway, considering that by bailing out in  pkg_pretend is done before any compiling takes place I don't think it is a big deal to ask the user to set this (and, if needed, the other) variable manually.