Add prologue code.
Add options for manual selection of APIs.
Remove primitive API selection code.
Add full API selection mechanism.

Mostly copied from configure.ac.
Set some flags depending on compiler and environment.
Build test programs.