XX vs XY
XY – it's as if one of 2nd X's little legs was broken off and replaced by penis.
At first, we all start off as female embryos. Some, I believe, being somewhat less then perfect, are sorted out to be males in the future. After all, females are much more universal - they can create babies (though not without male help so far).
Here is an illustration to this thought: there is a genetic defect called 'Testicular Feminization'. A girl is born and raised. It is discovered that by the age of 13 -15 years, she has failed to menstruate and is taken to the doctor. The doctor examines the 'girl' and states that this is, in fact, a boy, whose tissues are not sensitive to the male hormone. He does not have a uterus with ovaries, nor a vagina, but has testicles stuck in the 'labia majora'.
All the elements of the penis are built in, as usual, in the female configuration of genitalia.