In this paper, we address the formation of a magnetic flux rope (MFR) that erupted on 2012 July 12 and caused a strong geomagnetic storm event on July 15. Through analyzing the long-term evolution of the associated active region observed by the Atmospheric Imaging Assembly and the Helioseismic and Magnetic Imager on board the Solar Dynamics Observatory, it is found that the twisted field of an MFR, indicated by a continuous S-shaped sigmoid, is built up from two groups of sheared arcades near the main polarity inversion line half day before the eruption. The temperature within the twisted field and sheared arcades is higher than that of the ambient volume, suggesting that magnetic reconnection most likely works there. The driver behind the reconnection is attributed to shearing and converging motions at magnetic footpoints with velocities in the range of 0.1--0.6 km s$^{-1}$. The rotation of the preceding sunspot also contributes to the MFR buildup. Extrapolated three-dimensional non-linear force-free field structures further reveal the locations of the reconnection to be in a bald-patch region and in a hyperbolic flux tube. About two hours before the eruption, indications for a second MFR in the form of an S-shaped hot channel are seen. It lies above the original MFR that continuously exists and includes a filament. The whole structure thus makes up a stable double-decker MFR system for hours prior to the eruption. Eventually, after entering the domain of instability, the high-lying MFR impulsively erupts to generate a fast coronal mass ejection and X-class flare; while the low-lying MFR remains behind and continuously maintains the sigmoidicity of the active region.