The previous logic implicitly assumed that CFLAGS was either unset or started with a space, breaking the MacPorts build. In addition, it also extracted the version info from the running interpreter rather than the built one.
I ran into this when trying to package the release candidate of 3.8 for MacPorts, which sets CFLAGS during the build.