changeset 15140:bfc220d1de67 gui

include gui in default Octave binary * Makefile.am (GUIDIR): New variable. (SUBDIRS): Use it in the list instead of @GUIDIR@. List $(GUIDIR) before src. * gui/src/Makefile.am (bin_PROGRAMS): Delete. (octlib_LTLIBRARIES): New variable. (liboctgui_la_SOURCES): Rename from octave_gui_SOURCES. (liboctgui_la_CPPFLAGS): Rename from octave_gui_CPPFLAGS. (liboctgui_la_LIBADD): Rename from octave_gui_LDADD. Don't include Octave libraries in the list. Do include Qt libraries in the list. (liboctgui_la_LDFLAGS): Rename from octave_gui_LDFLAGS. Only include -L@QT_LIBDIR@ option in the list. (moc_%.cpp): Use $(liboctgui_la_CPPFLAGS) in rules, not $(octave_gui_CPPFLAGS). * octave-gui.h: New file. * octave-gui.cc: Include it. (dissociate_terminal): In parent, wait for child process and exit with exit status of child. (octave_start_gui): Rename from main. * run-octave.in: Start with GUI by default. Rename -gui option -cli to allow running octave-cli binary. * main.cc, main-cli.cc: New files. * main.c: Delete. * src/Makefile (bin_PROGRAMS): Include octave-cli in the list. (OCTAVE_CORE_LIBS): New variable. (octave_cli_SOURCES, octave_cli_LDADD, octave_cli_LDFLAGS): New variables. (octave_SOURCES): Define to main.cc, not main.c. (octave_CPPFLAGS): New variable. (octave_LDFLAGS): Include -DENABLE_GUI=1 in the list. (octave_LDADD): Use $(OCTAVE_CORE_LIBS) and link with GUI lib. * octave.cc (force_gui_option, no_gui_option): New static variables. (octave_starting_gui): New function. (usage_string): Update for new options. (FORCE_GUI_OPTION, NO_GUI_OPTION): New macros. (long_opts): Include "force-gui" and "no-gui" options in the list. (octave_main): Handle FORCE_GUI_OPTION and NO_GUI_OPTION cases. Error if both --force-gui and --no-gui are used. * octave.h (octave_starting_gui): Provide decl.
author John W. Eaton <jwe@octave.org>
date Fri, 10 Aug 2012 10:27:32 -0400
parents 089b98bdaebf
children 2eb789da13c3
files Makefile.am gui/src/Makefile.am gui/src/octave-gui.cc gui/src/octave-gui.h run-octave.in src/Makefile.am src/main-cli.cc src/main.c src/main.cc src/octave.cc src/octave.h
diffstat 11 files changed, 259 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,12 +67,12 @@
 
 include m4/module.mk
 
-# Subdirectories in which to run `make all'.
-SUBDIRS = libgnu libcruft liboctave src @GUIDIR@ scripts @DOCDIR@ examples test
+if OCTAVE_GUI
+GUIDIR = gui
+endif
 
-if OCTAVE_GUI
-SUBDIRS += gui
-endif
+# Subdirectories in which to run `make all'.
+SUBDIRS = libgnu libcruft liboctave $(GUIDIR) src scripts @DOCDIR@ examples test
 
 if ! AMCOND_BUILD_DOCS
 dist-hook:
--- a/gui/src/Makefile.am
+++ b/gui/src/Makefile.am
@@ -3,7 +3,7 @@
 
 moc_%.cpp: %.h
 	test -d $(@D) || mkdir -p $(@D)
-	@MOC@ -o$@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(octave_gui_CPPFLAGS) $<
+	@MOC@ -o$@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liboctgui_la_CPPFLAGS) $<
 
 ui_%.h: %.ui
 	@UIC@ -o $@ $<
@@ -11,8 +11,6 @@
 qrc_%.cpp: %.qrc
 	@RCC@ -o $@ $<
 
-bin_PROGRAMS = octave-gui
-
 octave_gui_MOC = \
 		 moc_documentation-dockwidget.cpp \
 		 moc_files-dockwidget.cpp \
@@ -39,7 +37,9 @@
 
 octave_gui_RC = qrc_resource.cpp
 
-octave_gui_SOURCES = \
+octlib_LTLIBRARIES = liboctgui.la
+
+liboctgui_la_SOURCES = \
 		     documentation-dockwidget.cc \
 		     files-dockwidget.cc \
 		     history-dockwidget.cc \
@@ -60,33 +60,37 @@
 		     octave-adapter/octave-main-thread.cc \
 		     qtinfo/parser.cc \
 		     qtinfo/webinfo.cc
