If you buy all of your pesto ingredients at the grocery store to make homemade pesto, then you are going to pay premium price, but there is another way.
1 - grow the basil yourself. It costs $1 to buy a pack of basil seeds, and you can just put it in your flower bed and take care of it with the rest of your flowers, and you end up with way more basil than you and your neighborhood could ever use
2 - grow your own garlic. Buy a bulb from the grocery store, and plant a couple of the cloves (again, in your flowerbed) - look up specifics on drying and storage for your area so you don't get rotten garlic. One bulb produces roughly 15 cloves and each clove produces another bulb, so you may never have to actually purchase garlic again
3 - pine nuts. This is the toughy - you can do one of 2 things - buy them in bulk to save the moolah over time, or go find some pine cones and harvest them yourself. This can be done, but it is a little labor intensive. However if you have the time, go for it - make it a job for kids looking for something to do.
4 - Olive oil - unless you know how to press it yourself, just buy it, and get a good quality.
Put basil leaves (4 cups unshredded is a good place to start), 2 garlic cloves, and 2 tbsp pine nuts in a blender and blend for 20 seconds on pulse. Then, drizzle in the oil from the top of the blender (through the hole made for that purpose, not with the lid completely off) and pulse the blender at the same time until you reach the desired consistency. Easy smeasy - and you can vary it how you like: add in another herb, use a different nut, salt, pepper or cayenne for flavor, add parmesan cheese, etc, etc - have fun with it.