Substitute values properly, fix linking flags.