Jump to content
43oh

Makefile for MSPGCC


Recommended Posts

Rickta59 says this might be of interest to others, so here's the Makefile I've been using for MSPGCC.

 

TARGETMCU       ?= msp430g2211

CROSS           := msp430-
CC              := $(CROSS)gcc
CXX             := $(CROSS)g++
OBJDUMP         := $(CROSS)objdump
SIZE            := $(CROSS)size
LD              := $(CC)
MSPDEBUG        := mspdebug
LDFLAGS         := -mmcu=$(TARGETMCU)
CFLAGS          := -Os -Wall -W -Wextra -Werror -g -mmcu=$(TARGETMCU)

ifneq ($(WITH_CXX),)
       CC      := $(CXX)
       LD      := $(CC)
endif

ifneq ($(DEBUG),)
ifeq ($(WITH_CXX),)
       CFLAGS  += -Wstrict-prototypes -Wmissing-prototypes -Wbad-function-cast
       CFLAGS  += -Werror-implicit-function-declaration -Wdeclaration-after-statement
       CFLAGS  += -Wnested-externs -Wold-style-definition
       CFLAGS  += -finline-functions
endif
       CFLAGS  += -Wmissing-declarations -Winit-self -Winline -Wredundant-decls
       CFLAGS  += -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -Wformat=2
       CFLAGS  += -Wfloat-equal -Wmissing-field-initializers
       CFLAGS  += -Wmissing-include-dirs -Wswitch-default -Wpacked
       CFLAGS  += -Wpacked -Wlarger-than-65500 -Wunknown-pragmas
       CFLAGS  += -Wmissing-format-attribute -Wmissing-noreturn
       CFLAGS  += -Wstrict-aliasing=2 -Wswitch-enum -Wundef -Wunreachable-code
       CFLAGS  += -Wunsafe-loop-optimizations -Wwrite-strings -Wcast-align
       CFLAGS  += -Wformat-nonliteral -Wformat-security -Waggregate-return

       CFLAGS  += -fno-common -Wp,-D_FORTIFY_SOURCE=2
endif

SRCS            := main.c
PROG            := $(firstword $(SRCS:.c=))
OBJS            := $(SRCS:.c=.o)

all:            $(PROG).elf $(PROG).lst

$(PROG).elf:    $(OBJS)
               $(LD) $(LDFLAGS) -o $(PROG).elf $(OBJS)

%.o:            %.c
               $(CC) $(CFLAGS) -c $<

%.lst:          %.elf
               $(OBJDUMP) -DS $< > $@
               $(SIZE) $<

clean:
               -rm -f $(PROG).elf $(PROG).lst $(OBJS)

install:        $(PROG).elf
               $(MSPDEBUG) -n rf2500 "prog $(PROG).elf"

 

I don't know what half of the CFLAGs mean anymore (some of them most likely don't even have any real meaning in the MSP430 context), I have collected them during the years, the result is considerably anal about code quality, though.

 

roxfan notes,

why not use gcc -S instead of objdump? objdump won't show symbols stripped by linker. http://www.delorie.com/djgpp/v2faq/faq8_20.html

 

Well, I got used to objdump's output, that's about it.

 

It's GNU make, don't even try with others, really. Also don't forget to expand spaces to tabs.

Link to post
Share on other sites

here are the 2 make files I use for mspgcc - for use or comparison

 

OBJECTS = main.o 

CC = msp430-gcc
CFLAGS =-Os -Wall -g -mmcu=msp430x2011

all : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o main.elf

%.o : %.c 
$(CC) $(CFLAGS) -c $<


clean:
rm -fr $(OBJECTS) main.elf

erase:
mspdebug rf2500 "erase"

upload:
mspdebug rf2500 "prog main.elf"

size:
msp430-size main.elf

 

CC=msp430-gcc
CFLAGS=-Os -Wall -g -mmcu=msp430g2231

OBJS=main.c


all: $(OBJS)
$(CC) $(CFLAGS) -o main.elf $(OBJS)

%.o: %.c
$(CC) $(CFLAGS) -c $<

clean:
rm -fr main.elf $(OBJS)

 

 

very simple and no extra flags

 

as for all your flags, time to get out the gcc manual lol

Link to post
Share on other sites

