OK I think I figured out the problem. The AM_CONDITIONAL statement should be further up in the configure.ac (right after if test x$enable_gui... block)
if test x$enable_gui