A copolymer near a selective interface: variational characterization of the free energy