Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Makefile to automatically files in project

After I upgraded to CDT 1.2.0.4 I saw that there is something
called "Managed Make C++ project", though only for CygWin.

I have so far been using a different solution. The makefile
below will:

- you can add and remove .cc files to the project without
modifying the makefile, it automatically enumerates and 
compiles all .cc files.
- it automatically creates the dependency rules

My ultimate goal is to have continuous compilation like JDT has,
but in the meantime, the solution below works quite well for me.

The biggest problem is that builds aren't asynchronous, so Eclipse
blocks every time I save(since it is running the make file).

The file below is just lifted out of an eCos project, but it shouldn't
be hard to adapt to other projects.


INSTALL_DIR=../ramapp/install

APPNAME = testapp

# All this include file does is to define the ECOS_* variables
# for stuff such as compilation options.
include $(INSTALL_DIR)/include/pkgconf/ecos.mak


# This is our output directory
OUTPUT = ../output/$(APPNAME)

# This will enumerate all .cc files in the current directory and
# create a list of .o files we want to generate
LINKFILES = $(patsubst %.cc,$(OUTPUT)/%.o,$(shell ls *.cc))

# C++ compile setup, eCos specific.
XCC           = $(ECOS_COMMAND_PREFIX)gcc
XCXX          = $(ECOS_COMMAND_PREFIX)g++
XLD           = $(XCC)

CFLAGS        = -I$(INSTALL_DIR)/include
CXXFLAGS      = $(CFLAGS)  $(ECOS_GLOBAL_CFLAGS) -fexceptions
LDFLAGS       = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld

# these are not files that should be date checked
.PHONY : clean all bumpversion $(OUTPUT) 
 

all: bumpversion $(OUTPUT) $(OUTPUT)/$(APPNAME).bin

$(OUTPUT):
	mkdir --parents $(OUTPUT)

clean: 
	echo Cleaning
	rm -rf $(OUTPUT)

# This tells GCC the form that the dependency rules should have.
GENOPT = -MP -MT '$(OUTPUT)/$*.o' -MT '$(OUTPUT)/$*.d'

.SILENT: $(LINKFILES) $(LINKFILES:.o=.d) $(OUTPUT)/$(APPNAME).bin


# Here we compile .cc to .o and .d files at the same time
$(OUTPUT)/%.o: %.cc
	echo -- compiling $*.cc
	$(XCXX) $(GENOPT) -MD -c -o $(OUTPUT)/$*.o $(CXXFLAGS) $<

$(OUTPUT)/%.d: %.cc
	mkdir --parents $(OUTPUT)
	echo -- dependencies $*.cc
	$(XCXX) $(GENOPT) -M -MF $(OUTPUT)/$*.d $(CXXFLAGS) $*.cc

$(OUTPUT)/%.bin: 
	echo -- linking 
	$(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $(OUTPUT)/$*.elf $^
	arm-elf-objcopy -O srec $(OUTPUT)/$*.elf $(OUTPUT)/$*.srec
	arm-elf-objcopy -O binary $(OUTPUT)/$*.elf $(OUTPUT)/$*.bin
	arm-elf-size $(OUTPUT)/$*.elf
	echo -- Done!

# Tricky!
# if a .d file does not exist, it will be compiled
-include $(LINKFILES:.o=.d)

bumpversion:
	rm -rf $(OUTPUT)/version.o

$(OUTPUT)/$(APPNAME).bin: $(LINKFILES)



Back to the top