summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-02-11 22:58:16 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-02-11 22:59:53 +0100
commit5b1afe32cf7496acea8182278aca83f59e8384e3 (patch)
treed1c0cadb01a5d638bb12251d488b7beef8a156d0 /Makefile
parent4e50c8291bd83a3fbb24a209fd1f6c7cbdb5283c (diff)
downloadmpd-box-5b1afe32cf7496acea8182278aca83f59e8384e3.tar.gz
mpd-box-5b1afe32cf7496acea8182278aca83f59e8384e3.tar.xz
Make code launchpad/energia compatible
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile62
1 files changed, 62 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0c8f506
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,62 @@
+# You can get arduino compatibility code from Energia
+# https://github.com/energia/Energia
+#
+# symlink/copy Energia/hardware/msp430/cores/msp430 to ./lib/msp430
+# symlink/copy Energia/hardware/msp430/variants/launchpad ./lib/launchpad
+# symlink/copy any other libraries you use into ./lib/
+#
+# 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 -Ilib/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_lib=$(wildcard lib/*/*.c lib/*/*.cpp)
+OBJS_lib_TMP=$(SOURCES_lib:.c=.o)
+OBJS_lib=$(OBJS_lib_TMP:.cpp=.o)
+BUILD_OBJS_lib=$(addprefix build/,$(OBJS_lib))
+
+CFLAGS += $(addprefix -I,$(sort $(dir $(SOURCES_lib))))
+
+all: dirs build/main.elf
+
+dirs:
+ mkdir -p $(sort $(dir $(BUILD_OBJS) $(BUILD_OBJS_lib)))
+
+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/lib/core.a: $(BUILD_OBJS_lib)
+ @echo " [AR] $@: $^"
+ @msp430-ar rcs $@ $^
+
+# link everything together
+build/main.elf: $(BUILD_OBJS) build/lib/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