-nodist_octave_gui_SOURCES = $(octave_gui_MOC) $(octave_gui_RC)
+
+liboctgui_la_LIBADD = \
+  libqterminal.la \
+  -lQtCore \
+  -lQtGui \
+  -lQtNetwork \
+  -lqscintilla2
+
+nodist_liboctgui_la_SOURCES = $(octave_gui_MOC) $(octave_gui_RC)
 
-octave_gui_CPPFLAGS = -I@QT_INCDIR@ \
-                      -I@QT_INCDIR@/QtCore \
-		      -I@QT_INCDIR@/QtGui \
-		      -I@QT_INCDIR@/QtNetwork \
-		      -I$(srcdir)/../qterminal/libqterminal \
-		      -I$(srcdir)/m-editor \
-		      -I$(srcdir)/octave-adapter \
-		      -I$(srcdir)/qtinfo \
-		      -I$(srcdir)/../../libcruft/misc \
-		      -I../../liboctave \
-		      -I$(srcdir)/../../liboctave \
-		      -I../../src/interp-core \
-		      -I$(srcdir)/../../src \
-		      -I$(srcdir)/../../src/interp-core \
-		      -I$(srcdir)/../../src/interpfcn \
-		      -I$(srcdir)/../../src/octave-value \
-		      -I$(srcdir)/../../src/operators \
-		      -I$(srcdir)/../../src/parse-tree
+liboctgui_la_CPPFLAGS = \
+  -I@QT_INCDIR@ \
+  -I@QT_INCDIR@/QtCore \
+  -I@QT_INCDIR@/QtGui \
+  -I@QT_INCDIR@/QtNetwork \
+  -I$(srcdir)/../qterminal/libqterminal \
+  -I$(srcdir)/m-editor \
+  -I$(srcdir)/octave-adapter \
+  -I$(srcdir)/qtinfo \
+  -I$(srcdir)/../../libcruft/misc \
+  -I../../liboctave \
+  -I$(srcdir)/../../liboctave \
+  -I../../src/interp-core \
+  -I$(srcdir)/../../src \
+  -I$(srcdir)/../../src/interp-core \
+  -I$(srcdir)/../../src/interpfcn \
+  -I$(srcdir)/../../src/octave-value \
+  -I$(srcdir)/../../src/operators \
+  -I$(srcdir)/../../src/parse-tree
 
-octave_gui_LDADD = libqterminal.la \
-		   ../../src/liboctinterp.la \
-                   ../../liboctave/liboctave.la \
-                   ../../libcruft/libcruft.la
-
-octave_gui_LDFLAGS = -L@QT_LIBDIR@ -lQtCore -lQtGui -lQtNetwork -lqscintilla2
+liboctgui_la_LDFLAGS = -L@QT_LIBDIR@
 
 noinst_HEADERS = \
 		 documentation-dockwidget.h \
--- a/gui/src/octave-gui.cc
+++ b/gui/src/octave-gui.cc
@@ -21,6 +21,7 @@
 #include "welcome-wizard.h"
 #include "resource-manager.h"
 #include "main-window.h"
+#include "octave-gui.h"
 
 // Dissociate from the controlling terminal, if any.
 
@@ -28,6 +29,7 @@
 dissociate_terminal (void)
 {
 #if ! defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN)
+
   pid_t pid = fork ();
 
   if (pid < 0)
@@ -46,15 +48,22 @@
         }
     }
   else
-    exit (0);
+    {
+      // Parent
+
+      int status;
+
+      waitpid (pid, &status, 0);
+
+      exit (WIFEXITED (status) ? WEXITSTATUS (status) : 127);
+    }
+
 #endif
 }
 
 int
