Author Topic: How to automatically set compiler flag for non C/C++ files  (Read 3993 times)

druidbartek

  • Guest
How to automatically set compiler flag for non C/C++ files
« on: January 17, 2008, 04:35:26 am »
hi,

first of all, sorry for disturbing you but I couldn't find info what I'm lookin for.

Ok, I'm developing some patches for embedded systems(ARM7 based on). My project consist of *.gif/*.rtttl files as well as C source code too. System I'm developing requires to "compile" such files (precisely, to convert it to other format). IDE which I was using before, based on standard makefile so it was easy to do it.
Currently I'm using CB and have no idea how to do it :?

In Advanced options I set behaviour for gif/rtttl files, e.g.:
Code
Command: Compile single file to object file
Extension: rtttl
Macro:      rtttl2re $file -o $objects_output_dir/$file_name.re
Generated files:
and it works fine but only in case when I manually set the compiler flag(Properties...>>Build>>Compile file)

but it's real embarrassing to set this flag by hand for 100 files or more  :shock:

so my question is - how to do it automatically?

thanks in advance

regards,
bartek

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How to automatically set compiler flag for non C/C++ files
« Reply #1 on: January 17, 2008, 09:54:19 am »
There's no good way to do this. No builtin support for doing anything the like, and editing the project file by hand isn't good either.

Maybe... maybe... you could write a script that walks through all project files from beginning to end, and sets the compile option if the filename ends with "gif". This shouldn't take more than 5-6 lines of code, and it is probably better than changing 100 files by hand.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: How to automatically set compiler flag for non C/C++ files
« Reply #2 on: January 17, 2008, 11:34:23 am »
Yes, only possible through scripting currently. I know it's not optimal but, as you 'll see, it's pretty easy. Not to mention that you 'll learn something new ;).

Here:

Code
local project = GetProjectManager().GetActiveProject();
if (IsNull(project))
{
ShowError(_T("No active project!"));
return;
}

local count = project.GetFilesCount();
for (local i = 0; i < count; ++i)
{
local project_file = project.GetFile(i);
if (project_file.file.GetExt().Matches(_T("rtttl")))
project_file.compile = true;
}

project.SetModified(true);
GetProjectManager().RebuildTree();

Save it as "something.script". You can use it in one of two ways:

  • With your project already open, open this script file in the editor, right-click (the editor) and select "Run blah-blah.script"
  • Or, better, you can add it to the menus using Settings->Scripting (try something like "Project/Update RTTL files" as the "Register in menus" value).

Be patient!
This bug will be fixed soon...

druidbartek

  • Guest
Re: How to automatically set compiler flag for non C/C++ files
« Reply #3 on: January 17, 2008, 08:10:08 pm »
gee, thanks mate!

huh, I have ever supposed scripting is such powerful tool in CB  :shock:

I though scripts are basic alike and here we have syntax quite similar to C++ :!:

regards,
Bartek


oh, one more question - I want to modify your sample a little bit. How can I add checking compiler ID?
I found GetCompilerID  function but I'm not sure how to use it :?

Code
if (BLAHBLAHBLAH.GetCompilerID().Matches(_T("NokiX SDK")))
// do something...

and what should I put instead of BLAHBLAHBLAH... :(

yeah, I admit - object languages it's not my favourite ones - I prefer some low-level ones :D

« Last Edit: January 17, 2008, 08:55:48 pm by druidbartek »

mariocup

  • Guest
Re: How to automatically set compiler flag for non C/C++ files
« Reply #4 on: January 17, 2008, 10:23:31 pm »
Hi druidbartek,

a few examples for scripting are located in the CB installation directory:
\share\CodeBlocks\scripts

In the directory share\CodeBlocks\templates\wizard you will find some wizards script in directories avr, plugins and wxWidgets that show some powerful examples. You can even create own pages and describe the layout with a resource file a wizard.xrc (resource file). You can design the interface with wxSmith (part of CB plugins).

The wiki page http://wiki.codeblocks.org/index.php?title=Scripting_commands describes the script bindings, but to see more in detail the parameters you should better open the files scriptbindings.cpp, sc_io.cpp and wiz.cpp and look at the declaration of the functions (context menu in the editor).