Move -lpthread to LDFLAGS, and splite XLDFLAGS into XLDFLAGS_BEGIN and XLDFLAGS_END.

The separation is for fitting the eglibc's flags.