The entropy of non-ergodic complex systems - A derivation from first principles