The design of freeform optical surfaces is an inverse problem in illumination optics. Combining the laws of geometrical optics and energy conservation gives rise to a generalized Monge-Ampère equation. The underlying mathematical structure of some optical systems allows for an optimal-transport formulation of the problem with an associated cost function. This motivates the design of optimal-transport-based numerical algorithms. However, not all optical systems can be cast in the framework of optimal transport. In this paper, we derive a formulation in terms of generating functions where the generalized Monge-Ampère equation becomes a generated Jacobian equation. We present an iterative least-squares algorithm that can be used to solve generated Jacobian equations. We consider two example systems: System 1 is a single freeform lens with a point source and far-field target, and System 2 is a single freeform reflector with a parallel source beam and near-field target. We introduce a novel derivation of the generating functions via Hamilton's characteristics. We can associate a cost function to System 1, and we compare the performance of the numerical algorithm to a previous optimal-transport-based version. System 2 cannot be formulated as an optimal-transport problem, which demonstrates the wider applicability of the new version of the algorithm to any optical system that can be described by a smooth generating function.