Working with existing makefile based project

General questions regarding the usage of CodeLite
jayachar
CodeLite Curious
Posts: 6
Joined: Sat Aug 31, 2013 11:07 am
Genuine User: Yes
IDE Question: c++
Contact:

Working with existing makefile based project

Post by jayachar »

Hi,

Downloaded CodeLite last night, in the hopes of using it on my Linux (Debian 'Wheezy') box, to browse, understand and later debug some existing source code, that is written predominantly in C/C++ with bits of lua, python and perl also thrown in. The project in question is highly modular, and every module is built using an independent Makefile, although it is a fairly simple Makefile at module level. The entire project is built using Makefile generated by autoconfig tool, based on various parameters -- as is typical, like optional libraries, features, build-tools, their options and various non-default paths etc.

Earlier I tried using Eclipse IDE with CDT, but got somewhat frustrated with it's UI and sluggish speed on my rather oldish laptop. All the source is organized like:

My existing Eclipse workspace -

Code: Select all

/home/jayachar/workspace/
The existing project that I intend to pull inside CodeLite workspace to work on it -

Code: Select all

/home/jayachar/workspace/MyProject/
/home/jayachar/workspace/MyProject/src/
/home/jayachar/workspace/MyProject/src/CodeFile_1.cpp
/home/jayachar/workspace/MyProject/src/CodeFile_2.cpp
/home/jayachar/workspace/MyProject/src/CodeFile_1.h
...
/home/jayachar/workspace/MyProject/src/modules/
/home/jayachar/workspace/MyProject/src/modules/ModuleX/
/home/jayachar/workspace/MyProject/src/modules/ModuleX/CodeFile_X1.c
/home/jayachar/workspace/MyProject/src/modules/ModuleX/CodeFile_X1.h
...
/home/jayachar/workspace/MyProject/src/modules/ModuleY/
/home/jayachar/workspace/MyProject/src/modules/ModuleZ/
...
However, I've struggled for a while, without being able to figure out how to go about it. Not sure if CodeLite treats the directory named "workspace" specially, since everytime I try to either create a new workspace, it goes inside the Eclipse-workspace directory to create a workspace there. If I try to open the Eclipse-workspace directory, it looks for some meta-file (perhaps) with extension *.workspace and doesn't find it.

Then I try to create a new workspace called "workspace-codelite" and import the project "MyProject" into it, it went ahead and created it as"

Code: Select all

/home/jayachar/workspace-codelite/workspace/MyProject/
while I was expecting it to be like --

Code: Select all

/home/jayachar/workspace-codelite/MyProject/
This silly little thing has got me stumped. I am bit picky and perfectionist about getting this organization correct! Any help in getting over this hurdle would be much appreciated.

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

Re: Working with existing makefile based project

Post by eranif »

If your goal is to:
- Enable code browsing + coding using codelite
- Keep using the existing Makefiles
- Allow running the autoconf from within codelite

You can achieve it like this:

- Close any workspace you have opened/created
- Create a custom build project and locate it at the top level folder of your project, this is done from:
Workspace -> New Project, and select the project path and give it a name:
custom-makefile-project.png
- You should now have a workspace + a single project (codelite will create the workspace for you)
- Right click on the project and select 'Import files from directory', the import dialog will pop-up select the folders you want to import (selecting a parent folder will automatically will select all its children)
import-dialog.png
Click OK, and let codelite import the files
Note that unlike eclipse: codelite does _not_ make a copy of the files it uses the existing copies from the file system

- To enable build using your own makefiles read this:
http://codelite.org/LiteEditor/CustomMakefiles

EDIT: I have updated the wiki link
Eran
You do not have the required permissions to view the files attached to this post.
Make sure you have read the HOW TO POST thread
jayachar
CodeLite Curious
Posts: 6
Joined: Sat Aug 31, 2013 11:07 am
Genuine User: Yes
IDE Question: c++
Contact:

Re: Working with existing makefile based project

Post by jayachar »

Thanks @eranif.

My project is about 99% C code, balance is C++, Lua, Python code. I presume that I will have to select g++ as the compiler at the project top-level. Since I'd be anyhow be using custom Makefiles, I guess this selection is immaterial, right ?

BTW, does CodeLite have the ability to auto-fold code wrapped in specific #ifdef's? For instance, while browsing code, I do not want to be distracted by code meant for WIN32 and QNX platforms. The code relevant to those platforms are wrapped in:

