I don't know very much about the Iberian Peninsula's history (save for the Spanish Civil War and a few snippets about Portugal), but it seems that after reconquista there were several distinct groups/kingdoms and most of these became Spain but Portugal has maintained it's independence throughout the years.
I see some similarities with the Basque Country and Catalonia, all three are on the Iberian peninsula and speak languages other than Spanish. How did these other communities become part of Spain while Portugal did not?
hi! you may find something of interest in the this section of the FAQ (link on sidebar):
The basques (then the Kingdom of Navarra) were actually quite a small state, and so were annexed militarily by castille in the XVI century.
As for the catalans, well, Portugal is independent because Catalonia isn't, or to put it in other words, in 1640, both Portugal and Catalonia rebelled against castillian rule, the spanish empire armies had to choose which one of the rebellions were they going to try to supress, since they had not enough troops for both; for obvious reasons (geography, economy etc) they choose Catalonia.
Even now many spaniards feel they fucked up, and wish they had chosen portugal, but alas, too late