⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compilerdlg.cpp

📁 用于开发Atmel的AVR系列单片机的GCC集成开发环境
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************
Project: WinAVRIDE        Class: Compiler Dialog
Copyright (C) 2005  Philipp Schober

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

History
19.Feb 2005 - First Release (V1.0)
****************************************************************************/

#include <vcl.h>
#pragma hdrstop

#include "CompilerDlg.h"
#include "OptionsDlg.h"
#include "DirDialog.h"
#include "ConRedirect.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TCompDlg *CompDlg;
//---------------------------------------------------------------------------
__fastcall TCompDlg::TCompDlg(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TCompDlg::OkButtonClick(TObject *Sender)
{
 ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TCompDlg::DoMake (TStringList *CList, TStringList *HList,
                                  AnsiString BasePath, int opt)
{
 int i;

 if (CList->Count == 0) return;
 for (i = 1;i < SizeGrid->RowCount;i++)
 {
  SizeGrid->Cells[0][i] = "";
  SizeGrid->Cells[1][i] = "";
  SizeGrid->Cells[2][i] = "";
 }
 SizeGrid->RowCount = 4;
 Position = poScreenCenter;
 doList = new TStringList;
 CFList = CList;
 HFList = HList;
 todo = opt;
 ProjectPath = BasePath;
 logfile = new TFileStream (IncludeTrailingBackslash (ProjectPath) + "build.log", fmCreate);
 ShowModal();
 delete logfile;
 delete doList;
}
//---------------------------------------------------------------------------
void __fastcall TCompDlg::DoCompile (AnsiString FileName)
{
 int i;

 for (i = 1;i < SizeGrid->RowCount;i++)
 {
  SizeGrid->Cells[0][i] = "";
  SizeGrid->Cells[1][i] = "";
  SizeGrid->Cells[2][i] = "";
 }
 SizeGrid->RowCount = 4;
 Position = poScreenCenter;
 doList = new TStringList;
 todo = DO_COMPILE;
 doList->Add (FileName);
 logfile = new TFileStream (IncludeTrailingBackslash (ProjectPath) + "build.log", fmCreate);
 ShowModal();
 delete logfile;
 delete doList;
}
//---------------------------------------------------------------------------

AnsiString __fastcall TCompDlg::ChangeExt (AnsiString Source, AnsiString ext)
{
 AnsiString obj;

 obj = Source;
 obj.Delete (obj.Pos (ExtractFileExt (obj)), 3);
 obj += ext;
 return obj;
}
//---------------------------------------------------------------------------
int __fastcall TCompDlg::CompareFileDates (AnsiString f1, AnsiString f2)
{
 FILETIME ft1, ft2;
 HANDLE filehandle;
 long r;

 filehandle = CreateFile (f1.c_str(), GENERIC_READ, 0, NULL,
                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 if (filehandle == INVALID_HANDLE_VALUE) return 0;
 GetFileTime (filehandle, NULL, NULL, &ft1);
 CloseHandle (filehandle);
 filehandle = CreateFile (f2.c_str(), GENERIC_READ, 0, NULL,
                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 if (filehandle == INVALID_HANDLE_VALUE) return 0;
 GetFileTime (filehandle, NULL, NULL, &ft2);
 CloseHandle (filehandle);
 r = CompareFileTime (&ft1, &ft2);
 if (r == -1) return (1); // First File is older
 if (r == 0) return (2); // Same File Data and Time
 return (3); // Second File is older
}
//---------------------------------------------------------------------------
bool __fastcall TCompDlg::Compile (void)
{
 AnsiString CompOptions, filedir, compiler;
 int i;

 compiler = DirDlg->Bin_Dir + "avr-gcc.exe";
 if (!FileExists (compiler))
 {
  Application->MessageBox ("Can't find avr-gcc.exe", "Error", MB_OK |MB_ICONERROR);
  return false;
 }
 for (i = 0;i < doList->Count;i++)
 {
  child_exitcode = 0;
  Action->Caption = "Compiling: " + ExtractFileName (doList->Strings[i]);
  Application->ProcessMessages ();
  filedir = ExtractFileDir (doList->Strings[i]);
  // ------------------- Generate Object File --------------------
  CompOptions = OptDlg->GetCompilerOptions (doList->Strings[i], OUTP_OBJ);
  con->RunChild (NULL, CompOptions.c_str (), filedir.c_str ());
  CompOptions += "\r\n";
  logfile->Write (CompOptions.c_str (), CompOptions.Length ());
  while (con->isChildRunning ())
  {
   Application->ProcessMessages ();
  }
  if (child_exitcode != 0) return false;
  // ------------- Generate Assembler Output ---------------------
  if (OptDlg->options.SaveTempBox)
  {
   CompOptions = OptDlg->GetCompilerOptions (doList->Strings[i], OUTP_ASM);
   con->RunChild (NULL, CompOptions.c_str (), filedir.c_str ());
   CompOptions += "\r\n";
   logfile->Write (CompOptions.c_str (), CompOptions.Length ());
   while (con->isChildRunning ())
   {
    Application->ProcessMessages ();
   }
   if (child_exitcode != 0) return false;
  }
 }
 return true;
}
//---------------------------------------------------------------------------
bool __fastcall TCompDlg::Linker (void)
{
 AnsiString linker, output, temp, workdir;
 int i;

 linker = DirDlg->Bin_Dir + "avr-gcc.exe";
 if (!FileExists (linker))
 {
  Application->MessageBox ("Can't find avr-gcc.exe", "Error", MB_OK |MB_ICONERROR);
  return false;
 }
 output = "\"" + OptDlg->OutputName + ".elf\"";
 workdir = ExtractFileDir (OptDlg->OutputName);
 temp = OptDlg->GetLinkerOptions (doList);
 child_exitcode = 0;
 Action->Caption = "Linking: " + ExtractFileName (output);
 con->RunChild (NULL, temp.c_str (), workdir.c_str ());
 temp += "\r\n";
 logfile->Write (temp.c_str (), temp.Length ());
 while (con->isChildRunning ())
 {
  Application->ProcessMessages ();
 }
 if (child_exitcode != 0) return false;

 linker = DirDlg->Bin_Dir + "avr-size.exe";
 temp = linker + " -A " + output;
 SizeOutput = "";
 con->OnStdOut = StdOutToList;
 con->RunChild (NULL, temp.c_str (), DirDlg->Bin_Dir.c_str ());
 temp += "\r\n";
 logfile->Write (temp.c_str (), temp.Length ());
 while (con->isChildRunning ())
 {
  Application->ProcessMessages ();
 }
 SizeList = new TStringList;
 SizeList->Clear ();
 SizeList->Text = SizeOutput;
 SizeToGrid ();
 con->OnStdOut = 0;
 return true;
}
//---------------------------------------------------------------------------
void __fastcall TCompDlg::Convert (void)
{
 AnsiString output, temp, objcopy;

 objcopy = DirDlg->Bin_Dir + "avr-objcopy.exe";
 if (!FileExists (objcopy))
 {
  Application->MessageBox ("Can't find avr-gcc.exe", "Error", MB_OK |MB_ICONERROR);
  return;
 }
 // ---------------- Generating Hex/Bin File ----------------------
 child_exitcode = 0;
 temp = OptDlg->GetObjcopyOptions (&output, 0);
 Action->Caption = "Generating: " + ExtractFileName (output);
 con->RunChild (objcopy.c_str (), temp.c_str (), DirDlg->Bin_Dir.c_str ());
 temp = objcopy + temp + "\r\n";
 logfile->Write (temp.c_str (), temp.Length ());
 while (con->isChildRunning ())
 {
  Application->ProcessMessages ();
 }
 // ------------------ Generating (Ext.)Coff File ----------------
 if (OptDlg->options.DbgGroup == 2 || OptDlg->options.DbgGroup == 3)
 {
  child_exitcode = 0;
  temp = OptDlg->GetObjcopyOptions (&output, 1);
  Action->Caption = "Generating: " + ExtractFileName (output);
  con->RunChild (objcopy.c_str (), temp.c_str (), DirDlg->Bin_Dir.c_str ());
  temp = objcopy + temp + "\r\n";
  logfile->Write (temp.c_str (), temp.Length ());
  while (con->isChildRunning ())
  {
   Application->ProcessMessages ();
  }
 }
 // -------------------- Generating EEPROM File ------------------
 if (OptDlg->options.GenEEPROM)
 {
  child_exitcode = 0;
  temp = OptDlg->GetObjcopyOptions (&output, 2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -