reorder compile and link flags

only include ldflags/cflags where appropriate.
reorder the linker flags to make newer gcc happy.
update the location of libs
throw fewer events