ISTANBUL — With war on Turkey’s borders, and political and economic troubles in Egypt, the two countries have turned to each other for support, looking to build an alliance that could represent a significant geopolitical shift in the Middle East prompted by the Arab Spring, uniting two countries with regional ambitions each headed by parties with roots in political Islam.