comparison src/main.in.cc @ 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 0c4a2e95c768
children d13fb462dd92 65e4e0569ed4
comparison
equal deleted inserted replaced
18148:bc1809fe55e4 18151:91a3858ef8cf
40 #include <string> 40 #include <string>
41 41
42 #include <sys/types.h> 42 #include <sys/types.h>
43 #include <unistd.h> 43 #include <unistd.h>
44 44
45 #ifndef OCTAVE_VERSION
46 #define OCTAVE_VERSION %OCTAVE_VERSION%
47 #endif
48
49 #ifndef OCTAVE_BINDIR
50 #define OCTAVE_BINDIR %OCTAVE_BINDIR%
51 #endif
52
53 #ifndef OCTAVE_PREFIX
54 #define OCTAVE_PREFIX %OCTAVE_PREFIX%
55 #endif
56
45 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) 57 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
46 58
47 #define WIN32_LEAN_AND_MEAN 59 #define WIN32_LEAN_AND_MEAN
48 #include <tlhelp32.h> 60 #include <tlhelp32.h>
49 61
354 } 366 }
355 367
356 return retval; 368 return retval;
357 } 369 }
358 370
359 #endif
360
361 #ifndef OCTAVE_BINDIR
362 #define OCTAVE_BINDIR %OCTAVE_BINDIR%
363 #endif
364
365 #ifndef OCTAVE_PREFIX
366 #define OCTAVE_PREFIX %OCTAVE_PREFIX%
367 #endif 371 #endif
368 372
369 // Find the directory where the octave binary is supposed to be 373 // Find the directory where the octave binary is supposed to be
370 // installed. 374 // installed.
371 375
588 bool start_gui = false; 592 bool start_gui = false;
589 bool gui_libs = false; 593 bool gui_libs = false;
590 594
591 std::string octave_bindir = get_octave_bindir (); 595 std::string octave_bindir = get_octave_bindir ();
592 596
593 std::string file = octave_bindir + dir_sep_char + "octave-cli"; 597 std::string file
598 = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;;
594 599
595 char **new_argv = new char * [argc + 1]; 600 char **new_argv = new char * [argc + 1];
596 601
597 #if defined (__WIN32__) && ! defined (__CYGWIN__)
598 int k = 1; 602 int k = 1;
599 #else
600 int k = 0;
601 new_argv[k++] = strsave ("octave");
602 #endif
603 603
604 bool warn_display = true; 604 bool warn_display = true;
605 605
606 for (int i = 1; i < argc; i++) 606 for (int i = 1; i < argc; i++)
607 { 607 {
609 { 609 {
610 start_gui = true; 610 start_gui = true;
611 gui_libs = true; 611 gui_libs = true;
612 file = octave_bindir + dir_sep_char; 612 file = octave_bindir + dir_sep_char;
613 #if defined (HAVE_OCTAVE_GUI) 613 #if defined (HAVE_OCTAVE_GUI)
614 file += "octave-gui"; 614 file += "octave-gui-" OCTAVE_VERSION;
615 #else 615 #else
616 file += "octave-cli"; 616 file += "octave-cli-" OCTAVE_VERSION;
617 #endif 617 #endif
618 new_argv[k++] = argv[i]; 618 new_argv[k++] = argv[i];
619 } 619 }
620 else if (! strcmp (argv[i], "--no-gui-libs")) 620 else if (! strcmp (argv[i], "--no-gui-libs"))
621 { 621 {
629 } 629 }
630 else if (! strcmp (argv[i], "--no-gui")) 630 else if (! strcmp (argv[i], "--no-gui"))
631 { 631 {
632 // If we see this option, then we can just exec octave; we 632 // If we see this option, then we can just exec octave; we
633 // don't have to create a child process and wait for it to 633 // don't have to create a child process and wait for it to
634 // exit. But do exec "octave", not "octave-cli", because even 634 // exit. But do exec "octave-gui", not "octave-cli", because
635 // if the --no-gui option is given, we may be asked to do some 635 // even if the --no-gui option is given, we may be asked to do
636 // plotting or ui* calls. 636 // some plotting or ui* calls.
637 637
638 // This option calls the cli executable for the 3.8 release. 638 // This option calls the cli executable for the 3.8 release.
639 } 639 }
640 else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "-q") 640 else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "-q")
641 || ! strcmp (argv[i], "--quiet")) 641 || ! strcmp (argv[i], "--quiet"))
656 if (! display_available (display_check_err_msg)) 656 if (! display_available (display_check_err_msg))
657 { 657 {
658 start_gui = false; 658 start_gui = false;
659 gui_libs = false; 659 gui_libs = false;
660 660
661 file = octave_bindir + dir_sep_char + "octave-cli"; 661 file = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
662 662
663 if (warn_display) 663 if (warn_display)
664 { 664 {
665 std::cerr << "octave: " << display_check_err_msg << std::endl; 665 std::cerr << "octave: " << display_check_err_msg << std::endl;
666 std::cerr << "octave: disabling GUI features" << std::endl; 666 std::cerr << "octave: disabling GUI features" << std::endl;
667 } 667 }
668 } 668 }
669 } 669 }
670
671 #if defined (__WIN32__) && ! defined (__CYGWIN__)
672 file += ".exe";
673 #endif
674
675 new_argv[0] = strsave (file.c_str ());
670 676
671 #if (defined (HAVE_OCTAVE_GUI) \ 677 #if (defined (HAVE_OCTAVE_GUI) \
672 && ! defined (__WIN32__) || defined (__CYGWIN__)) 678 && ! defined (__WIN32__) || defined (__CYGWIN__))
673 679
674 if (gui_libs && start_gui && have_controlling_terminal ()) 680 if (gui_libs && start_gui && have_controlling_terminal ())
731 else 737 else
732 retval = octave_exec (file, new_argv); 738 retval = octave_exec (file, new_argv);
733 739
734 #else 740 #else
735 741
736 #if defined (__WIN32__) && ! defined (__CYGWIN__)
737 file += ".exe";
738 new_argv[0] = strsave (file.c_str ());
739 #endif
740 retval = octave_exec (file, new_argv); 742 retval = octave_exec (file, new_argv);
741 743
742 #endif 744 #endif
743 745
744 return retval; 746 return retval;