1 2(********************************************************************) 3(* *) 4(* make7.sd7 Make utility to manage the compilation process *) 5(* Copyright (C) 2010 - 2014 Thomas Mertes *) 6(* *) 7(* This program is free software; you can redistribute it and/or *) 8(* modify it under the terms of the GNU General Public License as *) 9(* published by the Free Software Foundation; either version 2 of *) 10(* the License, or (at your option) any later version. *) 11(* *) 12(* This program is distributed in the hope that it will be useful, *) 13(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15(* GNU General Public License for more details. *) 16(* *) 17(* You should have received a copy of the GNU General Public *) 18(* License along with this program; if not, write to the *) 19(* Free Software Foundation, Inc., 51 Franklin Street, *) 20(* Fifth Floor, Boston, MA 02110-1301, USA. *) 21(* *) 22(********************************************************************) 23 24 25$ include "seed7_05.s7i"; 26 include "make.s7i"; 27 28 29const type: optionHash is hash [string] string; 30 31const proc: main is func 32 local 33 var integer: number is 0; 34 var string: curr_arg is ""; 35 var optionHash: make_option is optionHash.value; 36 var string: makefile is ""; 37 var stringHash: macros is stringHash.value; 38 var integer: equalPos is 0; 39 var array string: targets is 0 times ""; 40 var makeFlags: flags is makeFlags.value; 41 var boolean: okay is TRUE; 42 begin 43 number := 1; 44 while number <= length(argv(PROGRAM)) do 45 curr_arg := argv(PROGRAM)[number]; 46 if length(curr_arg) >= 2 and curr_arg[1] = '-' then 47 if curr_arg = "-C" and number < length(argv(PROGRAM)) then 48 incr(number); 49 chdir(convDosPath(argv(PROGRAM)[number])); 50 elsif curr_arg = "-f" and number < length(argv(PROGRAM)) then 51 incr(number); 52 make_option @:= [curr_arg[.. 2]] argv(PROGRAM)[number]; 53 else 54 make_option @:= [curr_arg[.. 2]] curr_arg[3 ..]; 55 end if; 56 elsif pos(curr_arg, '=') <> 0 then 57 equalPos := pos(curr_arg, '='); 58 macros @:= [curr_arg[.. pred(equalPos)]] curr_arg[succ(equalPos) ..]; 59 else 60 targets &:= curr_arg; 61 end if; 62 incr(number); 63 end while; 64 if "-v" in make_option or "-h" in make_option or "-?" in make_option then 65 writeln("Make7 Version 1.0 - Make utility to manage the compilation process"); 66 writeln("Copyright (C) 2010 - 2014 Thomas Mertes"); 67 writeln("This is free software; see the source for copying conditions. There is NO"); 68 writeln("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); 69 writeln("Make7 is written in the Seed7 programming language"); 70 writeln("Homepage: http://seed7.sourceforge.net"); 71 writeln; 72 writeln("usage: make7 [options] [targets]"); 73 writeln; 74 writeln("Options:"); 75 writeln(" -C dir"); 76 writeln(" Change to dir before reading the makefile or doing anything else."); 77 writeln(" -f file"); 78 writeln(" Use file as a makefile."); 79 writeln(" -i"); 80 writeln(" Ignore all errors in commands executed."); 81 writeln(" -n"); 82 writeln(" Print the commands that would be executed, but do not execute them."); 83 writeln(" -s"); 84 writeln(" Silent operation. Do not print the commands as they are executed."); 85 writeln; 86 else 87 if "-f" in make_option then 88 makefile := convDosPath(make_option["-f"]); 89 elsif fileType("makefile") = FILE_REGULAR then 90 makefile := "makefile"; 91 elsif fileType("Makefile") = FILE_REGULAR then 92 makefile := "Makefile"; 93 else 94 okay := FALSE; 95 if length(targets) = 0 then 96 writeln(" *** Target missing and no makefile found."); 97 else 98 writeln(" *** No makefile found."); 99 end if; 100 writeln("Use make7 -? to get information about make7."); 101 end if; 102 if "-i" in make_option then 103 incl(flags, ignoreErrors); 104 end if; 105 if "-n" in make_option then 106 incl(flags, dontExecute); 107 end if; 108 if "-s" in make_option then 109 incl(flags, silentMode); 110 end if; 111 if okay then 112 block 113 make(makefile, targets, flags, macros); 114 exception 115 catch FILE_ERROR: 116 writeln(" *** Make7 terminated."); 117 end block; 118 end if; 119 end if; 120 end func; 121