########################################################################### # # Rules.mk - Contains common makefile support for the Robostix sameples # ########################################################################### AVR_MCU = atmega128 all: $(TARGET) $(TARGET) : % : %.hex .PHONY: all $(TARGET) CROSS_COMPILE = avr- CC = $(CROSS_COMPILE)gcc OBJCOPY = $(CROSS_COMPILE)objcopy AVR_MCU_FLAGS = -mmcu=$(AVR_MCU) vpath %.c ../Common CFLAGS += -Os -Wall CPPFLAGS += $(AVR_MCU_FLAGS) -I . -I ../Common LDFLAGS += $(AVR_MCU_FLAGS) -Wl,-Map,$(basename $@).map DEP_OUTPUT_OPTION = -MMD -MF $(@:.o=.d) ECHO = @echo RM = rm COMMON_DEPS = $(strip $(COMMON_OBJS:.o=.d)) DEP_FILES = $(TARGET).d $(COMMON_DEPS) #-------------------------------------------------------------------------- # # Run make with v=1 or verbose=1 to get verbose output # ifeq ($(v),) export verbose = 0 else export verbose = 1 endif ifeq ($(verbose),) export verbose = 0 endif ifeq ($(verbose),0) Q = @ MAKEFLAGS += -s else Q = endif export Q #-------------------------------------------------------------------------- # # CFLAGS = flags used for C compiler # CXXFLAGS = flags for the C++ compiler # CPPFLAGS = flags for the C preprocessor (-D, -I) # PREPROCESS.c = $(CC) $(CPPFLAGS) $(TARGET_ARCH) -E -Wp,-C,-dD,-dI #-------------------------------------------------------------------------- # # The FORCE target can be used for things that you want to have rebuild # every single time (like *.pp files) # FORCE: .PHONY: FORCE #-------------------------------------------------------------------------- # # Compile C source files # # COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c # .PRECIOUS: %.o %.o : %.c $(ECHO) "Compiling $< ..." $(Q)$(COMPILE.c) $(DEP_OUTPUT_OPTION) $(OUTPUT_OPTION) $< #-------------------------------------------------------------------------- # # Generate Preprocessed files from C source (useful for debugging) # %.pp : %.c FORCE $(ECHO) "Preprocessing $< ..." $(Q)$(PREPROCESS.c) $< > $@ #-------------------------------------------------------------------------- # # Generate C/asm listing # %.cod : %.c FORCE $(ECHO) "Listing $< ..." $(Q)$(COMPILE.c) -gstabs -Wa,-ahdlms=$@ $< #-------------------------------------------------------------------------- # # Create a hex file from an elf file # %.hex : %.elf $(ECHO) "Creating $@ ..." $(Q)$(OBJCOPY) -j .text -j .data -O ihex $< $@ $(ECHO) #-------------------------------------------------------------------------- # # Create simple executables # %.elf : %.o $(COMMON_OBJS) $(ECHO) "Linking $@ ..." $(Q)$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(ECHO) avr-mem.sh $@ $(AVR_MCU) $(ECHO) clean: clean-other clean-hex clean-other: $(ECHO) "Removing generated files ..." $(Q)$(RM) -f *.d *.o *.elf *.map clean-hex: $(ECHO) "Removing hex files ..." $(Q)$(RM) -f *.hex #-------------------------------------------------------------------------- # # Include dependencies. # # The '-' at the beginning tells make not to complain about missing # dependency files. # ifneq ($(DEP_FILES),) ifeq ($(strip $(filter clean% exec print-%, $(MAKECMDGOALS))),) -include $(DEP_FILES) endif endif