We propose a general method for optimizing periodic input waveforms for global entrainment of weakly forced limit-cycle oscillators based on phase reduction and nonlinear programming. We derive averaged phase dynamics from the mathematical model of a limit-cycle oscillator driven by a weak periodic input and optimize the Fourier coefficients of the input waveform to maximize prescribed objective functions. In contrast to the optimization methods that rely on the calculus of variations, the proposed method can be applied to a wider class of optimization problems including global entrainment objectives. As an illustration, we consider two optimization problems, one for achieving fast global convergence of the oscillator to the entrained state and the other for realizing prescribed global phase distributions in a population of identical uncoupled noisy oscillators. We show that the proposed method can successfully yield optimal input waveforms to realize the desired states in both cases.