You need a Gift of Mastery, a Gift of Fortune, a Legendary Weapon Gift (varies depending on what weapon you want), and a Precursor.
Each of those has their own way of forming them. A basic overview would be to visit the wiki
http://wiki.guildwars2.com/wiki/Legendary_weapon
It's a long process (unless you have a lot of gold, then you can just buy it). To start it is just to play your character and get 100% map completion. A lot of the other stuff can be gotten through just that. Once you have that done then you can see what else you need.