Construction of first-principles density functional approximations and their applications to materials