Adding to other resources shared here, archaeologist Denise Schmandt-Besserat has written about the evolution of writing (not strictly the alphabet), and much is available online:
https://sites.utexas.edu/dsb/tokens/the-evolution-of-writing...
The roots of writing seems to be in counting/tallying marks, i.e. accounting. Another great book, "Against the Grain" by James Scott, describes how both tallying and writing developed hand-in-hand with the state.