Obtaining SDL's source code
Building and installation
Building and installing SDL for your platform (including how to obtain prebuilt binaries in some cases) is covered in Installation.
The source code to the latest official release of SDL2 is here.
If you want up to the minute bug fixes and improvements, you can track our work in SDL's Mercurial repository:
hg clone https://hg.libsdl.org/SDL SDL
We intend official releases to be reasonably stable, and don't promise anything about the quality level of the Mercurial repo from moment to moment, but as official releases tend to happen months apart, you might find a bug that's bothering you is fixed in revision control long before it makes it to a release.
SDL 1.2 (obsolete/legacy)
(tl;dr: don't use SDL 1.2)
If you want SDL 1.2, the final released version is 1.2.15. We occasionally collect a fix or two in revision control, but our current intention is to never release an official 1.2.16 build, and while we may accept small patches, we do not intend to ever work on 1.2 again. You should expect it to continue to bitrot over time, and become a liability to your project. The best course of action is to move to SDL 2.0 or later as quickly as possible, and we have put together a migration guide to help with this.
The 1.2.15 source code is here if you must have it.
You can find 1.2's source code in our Mercurial repository in the SDL-1.2 branch:
hg clone -u SDL-1.2 https://hg.libsdl.org/SDL SDL-1.2
This will leave you with an "SDL-1.2" directory with the latest (post-1.2.15) changes to SDL 1.2. You can use the -b option instead of -u to get a smaller checkout if you really just want the 1.2 source code.
Please note that eventually this branch will become a small compatibility shim that bridges the 1.2 API to a real build of SDL2. Plan accordingly.