A higher-order homogenization method for linear elastic structures is proposed. While most existing approaches to homogenization start from the equations of equilibrium, the proposed one works at the energy level. We start from an energy functional depending on microscopic degrees of freedom on the one hand and on macroscopic variables on the other hand; the homogenized energy functional is derived by relaxing the microscopic degrees of freedom and applying a formal two-scale expansion. This method delivers the energy functional of the homogenized model directly, including boundary terms that have not been discussed in previous work. Our method is formulated in a generic setting which makes it applicable to a variety of geometries in dimension 1, 2 or 3, and without any particular assumption on material symmetry. An implementation using a symbolic calculation language is proposed and it is distributed as an open-source library. Simple illustrations to elastic trusses having pre-stress or graded elastic properties are presented. The approach is presented in the context of discrete elastic structures and the connection with previous work on the higher-order homogenization of period continua is discussed.