home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / install.e < prev    next >
Text File  |  1999-06-05  |  15KB  |  459 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class INSTALL
  17.    --
  18.    -- The `install' command may be used to INSTALL SmallEiffel on all platforms.
  19.    --
  20.  
  21. inherit COMMAND_FLAGS;
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    command_name: STRING is "install";
  28.  
  29.    make is
  30.       local
  31.          argc: INTEGER;
  32.          arg: STRING;
  33.       do
  34.          echo.set_verbose;
  35.          argc := argument_count;
  36.          if argc = 0 then
  37.          elseif argc = 2 then
  38.             if ("-skip").is_equal(argument(1)) then
  39.                arg := argument(2);
  40.                if arg.is_integer then
  41.                   skip_step := arg.to_integer;
  42.                else
  43.                   echo_usage_exit;
  44.                end;
  45.             else
  46.                echo_usage_exit;
  47.             end;
  48.          else
  49.             echo_usage_exit;
  50.          end;
  51.          !!st.install;
  52.          echo.put_string("SmallEiffel install program started.%N");
  53.          if is_flag_version("-version") then end;
  54.          --
  55.          force_step("Checking %"SmallEiffel%" environment variable");
  56.          environment_variable;
  57.          finish_step;
  58.          --
  59.          if start_step("System name detection") then
  60.             system_name_detection;
  61.             finish_step;
  62.          end;
  63.          st.make;
  64.          system_name := st.system_name;
  65.          --
  66.          force_step("Writing default loadpath.se file");
  67.          default_loadpath;
  68.          finish_step;
  69.          --
  70.          if start_step("C compiler selection") then
  71.             c_compiler_selection;
  72.             finish_step;
  73.          end;
  74.          --
  75.          if start_step("Garbage collector selection") then
  76.             garbage_collector_selection;
  77.             finish_step;
  78.          end;
  79.          --
  80.          ch_dir_to("bin_c");
  81.          --
  82.          if start_step("Prepare `compile' command") then
  83.             prepare_no_split("compile.c");
  84.             finish_step;
  85.          end;
  86.          --
  87.          echo.put_string("--%NSmallEiffel install done (congratulations).%N");
  88.       end;
  89.  
  90.    environment_variable is
  91.       local
  92.          var: STRING;
  93.       do
  94.          system_se_path := get_environment_variable(fz_se);
  95.          if system_se_path = Void or else system_se_path.count = 0 then
  96.             var := fz_se.twin;
  97.             var.to_upper;
  98.             system_se_path := get_environment_variable(var);
  99.          end;
  100.          if system_se_path = Void or else system_se_path.count = 0 then
  101.             fatal_problem_description_start;
  102.             echo.put_string(
  103.             "Environment variable %"SmallEiffel%" is not set.%N%
  104.             %Please, set this variable with the absolute path of %N%
  105.             %the %"SmallEiffel/sys/system.se%" file.%N%
  106.             %A file %"system.se%" must exists in the sub-directory %"sys%"%
  107.             % of the%NSmallEiffel directory.%N");
  108.             fatal_problem_description_end;
  109.          end;
  110.          if not system_se_path.has_suffix("system.se") then
  111.             fatal_problem_description_start;
  112.             echo.put_string(
  113.             "Value of the Environment variable %"SmallEiffel%" value%Nis %"");
  114.             echo.put_string(system_se_path);
  115.             echo.put_string("%".%N");
  116.             echo.put_string(
  117.             "Please, set this variable with the absolute path of%N%
  118.             %the %"SmallEiffel/sys/system.se%" file.%N%
  119.             %For example, on Linux, the value is%N%
  120.             %often %"/usr/lib/SmallEiffel/sys/system.se%".%N%
  121.             %On Windows, %"C:\SmallEiffel\sys\system.se%" is a correct value%N%
  122.             %when the SmallEiffel directory is at toplevel of the C hard %
  123.             %disk.%N");
  124.             fatal_problem_description_end;
  125.          end;
  126.          if not file_exists(system_se_path) then
  127.             fatal_problem_description_start;
  128.             echo.put_string(
  129.             "Value of the Environment variable %"SmallEiffel%" value%Nis %"");
  130.             echo.put_string(system_se_path);
  131.             echo.put_string(
  132.             "%".%N%
  133.             %There is no readable file %"");
  134.             echo.put_string(system_se_path);
  135.             echo.put_string(
  136.             "%".%N%
  137.             %Check this absolute path as well as read permission.%N");
  138.             fatal_problem_description_end;
  139.          end;
  140.       end;
  141.  
  142.    system_name_detection is
  143.       local
  144.          sfw: STD_FILE_WRITE;
  145.       do
  146.          if file_exists("s:startup-sequence") then
  147.             -- This check has to be performed BEFORE the Unix check
  148.             -- ("/bin/ls"), because the latter might be true if the user
  149.             -- installed GeekGadgets and one of those perverted patches
  150.             -- to handle Unix-style paths !
  151.             echo.put_string("System seems to be an Amiga.%N");
  152.             system_name := "Amiga";
  153.          elseif file_exists("/bin/ls") then
  154.             echo.put_string("System seems to be UNIX.%N");
  155.             system_name := "UNIX";
  156.          else
  157.             system_name := choice_in("System name selection",st.system_list);
  158.          end;
  159.          echo.put_string("System is %"");
  160.          echo.put_string(system_name);
  161.          echo.put_string("%".%NTry to update %"");
  162.          echo.put_string(system_se_path);
  163.          echo.put_string("%".%N");
  164.          !!sfw.connect_to(system_se_path);
  165.          if not sfw.is_connected then
  166.             fatal_problem_description_start;
  167.             echo.put_string("Cannot write file %"");
  168.             echo.put_string(system_se_path);
  169.             echo.put_string("%".%NCheck write permissions.");
  170.             fatal_problem_description_end;
  171.          end;
  172.          sfw.put_string(system_name);
  173.          sfw.put_character('%N');
  174.          sfw.disconnect;
  175.          echo.put_string("Update of %"");
  176.          echo.put_string(system_se_path);
  177.          echo.put_string("%" done.%N");
  178.       end;
  179.  
  180.    default_loadpath is
  181.       local
  182.          path, directory: STRING;
  183.          list: ARRAY[STRING];
  184.          sfw: STD_FILE_WRITE;
  185.          i: INTEGER;
  186.       do
  187.          path := system_se_path.twin;
  188.          path.remove_suffix("system.se");
  189.          path.append("loadpath.");
  190.          path.append(system_name);
  191.          echo.put_string("Try to update %"");
  192.          echo.put_string(path);
  193.          echo.put_string("%".%N");
  194.          !!sfw.connect_to(path);
  195.          if not sfw.is_connected then
  196.             fatal_problem_description_start;
  197.             echo.put_string("Cannot write file %"");
  198.             echo.put_string(path);
  199.             echo.put_string("%".%NCheck write permissions.");
  200.             fatal_problem_description_end;
  201.          end;
  202.          -- Current directory :
  203.          if ("UNIX").is_equal(system_name) then
  204.             sfw.put_string("./%N");
  205.          elseif ("DOS").is_equal(system_name) then
  206.             sfw.put_string(".\%N");
  207.          elseif ("Windows").is_equal(system_name) then
  208.             sfw.put_string(".\%N");
  209.          elseif ("BeOS").is_equal(system_name) then
  210.             sfw.put_string("./%N");
  211.          elseif ("Macintosh").is_equal(system_name) then
  212.             sfw.put_string(":%N");
  213.          elseif ("VMS").is_equal(system_name) then
  214.             -- Don't know (mail the good one to colnet@loria.fr)
  215.          elseif ("OS2").is_equal(system_name) then
  216.             -- Don't know (mail the good one to colnet@loria.fr)
  217.          elseif ("Amiga").is_equal(system_name) then
  218.             sfw.put_string("%N");
  219.          end;
  220.          list := <<"lib_std", "lib_rand", "lib_show", "lib_se">>;
  221.          from
  222.             i := 1;
  223.          until
  224.             i > list.upper
  225.          loop
  226.             directory := system_se_path.twin;
  227.             directory.remove_suffix("system.se");
  228.             st.parent_directory(directory);
  229.             st.add_directory(directory,list.item(i));
  230.             sfw.put_string(directory);
  231.             if i < list.upper then
  232.                sfw.put_character('%N');
  233.             end;
  234.             i := i + 1;
  235.          end;
  236.          sfw.disconnect;
  237.          echo.put_string("Update of %"");
  238.          echo.put_string(path);
  239.          echo.put_string("%" done.%N");
  240.       end;
  241.  
  242.    c_compiler_selection is
  243.       local
  244.          path, name: STRING;
  245.          sfw: STD_FILE_WRITE;
  246.       do
  247.          name := choice_in("C compiler selection",st.compiler_list);
  248.          echo.put_string("Selected C compiler is %"");
  249.          echo.put_string(name);
  250.          echo.put_string("%".%N");
  251.          path := system_se_path.twin;
  252.          path.remove_suffix("system.se");
  253.          path.append("compiler.se");
  254.          echo.put_string("Try to update %"");
  255.          echo.put_string(path);
  256.          echo.put_string("%".%N");
  257.          !!sfw.connect_to(path);
  258.          if not sfw.is_connected then
  259.             fatal_problem_description_start;
  260.             echo.put_string("Cannot write file %"");
  261.             echo.put_string(path);
  262.             echo.put_string("%".%NCheck write permissions.");
  263.             fatal_problem_description_end;
  264.          end;
  265.          sfw.put_string(name);
  266.          std_input.last_string.clear;
  267.          echo.put_string(
  268.          "If you want to add some defaults C-compiler/Linker options,%N%
  269.          %type your options using one single line.%N%
  270.          %If you don't know, type <CR> only.%N%
  271.          %options ? ");
  272.          std_input.read_line;
  273.          if std_input.last_string.count > 0 then
  274.             if std_input.last_string.item(1) /= ' ' then
  275.                sfw.put_character(' ');
  276.             end;
  277.             sfw.put_string(std_input.last_string);
  278.          end;
  279.          sfw.put_character('%N');
  280.          sfw.disconnect;
  281.          echo.put_string("Update of %"");
  282.          echo.put_string(path);
  283.          echo.put_string("%" done.%N");
  284.       end;
  285.  
  286.    garbage_collector_selection is
  287.       local
  288.          cmd: STRING;
  289.       do
  290.          if system_name.is_equal("UNIX") then
  291.             cmd := system_se_path.twin;
  292.             cmd.remove_suffix("sys/system.se");
  293.             cmd.append("misc/GC.SH");
  294.             echo.put_string("Launching script %"");
  295.             echo.put_string(cmd);
  296.             echo.put_string("%".%N");
  297.             system(cmd);
  298.          elseif system_name.is_equal("Amiga") then
  299.             cmd := "echo m68k-amigaos.c >%"";
  300.             cmd.append(system_se_path.twin);
  301.             cmd.remove_suffix("sys/system.se");
  302.             cmd.append("sys/gc%"");
  303.             system(cmd);
  304.          elseif system_name.is_equal("Windows") then
  305.          elseif system_name.is_equal("BeOS") then
  306.  
  307.          end;
  308.       end;
  309.  
  310.    prepare_no_split(c_file: STRING) is
  311.       local
  312.          cmd: STRING;
  313.       do
  314.          !!cmd.make(128);
  315.          st.no_split_mode_command(cmd,c_file);
  316.          echo.put_string("<<");
  317.          echo.put_string(cmd);
  318.          echo.put_string(">>");
  319.  
  320.       end;
  321.  
  322.    ch_dir_to(dest: STRING) is
  323.       local
  324.          path: STRING;
  325.          p: POINTER;
  326.       do
  327.          path := system_se_path.twin;
  328.          path.remove_suffix("system.se");
  329.          st.parent_directory(path);
  330.          st.add_directory(path,dest);
  331.          p := path.to_external;
  332.          echo.put_string("Try to change directory to %"");
  333.          echo.put_string(path);
  334.          echo.put_string("%".%N");
  335.          c_inline_c("chdir(_p);%N");
  336.       end;
  337.  
  338.    system_se_path: STRING;
  339.  
  340.    step_number: INTEGER;
  341.  
  342.    step_name: STRING;
  343.  
  344.    skip_step: INTEGER;
  345.  
  346.    start_step(sn: STRING): BOOLEAN is
  347.       do
  348.          step_number := step_number + 1;
  349.          step_name := sn;
  350.          if skip_step < step_number then
  351.             Result := true;
  352.             echo.put_string("--%NStep #");
  353.             echo.put_integer(step_number);
  354.             echo.put_string(": ");
  355.             echo.put_string(sn);
  356.             echo.put_string(".%N");
  357.          else
  358.             echo.put_string("--%NSkipping step #");
  359.             echo.put_integer(step_number);
  360.             echo.put_string(": ");
  361.             echo.put_string(sn);
  362.             echo.put_string(".%N");
  363.          end;
  364.       end;
  365.  
  366.    finish_step is
  367.       do
  368.          echo.put_string("Done : (Step #");
  369.          echo.put_integer(step_number);
  370.          echo.put_string(": ");
  371.          echo.put_string(step_name);
  372.          echo.put_string(").%N");
  373.       end;
  374.  
  375.    force_step(sn: STRING) is
  376.       local
  377.          save: INTEGER;
  378.       do
  379.          save := skip_step;
  380.          skip_step := 0;
  381.          if start_step(sn) then end;
  382.          skip_step := save;
  383.       end;
  384.  
  385.    fatal_problem_description_start is
  386.       do
  387.          echo.put_string(
  388.          "*** Fatal problem during installation of SmallEiffel.%N%
  389.          %    Read carefully the following information before starting%N%
  390.          %    again the `install' command.%N%
  391.          %******************************************************************%N");
  392.       end;
  393.  
  394.    fatal_problem_description_end is
  395.       do
  396.          echo.put_string(
  397.          "******************************************************************%N%
  398.          %Fix the previously described problem and launch again `install'.%N");
  399.          die_with_code(exit_failure_code);
  400.       end;
  401.  
  402.    choice_in(title: STRING; names: ARRAY[STRING]): STRING is
  403.       local
  404.          i: INTEGER;
  405.          w: STRING;
  406.       do
  407.          from
  408.          until
  409.             Result /= Void
  410.          loop
  411.             echo.put_string(title);
  412.             echo.put_string(" :%N  ");
  413.             from
  414.                i := 1;
  415.             until
  416.                i > names.upper
  417.             loop
  418.                echo.put_string(names.item(i));
  419.                i := i + 1;
  420.                if i <= names.upper then
  421.                   echo.put_string(", ");
  422.                end;
  423.             end;
  424.             echo.put_string("%N? ");
  425.             std_input.read_word;
  426.             from
  427.                i := names.upper;
  428.                w := std_input.last_string.twin;
  429.             until
  430.                i = 0 or else Result /= Void
  431.             loop
  432.                if w.same_as(names.item(i)) then
  433.                   Result := names.item(i);
  434.                end;
  435.                i := i - 1;
  436.             end;
  437.             if Result = Void then
  438.                echo.put_string("%"");
  439.                echo.put_string(w);
  440.                echo.put_string("%" is not a valid choice.%N");
  441.             end;
  442.          end;
  443.       end;
  444.  
  445.    echo_usage_exit is
  446.       do
  447.          echo.put_string("usage : ");
  448.          echo.put_string(command_name);
  449.          echo.put_string(" [-skip <step_number>]%N");
  450.          die_with_code(exit_failure_code);
  451.       end;
  452.  
  453.    system_name: STRING;
  454.  
  455.    st: SYSTEM_TOOLS;
  456.  
  457. end -- INSTALL
  458.  
  459.