Did the idea of Prime and Megatron being old friends really not predate the live-action movies? I though it went further back than that. Wow.
It's not like every continuity was like Sunbow, with Megatron trying to kill Optimus at their first meeting. I believe Marvel UK had them knowing each other as rival gladiators. I remember G2 having Optimus muse about how he'd always hoped Megatron could be brought to work for the good of Cybertron, kinda hinting at some level of respect at least, if not friendship. But yeah, I don't recall any real substantial relationships between them prior to the 2007 movie.
It's easy to forget almost 20 years later, but there wasn't that much to the franchise at that point. We had Marvel and Sunbow flavors of G1, BW/BM that didn't really feature them, RiD, the Unicron Trilogy, and Dreamwave (which felt like a Superman Returns approach to Sunbow G1, kinda following the early parts of it in spirit while ignoring the later stuff).
As best I can recall, that bit in the 2007 movie and its media was the first time hinting at anything more than maybe respect and rivalry between them. And then IDW and Aligned really established the idea of them having been friends before the war.