summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 3ea5ba99e674c7f19de6fb5861ee702b66174eb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# You can get arduino compatibility code from Energia
# https://github.com/energia/Energia
#
# symlink/copy Energia/hardware/msp430/cores/msp430 to ./libs/msp430
# symlink/copy Energia/hardware/msp430/variants/launchpad ./libs/launchpad
# symlink/copy any other libraries you use into ./libs/
#
# put your own code into ./src/

# these can be configure to suite your environment
CC=msp430-gcc
CXX=msp430-g++
MCU=msp430g2553
MSPDEBUG_DRIVER=rf2500
CFLAGS=-c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=16000000L -MMD -DARDUINO=101 -DENERGIA=9 -Ilibs/launchpad
CXXFLAGS=$(CFLAGS)

# create a list of objects from src/
SOURCES=$(wildcard src/*.c src/*.cpp)
OBJS_TMP=$(SOURCES:.c=.o)
OBJS=$(OBJS_TMP:.cpp=.o)
BUILD_OBJS=$(addprefix build/,$(OBJS))

# create a list of library objects
SOURCES_LIBS=$(wildcard libs/*/*.c libs/*/*.cpp)
OBJS_LIBS_TMP=$(SOURCES_LIBS:.c=.o)
OBJS_LIBS=$(OBJS_LIBS_TMP:.cpp=.o)
BUILD_OBJS_LIBS=$(addprefix build/,$(OBJS_LIBS))

CFLAGS += $(addprefix -I,$(sort $(dir $(SOURCES_LIBS))))

all: dirs build/main.elf

dirs:
	mkdir -p $(sort $(dir $(BUILD_OBJS) $(BUILD_OBJS_LIBS)))

build/%.o: %.cpp
	@echo " [CXX] $@: $<"
	@$(CXX) $(CXXFLAGS) $^ -o $@

build/%.o: %.c
	@echo " [CC]  $@: $<"
	@$(CC) $(CFLAGS) $^ -o $@

# copy together all lib code into core.a
build/libs/core.a: $(BUILD_OBJS_LIBS)
	@echo " [AR]  $@: $^"
	@msp430-ar rcs $@ $^

# link everything together
build/main.elf: $(BUILD_OBJS) build/libs/core.a
	@echo " [CC]  $@: $^"
	@$(CC) -Os -Wl,-gc-sections,-u,main -mmcu=$(MCU) -o $@ $^ -lm

# upload the result to the board
upload: all
	mspdebug $(MSPDEBUG_DRIVER) --force-reset "prog build/main.elf" "verify build/main.elf"

clean:
	rm -fr build

.PHONY: dirs all upload clean