In 1807, during the Peninsular War (1807-14), France and Spain signed the secret Treaty of Fontainebleau foreseeing the invasion and subsequent division of Portuguese territory into three kingdoms. In the same year French troops commanded by General Junot entered Portugal. Portugal called for support from England while, at the same time, the Portuguese royal family left the country for Brazil. In 1808, Portuguese and British troops commanded by the Duke of Wellington defeated the French in the Battles of Roliça and Vimeiro. This forced Junot to negotiate the Convention of Cintra, which led to the evacuation of the French army from Portugal. A second invasion by French troops in 1809, commanded by Marshal Soult was forced to retreat. Wellington then decided to construct lines of defence for Lisbon, in order to defend against any further invasion and also to protect his own retreat and possible evacuation if overwhelmed by French forces. The Fort of Feira was constructed as part of the second line of the Lines of Torres Vedras. A third French invasion, headed by Marshal André Masséna advanced to the Lines of Torres Vedras but could not pass them and after five months was forced to retreat.