WARNING: does not respect PTHREAD_{FLAGS,LIBS}. I could not find a clean way to patch it in. It should still work fine for the common case, though.