Full rewrite, move to autotools

TODO: add correct headers for the install phase