home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / compile.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.8 KB  |  191 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://www.loria.fr/SmallEiffel
  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 COMPILE -- The command.
  17.  
  18. inherit GLOBALS;
  19.    
  20. creation make
  21.    
  22. feature {NONE}
  23.  
  24.    root: STRING;
  25.      -- The root to compile.
  26.    
  27.    c_code: BOOLEAN;
  28.      -- True if C code must be saved.
  29.    
  30.    make_file: STD_FILE_READ is
  31.       once 
  32.      !!Result.make;
  33.       end;
  34.  
  35.    tmp_string: STRING is
  36.       once
  37.      !!Result.make(256);
  38.       end;
  39.    
  40. feature 
  41.    
  42.    make is
  43.       local
  44.      time_out: INTEGER;
  45.      str: STRING;
  46.       do
  47.      if argument_count < 1 then
  48.         echo.w_put_string("Bad use of command `compile'.%N");
  49.         more_help(fz_compile);
  50.         die_with_code(exit_failure_code);
  51.      end;
  52.      if windows_system = system_name then
  53.         tmp_string.clear;
  54.          else
  55.         tmp_string.copy(small_eiffel_directory);
  56.         add_directory(tmp_string,fz_bin);
  57.          end;
  58.      tmp_string.append(us_compile_to_c);
  59.      tmp_string.append(x_suffix);
  60.      automat;
  61.      if root = Void then
  62.         echo.w_put_string("Error : No <Root-Class> in command line.%N");
  63.         die_with_code(exit_failure_code);
  64.      end;
  65.      str := root.twin;
  66.      if dos_system = system_name then
  67.         from
  68.         until
  69.            str.count <= 4
  70.         loop
  71.            str.remove_last(1);
  72.         end;
  73.      end;
  74.      str.append(make_suffix);
  75.          echo.file_removing(str);
  76.      echo.call_system(tmp_string);
  77.          from
  78.             time_out := 2000;
  79.          until
  80.             time_out = 0 or else make_file.is_connected
  81.          loop
  82.             make_file.connect_to(str);
  83.             time_out := time_out - 1;
  84.          end;
  85.      if not make_file.is_connected then
  86.         echo.w_put_string(fz_01);
  87.         echo.w_put_string(str);
  88.         echo.w_put_string("%" not found. %
  89.                 %Error(s) during `compile_to_c'.%N");
  90.         die_with_code(exit_failure_code);
  91.      end;
  92.      echo.put_string("C compiling using %"");
  93.      echo.put_string(str);
  94.      echo.put_string("%" command file.%N");
  95.      from  
  96.         make_file.read_line;
  97.      until
  98.         make_file.last_string.count = 0 
  99.      loop
  100.         tmp_string.copy(make_file.last_string);
  101.         echo.call_system(tmp_string);
  102.         make_file.read_line;
  103.      end;
  104.      make_file.disconnect;
  105.      if c_code then
  106.         echo.put_string("C code not removed (-c_code).%N");
  107.      else
  108.         if windows_system = system_name then
  109.            tmp_string.clear;
  110.             else
  111.            tmp_string.copy(small_eiffel_directory);
  112.            add_directory(tmp_string,fz_bin);
  113.             end;
  114.         tmp_string.append(fz_clean);
  115.         tmp_string.append(x_suffix);
  116.         tmp_string.extend(' ');
  117.             if echo.verbose then
  118.            tmp_string.append("-verbose ");
  119.         end;
  120.         tmp_string.append(root);
  121.         echo.call_system(tmp_string);
  122.      end;
  123.      echo.put_string(fz_02);
  124.       end;
  125.    
  126. feature {NONE}
  127.    
  128.    automat is
  129.       local
  130.      state, arg: INTEGER;
  131.      a: STRING;
  132.      -- state 0  : nothing done.
  133.      -- state 1  : "-o"/"-cc"/"-cecil" read.
  134.      -- state 2  : Root class name read.
  135.       do
  136.      from  
  137.         arg := 1;
  138.      until
  139.         arg > argument_count
  140.      loop
  141.         a := argument(arg);
  142.         if ("-verbose").is_equal(a) then
  143.            echo.set_verbose;
  144.         end;
  145.         if ("-c_code").is_equal(a) then
  146.            c_code := true;
  147.         else
  148.            tmp_string.extend(' ');
  149.            tmp_string.append(a);
  150.            inspect 
  151.           state
  152.            when 0 then
  153.           if a.item(1) /= '-' then
  154.              if a.has_suffix(o_suffix) then
  155.              elseif a.has_suffix(c_suffix) then
  156.              elseif a.item(1) = '+' then
  157.              elseif root = Void then
  158.             root := to_bcn(a);
  159.             root.to_lower;
  160.             state := 2;
  161.              else
  162.              end;
  163.           elseif ("-o").is_equal(a) then
  164.              state := 1;
  165.           elseif a.item(1) = '-' and then a.item(2) = 'o' then
  166.           elseif ("-cc").is_equal(a) then
  167.              state := 1;
  168.           elseif ("-cecil").is_equal(a) then
  169.              state := 1;
  170.           else
  171.           end;
  172.            when 1 then
  173.           state := 0;
  174.            when 2 then
  175.           state := 0;
  176.            end;
  177.         end;
  178.         arg := arg + 1;
  179.      end;
  180.       end;
  181.    
  182. feature {NONE}
  183.  
  184.    tmp_file_write: STD_FILE_WRITE is
  185.       once
  186.      !!Result.make;
  187.       end;
  188.  
  189. end -- COMPILE -- The command.
  190.  
  191.