Skip to content

Instantly share code, notes, and snippets.

@aarmot
Created January 23, 2013 11:27
Show Gist options
  • Save aarmot/4604573 to your computer and use it in GitHub Desktop.
Save aarmot/4604573 to your computer and use it in GitHub Desktop.
Makefile for MSP430 development in Linux. Inspiration taken from http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=Example:Makefile
#
# Makefile for msp430
#
# 'make' builds everything
# 'make lst' generates assembly listings of each source
# 'make dump' generates assembler dump of target
# 'make burn' flashes target into launchpad
# 'make clean' deletes everything except source files and Makefile
#
# You need to set TARGET, MCU and SOURCES for your project.
# TARGET is the name of the executable file to be produced
#
TARGET = null
MCU = msp430g2553
# List all the source files here
# eg if you have a source file foo.c then list it here
SOURCES = null.c
# Include are located in the Include directory
INCLUDES = -IInclude
LIBS =
# Add or subtract whatever MSPGCC flags you want. There are plenty more
#######################################################################################
CFLAGS = -mmcu=$(MCU) -g -Os -Wall -Wunused -Wno-main $(INCLUDES)
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map
########################################################################################
CC = msp430-gcc
LD = msp430-ld
AR = msp430-ar
AS = msp430-gcc
NM = msp430-nm
OBJCOPY = msp430-objcopy
OBJDUMP = msp430-objdump
RANLIB = msp430-ranlib
STRIP = msp430-strip
SIZE = msp430-size
READELF = msp430-readelf
MSPDEBUG = mspdebug
CP = cp -p
RM = rm -f
MV = mv
########################################################################################
.PHONY: all burn lst dump clean
# the file which will include dependencies
DEPEND = $(SOURCES:.c=.d)
# all the object files
OBJECTS = $(SOURCES:.c=.o)
all: $(TARGET).elf
$(TARGET).elf: $(OBJECTS)
@echo "Linking $@"
$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
@echo
@echo ">>>> Size of Firmware <<<<"
$(SIZE) $(TARGET).elf
@echo
%.o: %.c
@echo "Compiling $<"
$(CC) -c $(CFLAGS) -o $@ $<
# make assembler source listing
LISTINGS = $(SOURCES:.c=.lst)
lst: $(LISTINGS)
%.lst: %.c
@echo "Compiling $< to $@"
$(CC) -c $(CFLAGS) -Wa,-anlhd $< > $@
dump: $(TARGET).elf
$(OBJDUMP) -S $< > $(TARGET).dump
# include the dependencies unless we're going to clean, then forget about them.
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPEND)
endif
# dependencies file
# includes also considered, since some of these are our own
# (otherwise use -MM instead of -M)
%.d: %.c
@echo "Generating dependencies $@ from $<"
$(CC) -M ${CFLAGS} $< >$@
burn: $(TARGET).elf
$(MSPDEBUG) rf2500 "prog $(TARGET).elf"
clean:
-$(RM) $(TARGET).elf $(TARGET).map $(OBJECTS) $(DEPEND) $(LISTINGS) $(TARGET).dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment