Grain-boundary segregation in systems with limited solubility and chemical compounds