Stage-by-Stage optimization approach to optimal control for general time-delay systems