Add -lm to LDFLAGS && fix segfaults in generator

Signed-off-by: Cyril Hrubis <metan@ucw.cz>