General maximum entropy principle for self-gravitating perfect fluid