Fix CFLAGS order.
Fix detected flags from ACX_PTHREAD being reset.
Include path should be CPPFLAGS, not CFLAGS.
Merge pull request #1765 from jimis/minor

Fix detected flags from ACX_PTHREAD being reset.