Since 2.5.30 or similar flex now uses GNU m4 to create its output. Unfortunately up to 2.5.31, it doesn't check if m4 is GNU m4 or not, so when used on a system which USERLAND is not GNU it fails (with a -P option not found usually). Upstream already fixed this in CVS with a complete solution; the attached is mostly an hack but it's the least invasive thing I can think of. Thanks, Diego P.S.: flex should have an RDEPEND on sys-devel/m4.
Created attachment 80258 [details, diff] flex-2.5.31-gm4.patch
in cvs, thanks