diff --git a/.gitignore b/.gitignore
index b9be357648cbea9387d2c282770727e057ad3a02..b8a62f0ed0177051bae53a4a40fc4fb21e4ec5ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
 # exclude patterns (uncomment them if you want to use them):
 
 # Our Programs
+prep_plot
 *.app
 *.test
 *.elf
diff --git a/configure.in b/configure.in
index a6525da051cf384a04753d0a4e23c4058bb1c7ec..f8aa7439970cb08c87057e94f7bf3688723ad26c 100644
--- a/configure.in
+++ b/configure.in
@@ -41,6 +41,21 @@ AC_ARG_ENABLE([libraries],
      [build_libraries=no])
 AM_CONDITIONAL(BUILD_LIBRARIES, test "x$build_libraries" = xyes)
 
+# AutoTroll with Qt
+AC_ARG_ENABLE([gui],
+    [AS_HELP_STRING([--enable-gui],
+        [build JSBSim gui [default=no]])],
+     [build_gui=$enableval],
+     [build_gui=no])
+AM_CONDITIONAL(BUILD_GUI, test "x$build_gui" = xyes)
+AS_IF([test "x$build_gui" = "xyes"], [
+	PKG_CHECK_MODULES([OSG],[openscenegraph])
+])
+AS_IF([test "x$build_gui" = "xyes"], [
+	AT_WITH_QT([gui opengl])
+])
+
+
 dnl Checks for programs.
 AC_DISABLE_SHARED
 AC_PROG_CPP
@@ -106,9 +121,6 @@ AC_DEFINE(socklen_t,size_t)], [
 AC_MSG_RESULT(int)
 AC_DEFINE(socklen_t,int)])])
 
-# AutoTroll with Qt
-AT_WITH_QT([gui opengl])
-
 AC_OUTPUT( 
 	jsbsim.pc 
 		Makefile 
diff --git a/gui/Makefile.am b/gui/Makefile.am
index 17a6511effe7c8d9c7774e3fff1e59e8bd952c45..2a7fb7a425a7aa862a4c22e801368ecd8fb65bf8 100644
--- a/gui/Makefile.am
+++ b/gui/Makefile.am
@@ -1,3 +1,5 @@
+if BUILD_GUI
+
 include $(top_srcdir)/autotroll.mk
 
 # initiliaze to null
@@ -5,12 +7,26 @@ bin_PROGRAMS =
 BUILT_SOURCES =
 
 bin_PROGRAMS += trim
-trim_SOURCES = main.cpp MainWindow.cpp MainWindow.hpp MainWindow.ui MainWindow.ui.h \
+trim_SOURCES = main.cpp MainWindow.cpp MainWindow.hpp MainWindow.moc.cpp MainWindow.ui.h \
 			   osgUtils.cpp osgUtils.hpp Viewer.cpp Viewer.hpp QOSGAdapterWidget.cpp \
-			   QOSGAdapterWidget.hpp \
-			   $(top_srcdir)/src/math/FGNelderMead.cpp
+			   QOSGAdapterWidget.hpp $(top_srcdir)/src/math/FGNelderMead.cpp \
+			   ${top_srcdir}/src/FGFDMExec.cpp ${top_srcdir}/src/FGJSBBase.cpp \
+			   ${top_srcdir}/src/FGFDMExec.h ${top_srcdir}/src/FGJSBBase.h
 trim_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS)
-trim_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS) -DUSE_QT4 -DDATADIR=\"$(top_srcdir)/data\" -I$(top_srcdir)/src
+trim_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS) $(OSG_CFLAGS) -DUSE_QT4 -DDATADIR=\"$(top_srcdir)/data\" -I$(top_srcdir)/src
 trim_LDFLAGS  = $(QT_LDFLAGS) $(LDFLAGS)
-trim_LDADD    = $(QT_LIBS) $(LDADD)
+trim_LDADD    = $(QT_LIBS) $(LDADD) $(OSG_LIBS) -lboost_thread-mt -lboost_system-mt -lm \
+	$(top_srcdir)/src/initialization/libInit.a \
+	$(top_srcdir)/src/models/atmosphere/libAtmosphere.a \
+	$(top_srcdir)/src/models/libModels.a \
+	$(top_srcdir)/src/models/flight_control/libFlightControl.a \
+	$(top_srcdir)/src/models/propulsion/libPropulsion.a \
+	$(top_srcdir)/src/input_output/libInputOutput.a \
+	$(top_srcdir)/src/math/libMath.a \
+	$(top_srcdir)/src/simgear/props/libProperties.a \
+	$(top_srcdir)/src/simgear/xml/libExpat.a \
+	$(top_srcdir)/src/simgear/magvar/libcoremag.a
+
 BUILT_SOURCES += MainWindow.moc.cpp MainWindow.ui.h
+
+endif