Page 1 of 1

Help convert makefile to CodeLite

Posted: Tue Jul 19, 2011 7:44 pm
by jasper77
I'm in the early stages of a project. I have a hand written makefile that builds it, and I'm interested in using CodeLite to manage the build instead.
There are a few things I can't figure out how to do. I'll run down the lines in the makefile and say how I *think* I should address them in CodeLite,
so you can correct me if/when I'm wrong, and ask questions where I don't know.

The following lines point to the cross compiler and the objcopy utility. I know how to tell CodeLite what compiler to use: I go to Settings -> Build Settings and add a new compiler.
I have no idea what to do with the objcopy utility.

Code: Select all

CC="C:\path\to\my\cross-gcc"
OBJCOPY="C:\path\to\my\cross-objcopy"
The following identifies compiler flags. For the ones I want to apply to any project using this compiler, I put them with the Build Settings for that compiler.
For the project specific flags, I put them in Project Settings -> Common Settings -> Compiler.

Code: Select all

CFLAGS=-mthumb -mcpu=cortex-m3 -DSTM32F10X_CL -DUSE_STDPERIPH_DRIVER \
	-DMYFLAG1=0 -DMYFLAG2=0 -O0 \
	-ffunction-sections -fdata-sections -g -Wall 
The following are linker flags. I put them in "Linker options" for that compiler under Build Settings. Also I added the path to the linker when I added the compiler.

Code: Select all

LDFLAGS=-mthumb -mcpu=cortex-m3 -Tstm32_flash.ld -static \
	-Wl,-cref,-u,Reset_Handler -Wl,-Map=myproject.map \
	-Wl,--gc-sections
These are assembler flags. What do I do with them?

Code: Select all

ASFLAGS=-mthumb -mcpu=cortex-m3 -g -Wa,--warn 
There's a long list of object files. Is it correct that I don't need to put those anywhere if CodeLite is managing the build?

Code: Select all

OBJS= \
	./path/to/object/file.o \
	./path/to/another/file.o 

There's a long list of include directories. Do I need to add them all to the "Include Paths" in Project Settings?

Code: Select all

INC= \
	-I./common_includes/inc/ \
	-I./other/includes 
This rule uses the assembler flags. If any .s files have been updated, it creates object files for them. Where and how do I tell CodeLite to do this?

Code: Select all

%.o: %.s
	$(CC) -c  $(ASFLAGS) -o $@ $< 

Here's a second object file rule, which uses the compiler flags, if any .c files or include files have changed. I don't think I have to do anything in particular to instruct CodeLite to do this, right?

Code: Select all

%.o: %.c $(INCLUDES)
	$(CC) -c  $(CFLAGS) $(INC) -o $@ $<
This links the objects into a .elf file. What should I tell CodeLite for the type of target here? Is it an executable? This isn't even the final result of the build.

Code: Select all

myproject.elf: $(OBJS)
	$(CC) -o $@ $^ $(LDFLAGS)
This final step in the build uses objcopy to convert the .elf into a binary suitable for download onto the target microprocessor. How do I instruct CodeLite to do this?

Code: Select all

myproject.bin: myproject.elf
	$(OBJCOPY) -O binary myproject.elf myproject.bin

Re: Help convert makefile to CodeLite

Posted: Fri Jul 22, 2011 6:18 am
by jasper77
There haven't been any responses. Is the question unclear? Should I post it under the forum for installation and setup issues?

Thanks!

Re: Help convert makefile to CodeLite

Posted: Fri Jul 22, 2011 9:07 am
by eranif
jasper77 wrote:I have no idea what to do with the objcopy utility.
Make it a post build command
jasper77 wrote:These are assembler flags. What do I do with them?
Under the build settings -> gcc (or g++) select the 'File Types'
add new handling for '.s' files (copy the pattern from .c file) and change it to:

Code: Select all

$(C_CompilerName) -c "$(FileFullPath)" $(ASFLAGS) $(IncludePath) -o $(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) 
ASFLAGS can be defined as environment variable (Settings | Environment Variables). If you don't want ASFLAGS to be an environment variable, you can just place all your flags hard coded in the above pattern.
note that if you are using codelite from trunk, you can define an environment variables that will be kept as part of the project or workspace (project settings | environment)
jasper77 wrote:There's a long list of object files. Is it correct that I don't need to put those anywhere if CodeLite is managing the build?
No need to place them in codelite, they will be auto generated
jasper77 wrote:There's a long list of include directories. Do I need to add them all to the "Include Paths" in Project Settings?
Yes
jasper77 wrote:Is it an executable?
Yes. Use project of type 'executable' and the output of the project will be .elf file. then place the objcopy stage as a post build command

Eran