“Whoever”.

I’ve been having some trouble with constructs using the word “whoever” in English—specifically, when does one use “whoever”, and when does one use “whomever”? With something like “she who” or “he who”, it’s obvious—“I gave the flowers to him who hates them”, “I talked with he whom I saw”, etc. … what about whoever?


Basically, I’m asking whether the word “whoever” declines in respect to its own relative clause, or whether it declines with respect to the clause that contains it: “I give these books to whoever wants them” vs. “I give these books to whomever wants them”.