changeset 18151:91a3858ef8cf stable

invoke versioned binaries from octave driver program (bug #40957) * main.in.cc (OCTAVE_VERSION): New macro. (main) Append OCTAVE_VERSION to exec file name. Always set new_argv[0] to full name of file that is executed. * Makefile.am (octave-cli-$(version), octave-gui-$(version), all-local): New rules. (OCTAVE_VERSION_LINKS): New variable. (CLEANFILES): Include $(OCTAVE_VERSION_LINKS) in the list.
author John W. Eaton <jwe@octave.org>
date Thu, 19 Dec 2013 15:24:28 -0500
parents bc1809fe55e4
children 20f2b3c48c4c
files src/Makefile.am src/main.in.cc
diffstat 2 files changed, 44 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Wed Dec 18 17:47:21 2013 +0000
+++ b/src/Makefile.am	Thu Dec 19 15:24:28 2013 -0500
@@ -49,8 +49,11 @@
   octave \
   octave-cli
 
+OCTAVE_VERSION_LINKS = octave-cli-$(version)
+
 if AMCOND_BUILD_GUI
   OCTAVE_BINARIES += octave-gui
+  OCTAVE_VERSION_LINKS += octave-gui-$(version)
 endif
 
 OCTAVE_CORE_LIBS = \
@@ -136,6 +139,8 @@
   octave-config
 endif
 
+all-local: $(OCTAVE_VERSION_LINKS)
+
 if AMCOND_BUILD_COMPILED_AUX_PROGRAMS
 octave-config.cc: octave-config.in.cc Makefile
 	@$(do_subst_default_vals)
@@ -189,5 +194,17 @@
 
 .PHONY: make-version-links remove-version-links
 
+## We need these file names in the build tree because the wrapper
+## program (main.cc) will try to invoke the versioned binaries.
+
+octave-cli-$(version): octave-cli
+	rm -f $@
+	$(LN_S) $< $@
+
+octave-gui-$(version): octave-gui
+	rm -f $@
+	$(LN_S) $< $@
+
 CLEANFILES = \
-  $(bin_SCRIPTS)
+  $(bin_SCRIPTS) \
+  $(OCTAVE_VERSION_LINKS)
--- a/src/main.in.cc	Wed Dec 18 17:47:21 2013 +0000
+++ b/src/main.in.cc	Thu Dec 19 15:24:28 2013 -0500
@@ -42,6 +42,18 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifndef OCTAVE_VERSION
+#define OCTAVE_VERSION %OCTAVE_VERSION%
+#endif
+
+#ifndef OCTAVE_BINDIR
+#define OCTAVE_BINDIR %OCTAVE_BINDIR%
+#endif
+
+#ifndef OCTAVE_PREFIX
+#define OCTAVE_PREFIX %OCTAVE_PREFIX%
+#endif
+
 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
 
 #define WIN32_LEAN_AND_MEAN
@@ -358,14 +370,6 @@
 
 #endif
 
-#ifndef OCTAVE_BINDIR
-#define OCTAVE_BINDIR %OCTAVE_BINDIR%
-#endif
-
-#ifndef OCTAVE_PREFIX
-#define OCTAVE_PREFIX %OCTAVE_PREFIX%
-#endif
-
 // Find the directory where the octave binary is supposed to be
 // installed.
 
@@ -590,16 +594,12 @@
 
   std::string octave_bindir = get_octave_bindir ();
 
-  std::string file = octave_bindir + dir_sep_char + "octave-cli";
+  std::string file
+    = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;;
 
   char **new_argv = new char * [argc + 1];
 
-#if defined (__WIN32__) && ! defined (__CYGWIN__)
   int k = 1;
-#else
-  int k = 0;
-  new_argv[k++] = strsave ("octave");
-#endif
 
   bool warn_display = true;
 
@@ -611,9 +611,9 @@
           gui_libs = true;
           file = octave_bindir + dir_sep_char;
           #if defined (HAVE_OCTAVE_GUI)
-            file += "octave-gui";
+            file += "octave-gui-" OCTAVE_VERSION;
           #else
-            file += "octave-cli";
+            file += "octave-cli-" OCTAVE_VERSION;
           #endif
           new_argv[k++] = argv[i];
         }
@@ -631,9 +631,9 @@
         {
           // If we see this option, then we can just exec octave; we
           // don't have to create a child process and wait for it to
-          // exit.  But do exec "octave", not "octave-cli", because even
-          // if the --no-gui option is given, we may be asked to do some
-          // plotting or ui* calls.
+          // exit.  But do exec "octave-gui", not "octave-cli", because
+          // even if the --no-gui option is given, we may be asked to do
+          // some plotting or ui* calls.
 
           // This option calls the cli executable for the 3.8 release.
         }
@@ -658,7 +658,7 @@
           start_gui = false;
           gui_libs = false;
 
-          file = octave_bindir + dir_sep_char + "octave-cli";
+          file = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
 
           if (warn_display)
             {
@@ -668,6 +668,12 @@
         }
     }
 
+#if defined (__WIN32__) && ! defined (__CYGWIN__)
+  file += ".exe";
+#endif
+
+  new_argv[0] = strsave (file.c_str ());
+
 #if (defined (HAVE_OCTAVE_GUI) \
      && ! defined (__WIN32__) || defined (__CYGWIN__))
 
@@ -733,10 +739,6 @@
 
 #else
 
-#if defined (__WIN32__) && ! defined (__CYGWIN__)
-  file += ".exe";
-  new_argv[0] = strsave (file.c_str ());
-#endif
   retval = octave_exec (file, new_argv);
 
 #endif