summaryrefslogtreecommitdiffstats
path: root/Arduino.mk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Arduino.mk107
1 files changed, 73 insertions, 34 deletions
diff --git a/Arduino.mk b/Arduino.mk
index 7e9cea1..efc249e 100644
--- a/Arduino.mk
+++ b/Arduino.mk
@@ -3,8 +3,9 @@
# Arduino command line tools Makefile
# System part (i.e. project independent)
#
-# Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
-# Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
+# Copyright (C) 2010,2011,2012 Martin Oldfield <m@mjo.tc>, based on
+# work that is copyright Nicholas Zambetti, David A. Mellis & Hernando
+# Barragan.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
@@ -41,6 +42,27 @@
# - added -lc to linker opts,
# on Fabien Le Lez's advice
#
+# 0.7 12.vii.2011 M J Oldfield
+# - moved -lm to the end of linker opts,
+# to solve Frank Knopf's problem;
+# - added -F to stty opts: Craig Hollabaugh
+# reckons it's good for Ubuntu
+#
+# 0.8 12.ii.2012 M J Oldfield
+# - Patches for Arduino 1.0 IDE:
+# support .ino files;
+# handle board 'variants';
+# tweaked compile flags.
+# - Build a library from all the system
+# supplied code rather than linking the .o
+# files directly.
+# - Let TARGET default to current directory
+# as per Daniele Vergini's patch.
+# - Add support for .c files in system
+# libraries: Dirk-Willem van Gulik and Evan
+# Goldenberg both reported this and
+# provided patches in the same spirit.
+#
########################################################################
#
# STANDARD ARDUINO WORKFLOW
@@ -53,7 +75,7 @@
# ARDUINO_DIR = /Applications/arduino-0013
#
# TARGET = CLItest
-# ARDUINO_LIBS = LiquidCrystal
+# ARDUINO_LIBS = Ethernet Ethernet/utility SPI
#
# BOARD_TAG = uno
# ARDUINO_PORT = /dev/cu.usb*
@@ -63,13 +85,18 @@
# Hopefully these will be self-explanatory but in case they're not:
#
# ARDUINO_DIR - Where the Arduino software has been unpacked
+#
# TARGET - The basename used for the final files. Canonically
# this would match the .pde file, but it's not needed
# here: you could always set it to xx if you wanted!
-# ARDUINO_LIBS - A list of any libraries used by the sketch (we assume
-# these are in $(ARDUINO_DIR)/hardware/libraries
+#
+# ARDUINO_LIBS - A list of any libraries used by the sketch (we
+# assume these are in
+# $(ARDUINO_DIR)/hardware/libraries
+#
# ARDUINO_PORT - The port where the Arduino can be found (only needed
# when uploading
+#
# BOARD_TAG - The ard-parse-boards tag for the board e.g. uno or mega
# 'make show_boards' shows a list
#
@@ -84,8 +111,8 @@
#
# All of the object files are created in the build-cli subdirectory
# All sources should be in the current directory and can include:
-# - at most one .pde file which will be treated as C++ after the standard
-# Arduino header and footer have been affixed.
+# - at most one .pde or .ino file which will be treated as C++ after
+# the standard Arduino header and footer have been affixed.
# - any number of .c, .cpp, .s and .h files
#
# Included libraries are built in the build-cli/libs subdirectory.
@@ -159,6 +186,7 @@ ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
ifndef ARDUINO_CORE_PATH
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
+ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants
endif
endif
@@ -178,6 +206,11 @@ ifndef PARSE_BOARD
PARSE_BOARD = $(SELF_PATH)/ard-parse-boards --boards_txt=$(BOARDS_TXT)
endif
+# Which variant ? This affects the include path
+ifndef VARIANT
+VARIANT = $(shell $(PARSE_BOARD) $(BOARD_TAG) build.variant)
+endif
+
# processor stuff
ifndef MCU
MCU = $(shell $(PARSE_BOARD) $(BOARD_TAG) build.mcu)
@@ -217,9 +250,6 @@ ifndef ISP_EXT_FUSE
ISP_EXT_FUSE = $(shell $(PARSE_BOARD) $(BOARD_TAG) bootloader.extended_fuses)
endif
-
-
-
# Everything gets built in here
OBJDIR = build-cli
@@ -230,10 +260,11 @@ LOCAL_C_SRCS = $(wildcard *.c)
LOCAL_CPP_SRCS = $(wildcard *.cpp)
LOCAL_CC_SRCS = $(wildcard *.cc)
LOCAL_PDE_SRCS = $(wildcard *.pde)
+LOCAL_INO_SRCS = $(wildcard *.ino)
LOCAL_AS_SRCS = $(wildcard *.S)
-LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
- $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
- $(LOCAL_AS_SRCS:.S=.o)
+LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
+ $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
+ $(LOCAL_INO_SRCS:.ino=.o) $(LOCAL_AS_SRCS:.S=.o)
LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
# Dependency files
@@ -247,12 +278,9 @@ CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o)
CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \
$(OBJDIR)/%,$(CORE_OBJ_FILES))
-CORE_ARCHIVE = $(OBJDIR)/core.a
endif
endif
-# all the objects!
-OBJS = $(LOCAL_OBJS) $(LIB_OBJS)
########################################################################
# Rules for making stuff
@@ -262,6 +290,7 @@ OBJS = $(LOCAL_OBJS) $(LIB_OBJS)
TARGET_HEX = $(OBJDIR)/$(TARGET).hex
TARGET_ELF = $(OBJDIR)/$(TARGET).elf
TARGETS = $(OBJDIR)/$(TARGET).*
+CORE_LIB = $(OBJDIR)/libcore.a
# A list of dependencies
DEP_FILE = $(OBJDIR)/depends.mk
@@ -282,21 +311,19 @@ ECHO = echo
# General arguments
SYS_LIBS = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS))
-SYS_OBJS = $(wildcard $(patsubst %,%/*.o,$(SYS_LIBS)))
-LIB_SRC = $(wildcard $(patsubst %,%/*.cpp,$(SYS_LIBS)))
-LIB_OBJS = $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(LIB_SRC))
+LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS)))
+LIB_CPP_SRCS = $(wildcard $(patsubst %,%/*.cpp,$(SYS_LIBS)))
+LIB_OBJS = $(patsubst $(ARDUINO_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(LIB_C_SRCS)) \
+ $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(LIB_CPP_SRCS))
-CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
- -I. -I$(ARDUINO_CORE_PATH) \
+CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) \
+ -I. -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \
$(SYS_INCLUDES) -g -Os -w -Wall \
-ffunction-sections -fdata-sections
CFLAGS = -std=gnu99
CXXFLAGS = -fno-exceptions
ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
-LDFLAGS = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
-
-# Rules for making a CPP file from the main sketch (.cpe)
-PDEHEADER = \\\#include \"WProgram.h\"
+LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os
# Expand and pick the first port
ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT)))
@@ -310,10 +337,14 @@ ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT)))
# easy to change the build options in future
# library sources
-$(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.cpp
+$(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.c
mkdir -p $(dir $@)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
+$(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.cpp
+ mkdir -p $(dir $@)
+ $(CC) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
+
# normal local sources
# .o rules are for objects, .d for dependency tracking
# there seems to be an awful lot of duplication here!!!
@@ -349,7 +380,12 @@ $(OBJDIR)/%.d: %.s
# the pde -> cpp -> o file
$(OBJDIR)/%.cpp: %.pde
- $(ECHO) $(PDEHEADER) > $@
+ $(ECHO) '#include "WProgram.h"' > $@
+ $(CAT) $< >> $@
+
+# the ino -> cpp -> o file
+$(OBJDIR)/%.cpp: %.ino
+ $(ECHO) '#include <Arduino.h>' > $@
$(CAT) $< >> $@
$(OBJDIR)/%.o: $(OBJDIR)/%.cpp
@@ -411,11 +447,11 @@ all: $(OBJDIR) $(TARGET_HEX)
$(OBJDIR):
mkdir $(OBJDIR)
-$(CORE_ARCHIVE): $(CORE_OBJS)
- $(AR) rcs $@ $^
+$(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -lc -lm
-$(TARGET_ELF): $(OBJS) $(CORE_ARCHIVE)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(CORE_ARCHIVE) $(SYS_OBJS) -lc
+$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS)
+ $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS)
$(DEP_FILE): $(OBJDIR) $(DEPS)
cat $(DEPS) > $(DEP_FILE)
@@ -430,7 +466,7 @@ raw_upload: $(TARGET_HEX)
# stdin/out appears to work but generates a spurious error on MacOS at
# least. Perhaps it would be better to just do it in perl ?
reset:
- for STTYF in 'stty --file' 'stty -f' 'stty <' ; \
+ for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \
done ;\
$$STTYF $(ARD_PORT) hupcl ;\
@@ -449,14 +485,17 @@ ispload: $(TARGET_HEX)
-U lock:w:$(ISP_LOCK_FUSE_POST):m
clean:
- $(REMOVE) $(OBJS) $(CORE_OBJS) $(TARGETS) $(DEP_FILE) $(DEPS) $(CORE_ARCHIVE)
+ $(REMOVE) $(LOCAL_OBJS) $(CORE_OBJS) $(LIB_OBJS) $(CORE_LIB) $(TARGETS) $(DEP_FILE) $(DEPS)
depends: $(DEPS)
cat $(DEPS) > $(DEP_FILE)
+size: $(OBJDIR) $(TARGET_HEX)
+ $(SIZE) $(TARGET_HEX)
+
show_boards:
$(PARSE_BOARD) --boards
-.PHONY: all clean depends upload raw_upload reset show_boards
+.PHONY: all clean depends upload raw_upload reset size show_boards
include $(DEP_FILE)