One thing to figure out relatively early on is how you're going to move between the two countries. Ideally, you'll fly into one of them and out of the other so you don't have to deal with the border crossing more than once. Ground transportation between Spain and Portugal is quite limited, to the point that I, at least, would suggest that you pick one of the two countries for this trip. Portugal is fairly small but has way more than enough to keep you busy for two weeks, and Spain--well, I spent 89 days there in 2016 and didn't get to Andalucía.
Because of the international drop charge, you will probably find it cost-prohibitive to pick up and drop off a rental car in different countries. So that leaves the overnight train between Madrid and Lisbon, a bus from southern Spain to the Algarve (and I wouldn't include the Algarve in a short trip like this), a bus or train from Porto up to Santiago de Compostela, or a flight. You can take a look at flight options on Skyscanner.com.
Oops: I forgot the bus from Badajoz to (I guess) Lisbon. But it's very unlikely you'll find yourself in Badajoz.