-main (int argc, char *argv[])
+octave_start_gui (int argc, char *argv[])
 {
-  octave_initialize_interpreter (argc, argv, 0);
-
   dissociate_terminal ();
 
   QApplication application (argc, argv);
new file mode 100644
--- /dev/null
+++ b/gui/src/octave-gui.h
@@ -0,0 +1,28 @@
+/*
+
+Copyright (C) 2012 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if !defined (octave_octave_gui_h)
+#define octave_octave_gui_h 1
+
+extern int octave_start_gui (int argc, char **argv);
+
+#endif
--- a/run-octave.in
+++ b/run-octave.in
@@ -66,8 +66,8 @@
   elif [ "x$1" = "x-strace" ]; then
     driver="strace -o octave.trace"
     shift
-  elif [ "x$1" = "x-gui" ]; then
-    octave_executable="$builddir/gui/src/octave-gui"
+  elif [ "x$1" = "x-cli" ]; then
+    octave_executable="$builddir/src/octave-cli"
     shift
   fi
 fi
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,7 @@
 bin_PROGRAMS = \
   mkoctfile \
   octave \
+  octave-cli \
   octave-config
 
 mkoctfile_SOURCES =
@@ -58,7 +59,8 @@
   octave-config.cc
 else
 bin_PROGRAMS = \
-  octave
+  octave \
+  octave-cli
 
 bin_SCRIPTS = \
   mkoctfile \
@@ -218,18 +220,32 @@
 ## FIXME: Does this rule need to be uncommented?
 #fft.df fft.lo fft2.df fft2.lo fftn.df fftn.lo: CPPFLAGS += $(FFTW_XCPPFLAGS)
 
-octave_SOURCES = main.c
-
-octave_LDADD = \
+OCTAVE_CORE_LIBS = \
   liboctinterp.la \
   ../liboctave/liboctave.la \
-  ../libcruft/libcruft.la \
+  ../libcruft/libcruft.la
+
+octave_cli_SOURCES = main-cli.cc
+
+octave_cli_LDADD = \
+  $(OCTAVE_CORE_LIBS)
   $(OCTAVE_LINK_DEPS)
 
-octave_LDFLAGS = \
+octave_cli_LDFLAGS = \
   $(NO_UNDEFINED_LDFLAG) \
   $(OCTAVE_LINK_OPTS)
 
+octave_SOURCES = main.cc
+
+octave_CPPFLAGS = -I$(top_srcdir)/gui/src
+
+octave_LDADD = \
+  $(OCTAVE_CORE_LIBS) \
+  ../gui/src/liboctgui.la \
+  $(OCTAVE_LINK_DEPS)
+
+octave_LDFLAGS = -DENABLE_GUI=1 $(octave_cli_LDFLAGS)
+
 ## Section for defining and creating DEF_FILES
 SRC_DEF_FILES := $(shell $(srcdir)/find-defun-files.sh "$(srcdir)" $(DIST_SRC))
 
new file mode 100644
--- /dev/null
+++ b/src/main-cli.cc
@@ -0,0 +1,35 @@
+/*
+
+Copyright (C) 2012 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <octave.h>
+
+int
+main (int argc, char **argv)
+{
+  octave_initialize_interpreter (argc, argv, 0);
+
+  return octave_execute_interpreter ();
+}
deleted file mode 100644
--- a/src/main.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-
-Copyright (C) 2002-2012 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
-option) any later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "f77-fcn.h"
-#include "lo-ieee.h"
-
-#include "octave.h"
-
-int
-main (int argc, char **argv)
-{
-  return octave_main (argc, argv, 0);
-}
new file mode 100644
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,39 @@
+/*
+
+Copyright (C) 2012 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <octave.h>
+#include <octave-gui.h>
+
+int
+main (int argc, char **argv)
+{
+  octave_initialize_interpreter (argc, argv, 0);
+
+  if (octave_starting_gui ())
+    return octave_start_gui (argc, argv);
+
+  return octave_execute_interpreter ();
+}
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -56,6 +56,7 @@
 #include "lex.h"
 #include "load-path.h"
 #include "octave.h"
+#include "oct-conf.h"
 #include "oct-hist.h"
 #include "oct-map.h"
 #include "oct-mutex.h"
@@ -119,14 +120,23 @@
 // (--verbose; -V)
 static bool verbose_flag = false;
 
+// If TRUE, force the GUI to start.
+// (--force-gui)
+static bool force_gui_option = false;
+
+// If TRUE don't start the GUI.
+// (--no-gui)
+static bool no_gui_option = false;
+
 // Usage message
 static const char *usage_string =
   "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\
-       [--exec-path path] [--help] [--image-path path] [--info-file file]\n\
-       [--info-program prog] [--interactive] [--line-editing]\n\
-       [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\
-       [--no-site-file] [--no-window-system] [-p path] [--path path]\n\
-       [--silent] [--traditional] [--verbose] [--version] [file]";
+       [--exec-path path] [--force-gui] [--help] [--image-path path]\n\
+       [--info-file file] [--info-program prog] [--interactive]\n\
+       [--line-editing] [--no-gui] [--no-history] [--no-init-file]\n\
+       [--no-init-path] [--no-line-editing] [--no-site-file]\n\
+       [--no-window-system] [-p path] [--path path] [--silent]\n\
+       [--traditional] [--verbose] [--version] [file]";
 
 // This is here so that it's more likely that the usage message and
 // the real set of options will agree.  Note: the `+' must come first
@@ -144,18 +154,20 @@
 #define DOC_CACHE_FILE_OPTION 1
 #define EVAL_OPTION 2
 #define EXEC_PATH_OPTION 3
-#define IMAGE_PATH_OPTION 4
-#define INFO_FILE_OPTION 5
-#define INFO_PROG_OPTION 6
-#define LINE_EDITING_OPTION 7
-#define NO_INIT_FILE_OPTION 8
-#define NO_INIT_PATH_OPTION 9
-#define NO_LINE_EDITING_OPTION 10
-#define NO_SITE_FILE_OPTION 11
-#define NO_WINDOW_SYSTEM_OPTION 12
-#define PERSIST_OPTION 13
-#define TEXI_MACROS_FILE_OPTION 14
-#define TRADITIONAL_OPTION 15
+#define FORCE_GUI_OPTION 4
+#define IMAGE_PATH_OPTION 5
+#define INFO_FILE_OPTION 6
+#define INFO_PROG_OPTION 7
+#define LINE_EDITING_OPTION 8
+#define NO_GUI_OPTION 9
+#define NO_INIT_FILE_OPTION 10
+#define NO_INIT_PATH_OPTION 11
+#define NO_LINE_EDITING_OPTION 12
+#define NO_SITE_FILE_OPTION 13
+#define NO_WINDOW_SYSTEM_OPTION 14
+#define PERSIST_OPTION 15
+#define TEXI_MACROS_FILE_OPTION 16
+#define TRADITIONAL_OPTION 17
 struct option long_opts[] =
   {
     { "braindead",        no_argument,       0, TRADITIONAL_OPTION },
@@ -164,12 +176,14 @@
     { "echo-commands",    no_argument,       0, 'x' },
     { "eval",             required_argument, 0, EVAL_OPTION },
     { "exec-path",        required_argument, 0, EXEC_PATH_OPTION },
+    { "force-gui",        no_argument,       0, FORCE_GUI_OPTION },
     { "help",             no_argument,       0, 'h' },
     { "image-path",       required_argument, 0, IMAGE_PATH_OPTION },
     { "info-file",        required_argument, 0, INFO_FILE_OPTION },
     { "info-program",     required_argument, 0, INFO_PROG_OPTION },
     { "interactive",      no_argument,       0, 'i' },
     { "line-editing",     no_argument,       0, LINE_EDITING_OPTION },
+    { "no-gui",           no_argument,       0, NO_GUI_OPTION },
     { "no-history",       no_argument,       0, 'H' },
     { "no-init-file",     no_argument,       0, NO_INIT_FILE_OPTION },
     { "no-init-path",     no_argument,       0, NO_INIT_PATH_OPTION },
@@ -632,7 +646,8 @@
   disable_warning ("Octave:possible-matlab-short-circuit-operator");
 }
 
-// You guessed it.
+// EMBEDDED is declared int instead of bool because this function is
+// declared extern "C".
 
 int
 octave_main (int argc, char **argv, int embedded)
@@ -642,6 +657,9 @@
   return octave_execute_interpreter ();
 }
 
+// EMBEDDED is declared int instead of bool because this function is
+// declared extern "C".
+
 void
 octave_initialize_interpreter (int argc, char **argv, int embedded)
 {
@@ -787,6 +805,10 @@
             set_exec_path (optarg);
           break;
 
+        case FORCE_GUI_OPTION:
+          force_gui_option = true;
+          break;
+
         case IMAGE_PATH_OPTION:
           if (optarg)
             set_image_path (optarg);
@@ -810,6 +832,10 @@
           read_init_files = false;
           break;
 
+        case NO_GUI_OPTION:
+          no_gui_option = true;
+          break;
+
         case NO_INIT_PATH_OPTION:
           set_initial_path = false;
           break;
@@ -849,6 +875,12 @@
         }
     }
 
+  if (force_gui_option && no_gui_option)
+    {
+      error ("error: only one of --force-gui and --no-gui may be used");
+      usage ();
+    }
+
   // Make sure we clean up when we exit.  Also allow users to register
   // functions.  If we don't have atexit or on_exit, we're going to
   // leave some junk files around if we exit abnormally.
@@ -982,6 +1014,36 @@
   return 0;
 }
 
+// Return int instead of bool because this function is declared
+// extern "C".
+
+int
+octave_starting_gui (void)
+{
+  if (force_gui_option)
+    return true;
+
+  if (no_gui_option)
+    return false;
+
+  if (persist)
+    return true;
+
+  if (! (interactive || forced_interactive))
+    return false;
+
+  // If we have code to eval or execute from a file, and we are going to
+  // exit immediately after executing it, don't start the gui.
+
+  int last_arg_idx = optind;
+  int remaining_args = octave_cmdline_argc - last_arg_idx;
+
+  if (! code_to_eval.empty () || remaining_args > 0)
+    return false;
+
+  return true;
+}
+
 DEFUN (argv, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} argv ()\n\
--- a/src/octave.h
+++ b/src/octave.h
@@ -38,6 +38,8 @@
 extern OCTINTERP_API char **octave_cmdline_argv;
 extern OCTINTERP_API int octave_embedded;
 
+extern OCTINTERP_API int octave_starting_gui (void);
+
 #ifdef  __cplusplus
 }
 #endif