Using CodeLite in cross-compiling context

General questions regarding the usage of CodeLite
SiZiOUS
CodeLite Curious
Posts: 6
Joined: Mon Mar 02, 2015 10:42 pm
Genuine User: Yes
IDE Question: C++
Contact:

Using CodeLite in cross-compiling context

Post by SiZiOUS »

Hi there,

First of all, thanks for this very high quality multi-platform IDE. :)

I want to use CodeLite to do some programming in cross-compile mode and really I don't know where to start.
Please note that I have everything to make cross-compiling so my questions are really about the CodeLite usage.
I'm developing under Windows (7 x64 if it's does matter).

The context is:
  • The cross-compiler I use need to be used under the MinGW/MSYS environment (I can't use it directly in 'normal' cmd shell). It's a 'normal' toolchain based on GNU tools (GCC/GDB...). I already have written the batch file (for the 'cmd' shell) to run in order to call the 'make' executable directly in the MSYS environment.
  • The cross-compiler itself is for the target 'sh-elf' AND 'arm-eabi' (because it's an architecture with 2 chips, but the SH remains the 'main' chip).
  • Executables produced are made by hand-written Makefiles (that use some preconfigured rules by the way, that's why it needs to be run from MSYS shell).
  • When I run the program, I need to launch a 'loader' executable by passing some parameters including the project output (it's an ELF file)
  • When I debug the program, the previous point remains true but a new switch need to be passed in order to start the GDBserver on target (remote debugging).
I have a 'dream' and it consists of writing a CodeLite plugin in order to make all these steps automatically :
  • Writing the makefile (by using some template I own)
  • Executing the 'loader' instead of loading the ELF file
  • When debugging, starting the 'loader' with the according parameters, then starting gdb in the same time and do remote debugging..
I have several skills in differents languages, but I need some help to learn where to start about writing a CodeLite plugin. I didn't find what I was looking for in the doc.
Maybe someone can show me the right place to start ? or maybe there's plugins around made for doing some cross-compilation (I saw there's a lot of questions about ARM SDKs...).

Thank in advance ! :)

Best regards,
Mike
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by eranif »

First, make sure that you are running the latest weekly build from here: http://downloads.codelite.org/
It contains various bug fixes, some are related to your case.
The cross-compiler I use need to be used under the MinGW/MSYS environment (I can't use it directly in 'normal' cmd shell). It's a 'normal' toolchain based on GNU tools (GCC/GDB...). I already have written the batch file (for the 'cmd' shell) to run in order to call the 'make' executable directly in the MSYS environment.
The best way to tell codelite that you are using MinGW/MSYS is to execute CodeLite from within the MSYS shell iteself. (something like: /c/codelite-dir/codelite.exe &)
Executables produced are made by hand-written Makefiles (that use some preconfigured rules by the way, that's why it needs to be run from MSYS shell).
If you want to use your own makefiles, you should enable the "custom build" option in codelite which basically allows you to run whatever you want.
http://codelite.org/LiteEditor/CustomMakefiles#toc3

http://codelite.org/Developers/CreatePlugin

Eran
Make sure you have read the HOW TO POST thread
SiZiOUS
CodeLite Curious
Posts: 6
Joined: Mon Mar 02, 2015 10:42 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by SiZiOUS »

Thank you very much for your fast answer Eran.

I'm really thinking of creating a new CodeLite plugin in order to make all these steps automatically. The thing is, I don't know if the wizard generate an 'empty' plugin or it contains some code sample for ex, overriding the makefile generation ?

Another thing is when you hit run or debug command, can I intercept the signal in order to upload the produced binary to the remote target?

I'm speaking from the new plugin point of view.

Thank you very much in advance,
Mike
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by eranif »

From what I have read, you need to create a skeleton plugin and start from there.
The wizard will create an empty plugin that will compile and will get loaded into CodeLite.

It does nothing at this point.

However, the entire plugin mechanism of CodeLite is event based.
For example, in your case, to implement the functionality of:
When debugging, starting the 'loader' with the according parameters, then starting gdb in the same time and do remote debugging
You would want to capture the event: wxEVT_DEBUG_STARTING
This event is sent just before the debug session starts, so in your case, you should have code simialr to this in your plugin:

Code: Select all

// In the constructor of the plugin
EventNotifier::Get()->Bind(wxEVT_DEBUG_STARTING, &MyPlugin::OnDebugStarting, this);

Code: Select all

// In the "UnPlug" method of the plugin
EventNotifier::Get()->Unbind(wxEVT_DEBUG_STARTING, &MyPlugin::OnDebugStarting, this);
And the handlers itself:

Code: Select all

void MyPlugin::OnDebugStarting(wxCommandEvent& event)
{
    // we must call event.Skip() so codelite will continue the normal execution
    // if we don't call event.Skip(), codelite will assume that we have taken over 
    // the "Debug Starting" event and will do nothing
    event.Skip();
    // TODO :: launch the "Loader" here
}
To get a list of all events fired from CodeLite to the plugins, see this file (there is a comment on top of each event
with a brief description of what it does)
https://github.com/eranif/codelite/blob ... e_events.h

Eran
Make sure you have read the HOW TO POST thread
SiZiOUS
CodeLite Curious
Posts: 6
Joined: Mon Mar 02, 2015 10:42 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by SiZiOUS »

Thank you very much for your valuable answer. This is exactly what I was looking for starting the plugin.

Maybe do you have some sample code (the skeleton) to provide for handling the makefile as well?
Or more simpler with CodeLite events we can do everything we want; so I'll find an event handler for makefile generation, in the same 'spirit' of the previous sample?

Edit: OK, just saw your header file, so for the makefile generation, I think this should do the trick:

Code: Select all

// Event type: clBuildEvent
// the below two events are sent by the application to the plugins to query whether a
// given project and build configuration are handled by the plugin.
// the first event is whether the makefile file is generated by the plugin
// and the second is to know whether the build process is also being
// handled by the plugin.
// the return answer is done by simply avoid calling event.Skip() (which will result in ProcessEvent() == true)
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_GET_IS_PLUGIN_MAKEFILE, clBuildEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_GET_IS_PLUGIN_BUILD, clBuildEvent);
Edit 2: About the makefile generation, is it possible to get inside the plugin code some project parameters like the "output file" (an internal var, something like '$(OUTPUT_BIN)')?
The question is, may you provide me some code sample in order to get the current project properties?

Just additionnal question about the plugin system: I just wondering, if I write a plugin under Windows, the same plugin will work on another platforms (of course with recompilation)?
The question here is, when the plugin is developed, all the methods/events are multiplatforms in the CodeLite 'kernel' ? Or there's some methods/events that is only available for a specific plateform?

Other thing, to start writing the plugin, all I need is to download CodeLite, plug it on the toolchain (MinGW) and that's all?
I think the answer is yes but just wondering if I need more things (like a 'CodeLite SDK').

Thank you,
Mike
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by eranif »

The best to place to search for examples, are in codelite sources.
For example, have a look at the CMakePlugin which hooks into the build system and generates CMakeLists.txt files based on the project configuration

https://github.com/eranif/codelite/blob ... Plugin.cpp

The start building a plugin you either clone a specific tag from GitHub (7.0, 6.1 etc) or download the release zip file
or work directly on 'master'


Eran
Make sure you have read the HOW TO POST thread
SiZiOUS
CodeLite Curious
Posts: 6
Joined: Mon Mar 02, 2015 10:42 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite in cross-compiling context

Post by SiZiOUS »

Thank you very much for all Eran.
I'll check this out. :)

Mike
Post Reply