How and why?
You are talking 40,000 years ago Lover. And pre-literate societies. I suggest funding more archaeological work! If we don’t want to do that, then we have to use our imaginations. As I said, the people 40,000 ya who advanced astronomy were, well, astronomers , perhaps astronomer priests. They were smart, imaginative, artistic folks. We are indebted to the whoever they were, irrespective about the accuracy of their calculations.
We may never know exactly how and why.