The Second Life source code is available under the GNU General Public License, version 2.0, with a FLOSS exception, as well as under alternative terms for proprietary applications. For more details, see the Second Life viewer source licensing page. -----------------The license
The source code is available from the viewer source code archive page. ---------The download page for source code
To understand what you are looking at after you get the code, see viewer source. ------ Make it easier to understand the directory structure of viewer souce
Once you've downloaded the code, you can learn what to do next by reading the build instructions on the developer wiki. ------------------ compile the viewer source code.