Sun Pharmaceutical Industries Ltd is buying Ranbaxy Laboratories Ltd through an all-stock merger in which five shares of Ranbaxy will fetch four shares of Sun Pharma.