Rewrite makefile and put linker flags at the end

Putting the linker flags at the end seems to be necessary to have it
link correctly.