Respect LDFLAGS

LDFLAGS variable has to be ordered differently. CFLAGS don't need to be added to the linking phase.
I added some other small improvements.