simplified makefile, corrected text parsing

Thank you very much for this useful piece of code.

I've updated the text parsing to find some libraries that were being missed by your original code. I've also simplified the makefile a bit.