Code: Select all

#ifdef _WIN32_ENABLE
...
#endif
and

Code: Select all

#ifdef _QNX_ENABLE
...
#endif
And if for every file within the project, if I open them, and via a project level option, the folding of code within _WIN32_ENABLE and _QNX_ENABLE is set to true, all that code shows up collapsed in a single-line i.e. the opening #ifdef line.

Or am I dreaming ?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Working with existing makefile based project

Post by eranif »

You will need to set the compiler type mainly for parsing the compiler (each compiler comes with set of regular expressions)
In your case, gcc / g++ is the same.

Note about code completion:

codelite has its own code completion engine, however, it also supports clang as code completion engine (the 2 engines can be used internally with no problem), however, setting clang for custom makefile project requires a small configuration
change described here:

clang code completion in codelite:
http://codelite.org/LiteEditor/ClangIntegration41#toc1

Specifically custom makefiles:
http://codelite.org/LiteEditor/ClangIntegration41#toc3

Eran
Make sure you have read the HOW TO POST thread
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Working with existing makefile based project

Post by eranif »

jayachar wrote:BTW, does CodeLite have the ability to auto-fold code wrapped in specific #ifdef's? For instance, while browsing code, I do not want to be distracted by code meant for WIN32 and QNX platforms
It has no way to hide it, however, it can "disable" it by colouring it with grey colour
However, this functionality is broken in codelite 5.2 and is fixed in git head
grey-blocks.png
Eran
You do not have the required permissions to view the files attached to this post.
Make sure you have read the HOW TO POST thread
jayachar
CodeLite Curious
Posts: 6
Joined: Sat Aug 31, 2013 11:07 am
Genuine User: Yes
IDE Question: c++
Contact:

Re: Working with existing makefile based project

Post by jayachar »

Thanks Eran.

So to ensure that the code-block surrounding by the #if / #ifdef in question, is there some way to declare a list, kind of a grey-out list ?
Is there any nightly build done for CodeLight ?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Working with existing makefile based project

Post by eranif »

jayachar wrote:Thanks Eran.

So to ensure that the code-block surrounding by the #if / #ifdef in question, is there some way to declare a list, kind of a grey-out list ?
Is there any nightly build done for CodeLight ?
No, no list to define, its done automatically by parsing the source files.
There is no nightly build, but you can build codelite from sources by reading this:

http://codelite.org/Developers/Linux

Eran
Make sure you have read the HOW TO POST thread
jayachar
CodeLite Curious
Posts: 6
Joined: Sat Aug 31, 2013 11:07 am
Genuine User: Yes
IDE Question: c++
Contact:

Re: Working with existing makefile based project

Post by jayachar »

@Eran, without a list of macros defined, how does CodeLite know which #if and #ifdef blocks to grey-out and which not to ?
Or does it grey-out all such blocks, irrespective of the condition check ?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Working with existing makefile based project

Post by eranif »

It uses clang for this purpose.
clang is a compiler - so the same way the compiler knows which blocks not to enter

Since you are using a custom makefile with autoconf you should do this:

If you run the configure from within codelite, define 2 environment variable from Settings -> Environment variables :

Code: Select all

CXX=codelitegcc g++
CC=codelitegcc gcc
If you are running things from the command line:

Code: Select all

export CXX=codelitegcc g++
export CC=codelitegcc gcc
./configure
codelitegcc is a small executable that copies the build line and pass it to the g++/gcc (or any other compiler) the compilation lines are kept in a small compilation.db sqlite file
which later is used by codelite to get the compilation line it needs and pass it to clang

Once codelite has the compilation line and it can create an AST using libclang and traverse it to get the list of macros (this is how clang works)
If you are really interested, codelite is open source - you can see it in the code ;), specifically look here:

Code: Select all

void ClangDriver::GetMacros(IEditor *editor)

in file

Code: Select all

LiteEditor/clang_driver.cpp
Eran

Eran
Make sure you have read the HOW TO POST thread
jayachar
CodeLite Curious
Posts: 6
Joined: Sat Aug 31, 2013 11:07 am
Genuine User: Yes
IDE Question: c++
Contact:

Re: Working with existing makefile based project

Post by jayachar »

Thanks @Eran.

Well, I am not familiar with clang, but thought it to be a newer alternative to gcc/g++. I already have gcc installed, so to use this feature of code-folding, do I have to necessarily install clang ?
Post Reply