google was a search engine to start with, then it started to become bigger and needed some funding, it used it popularity as a search engine to get in to the ad business and once it had a source of revenue has started branching out in to various other areas (some profitable, but most cost them money to run)
google has 2 sides to the company, the majority of what it does is giving to the community to help out, but of course there is a (growing) commercial side to the company as well (that is how it can afford to give..)