Following up on viewtopic.php?f=10&t=1228#p8163, I made some tweaks to the Makefile. It now has simple heuristics to detect whether you are running Windows (I'm not much of a Windows person, so it is kind of a shot in the dark, please test), and if yes, it uses MSP430Flasher for installing.

 

It is also possible to have only one central instance of this "master" Makefile, with per-project Makefiles only referencing this one, possibly overriding some settings.

 

Per-project Makefile:

TARGETMCU       := msp430g2211

include         ../Makefile

(I really don't recommend symlinking the master Makefile in project directories, you'll surely shoot yourself in the foot sooner or later.)

 

Master Makefile:

TARGETMCU       ?= msp430g2231
SRCS            ?= main.c

CROSS           := msp430-
CC              := $(CROSS)gcc
CXX             := $(CROSS)g++
OBJDUMP         := $(CROSS)objdump
OBJCOPY         := $(CROSS)objcopy
SIZE            := $(CROSS)size
LD              := $(CC)
MSPDEBUG        := mspdebug
MSP430FLASHER   := C:\\bin\\MSP430Flasher
LDFLAGS         := -mmcu=$(TARGETMCU)
CFLAGS          := -Os -Wall -W -Wextra -Werror -std=gnu99 -g -mmcu=$(TARGETMCU)

ifneq ($(WITH_CXX),)
       CC      := $(CXX)
       LD      := $(CC)
endif

ifeq ($(WITH_CXX),)
       CFLAGS  += -Wstrict-prototypes -Wmissing-prototypes -Wbad-function-cast
       CFLAGS  += -Werror-implicit-function-declaration -Wdeclaration-after-statement
       CFLAGS  += -Wnested-externs -Wold-style-definition
endif
       CFLAGS  += -Wmissing-declarations -Winit-self -Winline -Wredundant-decls
       CFLAGS  += -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -Wformat=2
       CFLAGS  += -Wfloat-equal -Wmissing-field-initializers
       CFLAGS  += -Wmissing-include-dirs -Wswitch-default -Wpacked
       CFLAGS  += -Wpacked -Wlarger-than-65500 -Wunknown-pragmas
       CFLAGS  += -Wmissing-format-attribute -Wmissing-noreturn
       CFLAGS  += -Wstrict-aliasing=2 -Wswitch-enum -Wundef -Wunreachable-code
       CFLAGS  += -Wunsafe-loop-optimizations -Wwrite-strings -Wcast-align
       CFLAGS  += -Wformat-nonliteral -Wformat-security -Waggregate-return
       CFLAGS  += -fno-common -Wp,-D_FORTIFY_SOURCE=2
       CFLAGS  += -finline-functions

CXXFLAGS        := $(CFLAGS)

PROG            := $(firstword $(SRCS:.c=))
OBJS            := $(SRCS:.c=.o)

all:            $(PROG).elf $(PROG).hex $(PROG).lst

%.elf:          $(OBJS)
               $(LD) $(LDFLAGS) -o $(PROG).elf $(OBJS)
               $(SIZE) $<

%.o:            %.c
               $(CC) $(CFLAGS) -c $<

%.lst:          %.elf
               $(OBJDUMP) -DS $< > $@

%.hex:          %.elf
               $(OBJCOPY) -O ihex $< $@

clean:
               -rm -f $(PROG).elf $(PROG).lst $(PROG).hex $(OBJS)
install:        $(PROG).elf $(PROG).hex
ifeq ($(OS),Windows_NT)
               $(MSP430FLASHER) -n $(TARGETMCU) -e ERASE_MAIN -w $<
else
               $(MSPDEBUG) -n rf2500 "prog $<"
endif

erase:
               $(MSPDEBUG) -n rf2500 erase

.PHONY:         all clean install erase
.PRECIOUS:      %.o

 

I don't know what options does MSP430Flasher take, I just sort of guessed.

Link to post
Share on other sites

SLAU101 describes (in section A2) another format, TI-txt, which is supported by this MSP-GANG430 programmer. The format is also understood by SRecord (useful addition to the toolchest in it's own right).

 

I wonder, Rickta59, could you possibly try if MSP430Flasher understands this format? To convert from the Intel hex emitted by objcopy, you would go like "srec_cat -O $output.ti -TITXT $input.hex -I". Just for kicks, if you get to it :).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...