User forums > Using Code::Blocks
cbp2make - makefile generation tool
oBFusCATed:
So you'll rewrite depslib :lol:
Pecan:
Something like the following might help you get the dependencies that CB already sets up.
--- Code: ---//----------------------------------------------------------------------------
void <yourclassname>::WriteMakDependencies(wxFFile& makeFile_fp)
// ----------------------------------------------------------------------------
{
cbProject* prj = GetProjectManager()->GetActiveCBProject();
if (not prj) return;
wxFileName fn(GetProjectManager()->GetActiveCBProjectFilename());
fn.SetExt(_T("depend"));
wxString depsFilename = fn.GetFullPath();
wxArrayString depsarr;
wxString str;
// Get array containing lines like "filename;dependfile;dependfile;"
GetMakeDependencies( depsFilename, depsarr);
if (depsarr.GetCount() == 0)
return;
for (size_t knt=0; knt < depsarr.GetCount(); ++knt)
{
wxArrayString adepLine = wxStringTokenize(depsarr[knt], wxT(";"));
wxString shortFilename = adepLine[0].AfterLast(wxFILE_SEP_PATH);
wxString filenameBase = shortFilename.BeforeLast(_T('.'));
if ( not shortFilename.AfterLast(_T('.')).StartsWith(_T("c")) )
continue; //not a .cxx file
if (adepLine.GetCount() > 1) do
{ //source has dependencies
wxString depstr = wxEmptyString;
for (int j=1; j<(int)adepLine.GetCount(); ++j)
{ // append the dependecies;
adepLine[j].Replace(_T("<"),_T(""));
adepLine[j].Replace(_T(">"),_T(""));
depstr.Append( adepLine[j] + _T(" "));
}
str.Printf( _T("%s.o: %s\n"), filenameBase.c_str(), depstr.c_str() );
makeFile_fp.Write( CvtU2C(str), str.Length()); //name.o: dependent files
}while(0);
str.Printf( _T("%s.o: %s\n"), filenameBase.c_str(), shortFilename.c_str());
makeFile_fp.Write( CvtU2C(str), str.Length()); //name.o: cxx filename
str.Printf( _T("\t$(CC) -c $(CFLAGS) %s\n"), shortFilename.c_str() );
makeFile_fp.Write( CvtU2C(str), str.Length());
}
}//WriteMakDependencies
// ----------------------------------------------------------------------------
bool <yourclassname>::GetMakeDependencies(wxString& filepath, wxArrayString& depsarr )
// ----------------------------------------------------------------------------
{
// Read .depend file into a wxArrayString consisting of lines of
// sourcefilename;dependfilename;dependfilename;
// sourcefilename;
// sourcefilename;dependfilename; etc
if (not ::wxFileExists(filepath))
return false;
wxString str;
FILE *f;
char buf[1024];
//int vmajor, vminor;
wxString h;
int n;
time_t timeval;
depsarr.Clear();
wxFFile file(filepath, _T("r"));
if ( not file.IsOpened() )
return false;
f = file.fp();
/* Skip magic */
fgets(buf, sizeof(buf), f);
while (fgets(buf, sizeof (buf), f))
{
buf[strlen(buf) - 1] = '\0'; /* zap newline */
if (!buf[0])
continue;
if (buf[0] == '\t')
{
str.Append( CvtC2U(buf+1) +_T(";"));
continue;
}
sscanf(buf, "%ld %n", &timeval, &n);
if ( not str.empty())
{
depsarr.Add(str);
}
str = CvtC2U(buf+n) + _T(";");
}
// last buffer
if ( not str.empty())
{
depsarr.Add(str);
}
//fclose(f); file closed by wxFFile
return true;
}
--- End code ---
mirai:
--- Quote from: Pecan on March 26, 2011, 03:58:07 pm ---Something like the following might help you get the dependencies that CB already sets up.
--- End quote ---
I would need CB to make this work while one of major requirements is to avoid dependency from anything but .cbp/.workspace file.
p.s. Even just linking with CB SDK is not a solution, this would make me stuck with too large 3rd party code base.
stahta01:
--- Quote from: mirai on March 26, 2011, 05:46:15 pm ---
--- Quote from: Pecan on March 26, 2011, 03:58:07 pm ---Something like the following might help you get the dependencies that CB already sets up.
--- End quote ---
I would need CB to make this work while one of major requirements is to avoid dependency from anything but .cbp/.workspace file.
--- End quote ---
It looks to me that depslib does not depend on Code::Blocks.
Tim S.
mirai:
--- Quote from: stahta01 on March 26, 2011, 10:18:30 pm ---It looks to me that depslib does not depend on Code::Blocks.
--- End quote ---
I meant that example of WX/CB-based code posted by Pecan.
p.s. Actually I'm already somewhere in the middle of implementing dependency management and will release as soon as it is ready.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version