  This paper provides necessary and sufficient conditions of optimality for
variational problems that deal with a fractional derivative with respect to
another function. Fractional Euler--Lagrange equations are established for the
fundamental problem and when in presence of an integral constraint. A Legendre
condition, which is a second-order necessary condition, is also obtained. Other
cases, such as the infinite horizon problem, the problem with delays in the
Lagrangian, and the problem with high-order derivatives, are considered.
Finally, a necessary condition for the optimal fractional order to satisfy is
proved.
