Subversion Repositories Kolibri OS

Rev

Rev 215 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ForReading = 1
  2. ForWriting = 2
  3. ForAppending = 8
  4. var fso = new ActiveXObject("Scripting.FileSystemObject");
  5. var wsh = new ActiveXObject("WScript.Shell");
  6. _DEBUG = true;
  7. function _debug(mes)
  8. {
  9.         if(_DEBUG != true) return mes;
  10.         try{var file = fso.OpenTextFile("debug_info.txt", ForAppending);}
  11.         catch(e){var file = fso.CreateTextFile("debug_info.txt", true);}
  12.         file.Write(mes);
  13.         file.close();
  14.         return mes;
  15. }
  16. function alert(mes){WScript.Echo(mes);return mes}
  17.  
  18. function debug(obj){for(key in obj)alert('['+key+']="'+obj[key]+'"')}
  19. function getFileContent(filename){
  20.         var file = fso.OpenTextFile(filename, ForReading);
  21.         var content = file.ReadAll();
  22.         file.close();
  23.         return content;
  24. }
  25. function include(filename){
  26.         eval(getFileContent(filename));
  27. }
  28. function Project(filename){
  29.         var text = getFileContent(filename);
  30.         eval("var config = {"+text+"};")
  31.         for(key in config) this[key] = config[key];
  32.         if(!this.files) this.files = [];
  33.         function getFileExt(name){
  34.                 var i = name.lastIndexOf(".");
  35.                 return (i==-1)? "" : name.substr(i);
  36.         }
  37.         this.getFileList = function(folder){
  38.                 var f = fso.GetFolder(folder);
  39.                 var fc = new Enumerator(f.SubFolders);
  40.                 for (; !fc.atEnd(); fc.moveNext())
  41.                 {
  42.                         var name = fc.item()+"";
  43.                         if(name[0]!='.' && !this.isIgnored(name))
  44.                                 this.getFileList(name);
  45.                 }
  46.                 delete fc;
  47.                 fc = new Enumerator(f.Files);
  48.                 for (; !fc.atEnd(); fc.moveNext())
  49.                 {
  50.                         var name = fc.item()+"";
  51.                         if(name[0]!='.' && !this.isIgnored(name))
  52.                                 this.files.push(name);
  53.                 }
  54.         }
  55.         this.clean = function(){
  56.                 var fl = new Enumerator(this.files);
  57.                 var fo;
  58.                 for (; !fl.atEnd(); fl.moveNext()){
  59.                         var file = fl.item()
  60.                         switch(getFileExt(file)){
  61.                         case ".o":
  62.                         case ".s":
  63.                                 fo = fso.GetFile(file);
  64.                                 fo.Delete();
  65.                                 break;
  66.                         }
  67.                 }
  68.                 delete fl;
  69.         }
  70.         var objList = [];
  71.         this.compile_asm = function(filename){
  72.                 var objname = filename.replace(/.\w{1,3}$/,".o");
  73.                 objList.push(objname);
  74.                 if(fso.FileExists(objname)) return;
  75.                 wsh.Run(_debug('"'+this.fasm+'" "'+filename+'" "'+objname+'"\n'),0,true);
  76.         }
  77.         this.compile_c = function(filename){
  78.                 var objname = filename.replace(/.\w{1,3}$/,".o");
  79.                 objList.push(objname);
  80.                 if(fso.FileExists(objname)) return;
  81.                 var asmname = filename.replace(/.\w{1,3}$/,".s");
  82.                 var command = "";
  83.                 if(!fso.FileExists(asmname)){
  84.                         command = '"'+this.gccpath +"\\"+ this.gccexe + "\" -nostdinc";
  85.                         if(this.include) command += " -I .\\include";
  86.                         command +=" -DGNUC" +' "'+filename + '" -o "' + asmname + '"\n';
  87.                         wsh.Run(_debug("cmd.exe /c "+command), 0, true);
  88.                 }
  89.                 command = '"'+this.gccpath +"\\"+ this.asexe +'" "'+ asmname +'" -o "'+ objname +'"\n';
  90.                 wsh.Run(_debug("cmd.exe /c "+command), 0, true);
  91.                 command = '"'+this.gccpath +"\\"+ this.objcopyexe +'" -O elf32-i386 --remove-leading-char "'+ objname +'"\n';
  92.                 wsh.Run(_debug("cmd.exe /c "+command), 0, true);
  93.         }
  94.         this.build = function(){
  95.                 var fl = new Enumerator(this.files);
  96.                 for (; !fl.atEnd(); fl.moveNext()){
  97.                         var file = fl.item()
  98.                         switch(getFileExt(file)){
  99.                                 case ".c": this.compile_c(file);break;
  100.                                 case ".asm": this.compile_asm(file);break;
  101.                                 case ".o": objList.push(file);break;
  102.                         }
  103.                 }
  104.                 delete fl;
  105.                 fl = new Enumerator(objList);
  106.                
  107. /*              var file = fso.CreateTextFile("OBJLIST.TXT", true);
  108.                 file.Write("CREATE "+this.dstpath+'\\'+this.name+".a\r\n");
  109.                 for (; !fl.atEnd(); fl.moveNext()){file.Write("ADDMOD "+fl.item()+"\r\n");}
  110.                 file.Write("SAVE\r\t");
  111.                 file.Close();
  112.                 wsh.Run(this.gccpath+"\\ar.exe -M < OBJLIST.TXT", 0, true);*/
  113.                
  114.                 var ar = wsh.Exec(_debug(this.gccpath+"\\ar.exe -M\n"))
  115.                 ar.StdIn.Write(_debug("CREATE "+this.dstpath+'\\'+this.name+".a\r\n"));
  116.                 for (; !fl.atEnd(); fl.moveNext()){ar.StdIn.Write(_debug("ADDMOD "+fl.item()+"\r\n"));}
  117.                 ar.StdIn.Write(_debug("SAVE\r\n"));
  118.         }
  119.         this.rebuild = function(){
  120.                 this.clean();
  121.                 this.build();
  122.         }
  123.         this.isIgnored = function(value){
  124.                 for(var i=0; i<this.ignored.length; i++)
  125.                         if (this.ignored[i]==value||this.ignored[i]==getFileExt(value)) return true;
  126.                 return false;
  127.         }
  128.         this.nothing = function(){alert("Hello")}
  129.         this.getFileList(this.srcpath);
  130. }
  131.  
  132. try{var confFile = WScript.Arguments(1);}catch(e){var confFile = "make.cfg";}
  133. try{var action = WScript.Arguments(0);}catch(e){var action = "build";}
  134.  
  135. var conf = new Project(confFile);
  136. conf[action]();
  137.  
  138. if(conf.autoclean && action != "clean"){conf["clean"]();}
  139. alert("Done");