Juanjo Comellas excelent getopt

This should be a external dependency, right now I decided to copy the
appropriate bits.