|
|
@ -1,274 +1,320 @@
|
|
|
|
|
|
|
|
TARGET = $(notdir $(CURDIR))
|
|
|
|
|
|
|
|
# CHANGE BELOW:
|
|
|
|
|
|
|
|
#~ INSTALL_DIR = /Applications/Arduino.app/Contents/Resources/Java
|
|
|
|
|
|
|
|
INSTALL_DIR = /home/bkubicek/software/arduino-0022
|
|
|
|
|
|
|
|
#~ PORT = /dev/cu.usbserial*
|
|
|
|
|
|
|
|
PORT = /dev/ttyACM0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get these values from:
|
|
|
|
|
|
|
|
# $(INSTALL_DIR)/hardware/boards.txt
|
|
|
|
|
|
|
|
# (arduino-0022/hardware/arduino/boards.txt)
|
|
|
|
|
|
|
|
# The values below are for the "Arduino Duemilanove or Nano w/ ATmega328"
|
|
|
|
|
|
|
|
# now for "Arduino Mega 2560"
|
|
|
|
|
|
|
|
UPLOAD_SPEED = 115200
|
|
|
|
|
|
|
|
UPLOAD_PROTOCOL = stk500v2
|
|
|
|
|
|
|
|
BUILD_MCU = atmega2560
|
|
|
|
|
|
|
|
BUILD_F_CPU = 16000000L
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# getting undefined reference to `__cxa_pure_virtual'
|
|
|
|
|
|
|
|
#~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
|
|
|
|
|
|
|
|
#~ http://www.arduino.cc/playground/OpenBSD/CLI
|
|
|
|
|
|
|
|
#~ [http://arduino.cc/forum/index.php?topic=52041.0 A "simple" makefile for Arduino]
|
|
|
|
|
|
|
|
#~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275488191 Arduino Forum - Configuring avr-gcc options in arduino IDE]
|
|
|
|
|
|
|
|
# found in /usr/lib/gcc/avr/4.3.5/cc1plus; fixed with -Wl,--gc-section
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
# Below here nothing should be changed...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Arduino 0022 Makefile
|
|
|
|
#~ AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
|
|
|
|
# Uno with DOGS102 Shield
|
|
|
|
# in Ubuntu, avr-gcc is installed separate;
|
|
|
|
|
|
|
|
# only avrdude comes with the IDE
|
|
|
|
|
|
|
|
AVR_TOOLS_PATH = /usr/bin
|
|
|
|
|
|
|
|
AVR_DUDE_PATH = $(INSTALL_DIR)/hardware/tools
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# written by olikraus@gmail.com
|
|
|
|
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
|
|
|
|
#
|
|
|
|
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
|
|
|
|
# Features:
|
|
|
|
$(ARDUINO)/wiring_pulse.c \
|
|
|
|
# - boards.txt is used to derive parameters
|
|
|
|
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
|
|
|
|
# - All intermediate files are put into a separate directory (TMPDIRNAME)
|
|
|
|
# added applet/$(TARGET).cpp as in IDE 0022
|
|
|
|
# - Simple use: Copy Makefile into the same directory of the .pde file
|
|
|
|
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
|
|
|
|
#
|
|
|
|
$(ARDUINO)/Print.cpp \
|
|
|
|
# Limitations:
|
|
|
|
$(ARDUINO)/main.cpp
|
|
|
|
# - requires UNIX environment
|
|
|
|
# applet/$(TARGET).cpp # no need, having a rule now for applet/$(TARGET).cpp.o
|
|
|
|
# - TMPDIRNAME must be subdirectory of the current directory.
|
|
|
|
# added main.cpp, as in 0022
|
|
|
|
#
|
|
|
|
FORMAT = ihex
|
|
|
|
# Targets
|
|
|
|
|
|
|
|
# all build everything
|
|
|
|
# Name of this Makefile (used for "make depend").
|
|
|
|
# upload build and upload to arduino
|
|
|
|
MAKEFILE = Makefile
|
|
|
|
# clean remove all temporary files (includes final hex file)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Debugging format.
|
|
|
|
# History
|
|
|
|
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
|
|
|
|
# 001 28 Apr 2010 first release
|
|
|
|
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
|
|
|
|
# 002 05 Oct 2010 added 'uno'
|
|
|
|
DEBUG = stabs
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
OPT = 2
|
|
|
|
#=== user configuration ===
|
|
|
|
|
|
|
|
# All ...PATH variables must have a '/' at the end
|
|
|
|
# Place -D or -U options here
|
|
|
|
|
|
|
|
#~ CDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
|
|
|
|
# Board (and prozessor) information: see $(ARDUINO_PATH)hardware/arduino/boards.txt
|
|
|
|
#~ CXXDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
|
|
|
|
# Some examples:
|
|
|
|
# now called DF_CPU
|
|
|
|
# BOARD DESCRIPTION
|
|
|
|
CDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=22
|
|
|
|
# uno Arduino Uno
|
|
|
|
CXXDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=22
|
|
|
|
# atmega328 Arduino Duemilanove or Nano w/ ATmega328
|
|
|
|
|
|
|
|
# diecimila Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
|
|
|
|
# Place -I options here
|
|
|
|
# mega Arduino Mega
|
|
|
|
CINCS = -I$(ARDUINO) -I$(INSTALL_DIR)/libraries/LiquidCrystal/ -I$(INSTALL_DIR)/libraries/EEPROM/
|
|
|
|
# mini Arduino Mini
|
|
|
|
CXXINCS = -I$(ARDUINO)
|
|
|
|
# lilypad328 LilyPad Arduino w/ ATmega328
|
|
|
|
|
|
|
|
BOARD:=mega
|
|
|
|
# Compiler flag to set the C Standard level.
|
|
|
|
|
|
|
|
# c89 - "ANSI" C
|
|
|
|
# additional (comma separated) defines
|
|
|
|
# gnu89 - c89 plus GCC extensions
|
|
|
|
# -DDOGM128_HW board is connected to DOGM128 display
|
|
|
|
# c99 - ISO C99 standard (not yet fully implemented)
|
|
|
|
# -DDOGM132_HW board is connected to DOGM132 display
|
|
|
|
# gnu99 - c99 plus GCC extensions
|
|
|
|
# -DDOGS102_HW board is connected to DOGS102 display
|
|
|
|
CSTANDARD = -std=gnu99
|
|
|
|
# -DDOG_REVERSE 180 degree rotation
|
|
|
|
CDEBUG = -g$(DEBUG)
|
|
|
|
# -DDOG_SPI_SW_ARDUINO force SW shiftOut
|
|
|
|
# note that typically, IDE 0022 uses -w to suppress warnings (both in cpp and c)!
|
|
|
|
DEFS=-DDOGS102_HW -DDOG_DOUBLE_MEMORY -DDOG_SPI_SW_ARDUINO
|
|
|
|
CWARN = -Wall
|
|
|
|
|
|
|
|
#~ CWARN = -w
|
|
|
|
# The location where the avr tools (e.g. avr-gcc) are located. Requires a '/' at the end.
|
|
|
|
# "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++:
|
|
|
|
# Can be empty if all tools are accessable through the search path
|
|
|
|
CCWARN = -Wstrict-prototypes
|
|
|
|
AVR_TOOLS_PATH:=/usr/bin/
|
|
|
|
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
|
|
|
|
|
|
|
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
|
|
|
|
# Install path of the arduino software. Requires a '/' at the end.
|
|
|
|
|
|
|
|
ARDUINO_PATH:=/home/bkubicek/software/arduino-0022/
|
|
|
|
# to eliminate pins_ardiuno warnings:
|
|
|
|
|
|
|
|
# http://arduino.cc/pipermail/developers_arduino.cc/2010-December/004005.html
|
|
|
|
# Install path for avrdude. Requires a '/' at the end. Can be empty if avrdude is in the search path.
|
|
|
|
|
|
|
|
AVRDUDE_PATH:=
|
|
|
|
# [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
|
|
|
|
|
|
|
|
#~ For building the objects files "-ffunction-sections -fdata-sections" was missing
|
|
|
|
# The unix device where we can reach the arduino board
|
|
|
|
#~ and the final avr-gcc call needs "-Wl,--gc-section".
|
|
|
|
# Uno: /dev/ttyACM0
|
|
|
|
CXSECTF = -fno-exceptions -ffunction-sections -fdata-sections
|
|
|
|
# Duemilanove: /dev/ttyUSB0
|
|
|
|
CFINALF = -Wl,--gc-section
|
|
|
|
AVRDUDE_PORT:=/dev/ttyACM0
|
|
|
|
|
|
|
|
|
|
|
|
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CCWARN) $(CSTANDARD) $(CEXTRA)
|
|
|
|
# List of all libaries which should be included.
|
|
|
|
# added CWARN also to .cpp
|
|
|
|
#EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
|
|
|
|
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CXSECTF)
|
|
|
|
#EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Dogm/
|
|
|
|
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
|
|
|
|
#EXTRA_DIRS+=/home/kraus/src/arduino/dogm128/hg/libraries/Dogm/
|
|
|
|
LDFLAGS = -lm
|
|
|
|
|
|
|
|
|
|
|
|
#=== fetch parameter from boards.txt processor parameter ===
|
|
|
|
# Programming support using avrdude. Settings and variables.
|
|
|
|
# the basic idea is to get most of the information from boards.txt
|
|
|
|
AVRDUDE_PORT = $(PORT)
|
|
|
|
|
|
|
|
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
|
|
|
|
BOARDS_TXT:=$(ARDUINO_PATH)hardware/arduino/boards.txt
|
|
|
|
AVRDUDE_FLAGS = -V -F \
|
|
|
|
|
|
|
|
-p $(BUILD_MCU) -P $(AVRDUDE_PORT) -c $(UPLOAD_PROTOCOL) \
|
|
|
|
# get the MCU value from the $(BOARD).build.mcu variable. For the atmega328 board this is atmega328p
|
|
|
|
-b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avrdude.conf
|
|
|
|
MCU:=$(shell sed -n -e "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_TXT))
|
|
|
|
# -b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf
|
|
|
|
# get the F_CPU value from the $(BOARD).build.f_cpu variable. For the atmega328 board this is 16000000
|
|
|
|
|
|
|
|
F_CPU:=$(shell sed -n -e "s/$(BOARD).build.f_cpu=\(.*\)/\1/p" $(BOARDS_TXT))
|
|
|
|
# Program settings
|
|
|
|
|
|
|
|
CC = $(AVR_TOOLS_PATH)/avr-gcc
|
|
|
|
# avrdude
|
|
|
|
CXX = $(AVR_TOOLS_PATH)/avr-g++
|
|
|
|
# get the AVRDUDE_UPLOAD_RATE value from the $(BOARD).upload.speed variable. For the atmega328 board this is 57600
|
|
|
|
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
|
|
|
|
AVRDUDE_UPLOAD_RATE:=$(shell sed -n -e "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_TXT))
|
|
|
|
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
|
|
|
|
# get the AVRDUDE_PROGRAMMER value from the $(BOARD).upload.protocol variable. For the atmega328 board this is stk500
|
|
|
|
AR = $(AVR_TOOLS_PATH)/avr-ar
|
|
|
|
# AVRDUDE_PROGRAMMER:=$(shell sed -n -e "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_TXT))
|
|
|
|
SIZE = $(AVR_TOOLS_PATH)/avr-size
|
|
|
|
# use stk500v1, because stk500 will default to stk500v2
|
|
|
|
NM = $(AVR_TOOLS_PATH)/avr-nm
|
|
|
|
AVRDUDE_PROGRAMMER:=stk500v1
|
|
|
|
#~ AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
|
|
|
|
|
|
|
|
AVRDUDE = $(AVR_DUDE_PATH)/avrdude
|
|
|
|
#=== identify user files ===
|
|
|
|
REMOVE = rm -f
|
|
|
|
PDESRC:=$(shell ls *.pde)
|
|
|
|
MV = mv -f
|
|
|
|
TARGETNAME=$(basename $(PDESRC))
|
|
|
|
|
|
|
|
|
|
|
|
# Define all object files.
|
|
|
|
CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
|
|
|
|
# NOTE: obj files will be created in respective src directories (libraries or $(INSTALL_DIR));
|
|
|
|
CDIRS:=*.c utility/*.c $(addsuffix *.c,$(CDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.c
|
|
|
|
# make clean deletes them fine
|
|
|
|
CSRC:=$(shell ls $(CDIRS) 2>/dev/null)
|
|
|
|
# note that srcs are in libraries or other directories;
|
|
|
|
|
|
|
|
# $(CXXSRC:.cpp=.o) will cause obj files to be in same loc as src files
|
|
|
|
CCSRC:=$(shell ls *.cc 2>/dev/null)
|
|
|
|
#~ OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
|
|
|
|
|
|
|
|
# to change the output directory for object files;
|
|
|
|
CPPDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
|
|
|
|
# must change the obj list here!
|
|
|
|
CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.cpp
|
|
|
|
# and then, match to corresponding rule somehow?
|
|
|
|
CPPSRC:=$(shell ls $(CPPDIRS) 2>/dev/null)
|
|
|
|
# or leave this - and parse in rule (auth automatic variable $(@F))?
|
|
|
|
|
|
|
|
# "Suffix Replacement"
|
|
|
|
#=== build internal variables ===
|
|
|
|
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
|
|
|
|
|
|
|
|
|
|
|
|
# the name of the subdirectory where everything is stored
|
|
|
|
# added - OBJ list, transformed into applet/
|
|
|
|
TMPDIRNAME:=tmp
|
|
|
|
OBJT = $(addprefix applet/,$(notdir $(OBJ)))
|
|
|
|
TMPDIRPATH:=$(TMPDIRNAME)/
|
|
|
|
ALLSRC = $(SRC) $(CXXSRC) $(ASRC)
|
|
|
|
|
|
|
|
|
|
|
|
AVRTOOLSPATH:=$(AVR_TOOLS_PATH)
|
|
|
|
# Define all listing files.
|
|
|
|
|
|
|
|
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
|
|
|
|
OBJCOPY:=$(AVRTOOLSPATH)avr-objcopy
|
|
|
|
|
|
|
|
OBJDUMP:=$(AVRTOOLSPATH)avr-objdump
|
|
|
|
# Combine all necessary flags and optional flags.
|
|
|
|
SIZE:=$(AVRTOOLSPATH)avr-size
|
|
|
|
# Add target processor to flags.
|
|
|
|
|
|
|
|
ALL_CFLAGS = -mmcu=$(BUILD_MCU) -I. $(CFLAGS)
|
|
|
|
CPPSRC:=$(addprefix $(TMPDIRPATH),$(PDESRC:.pde=.cpp)) $(CPPSRC)
|
|
|
|
ALL_CXXFLAGS = -mmcu=$(BUILD_MCU) -I. $(CXXFLAGS)
|
|
|
|
|
|
|
|
ALL_ASFLAGS = -mmcu=$(BUILD_MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
|
|
|
COBJ:=$(CSRC:.c=.o)
|
|
|
|
|
|
|
|
CCOBJ:=$(CCSRC:.cc=.o)
|
|
|
|
# depended libraries of .pde need to be added from
|
|
|
|
CPPOBJ:=$(CPPSRC:.cpp=.o)
|
|
|
|
# $(INSTALL_DIR)/libraries (TODO: and/or ~/sketchbook/libraries)
|
|
|
|
|
|
|
|
# grep for 'include', test if exists, add...
|
|
|
|
OBJFILES:=$(COBJ) $(CCOBJ) $(CPPOBJ)
|
|
|
|
# note: prefix "a real tab character" http://www.delorie.com/djgpp/doc/ug/larger/makefiles.html
|
|
|
|
DIRS:= $(dir $(OBJFILES))
|
|
|
|
# $$ to escape $ for shell;
|
|
|
|
|
|
|
|
# note: must NOT put comments # inside bash execution;
|
|
|
|
DEPFILES:=$(OBJFILES:.o=.d)
|
|
|
|
# those would get removed by make; making shell see "EOF in backquote substitution"
|
|
|
|
# assembler files from avr-gcc -S
|
|
|
|
# echo $$ix ; \
|
|
|
|
ASSFILES:=$(OBJFILES:.o=.s)
|
|
|
|
# 'shell' twice - for each subprocess! Backtick doesn't get expanded?
|
|
|
|
# disassembled object files with avr-objdump -S
|
|
|
|
GREPRES:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
|
|
|
|
DISFILES:=$(OBJFILES:.o=.dis)
|
|
|
|
if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
|
|
|
|
|
|
|
|
LINCS="$$LINCS -I$(INSTALL_DIR)/libraries/$$ix" ;\
|
|
|
|
|
|
|
|
fi; \
|
|
|
|
LIBNAME:=$(TMPDIRPATH)$(TARGETNAME).a
|
|
|
|
done; \
|
|
|
|
ELFNAME:=$(TMPDIRPATH)$(TARGETNAME).elf
|
|
|
|
echo $$LINCS)
|
|
|
|
HEXNAME:=$(TMPDIRPATH)$(TARGETNAME).hex
|
|
|
|
# append includes:
|
|
|
|
|
|
|
|
CINCS += $(GREPRES)
|
|
|
|
AVRDUDE_FLAGS = -V -F
|
|
|
|
CXXINCS += $(GREPRES)
|
|
|
|
AVRDUDE_FLAGS += -C $(ARDUINO_PATH)/hardware/tools/avrdude.conf
|
|
|
|
# append library source .cpp files too (CXXSRC)
|
|
|
|
AVRDUDE_FLAGS += -p $(MCU)
|
|
|
|
GREPRESB:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
|
|
|
|
AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
|
|
|
|
if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
|
|
|
|
AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER)
|
|
|
|
CPPSRCS="$$CPPSRCS $(INSTALL_DIR)/libraries/$$ix/*.cpp" ;\
|
|
|
|
AVRDUDE_FLAGS += -b $(AVRDUDE_UPLOAD_RATE)
|
|
|
|
fi; \
|
|
|
|
AVRDUDE_FLAGS += -U flash:w:$(HEXNAME)
|
|
|
|
done; \
|
|
|
|
|
|
|
|
echo $$CPPSRCS)
|
|
|
|
AVRDUDE = avrdude
|
|
|
|
CXXSRC += $(GREPRESB)
|
|
|
|
|
|
|
|
# added - only CXX obj from libraries:
|
|
|
|
#=== predefined variable override ===
|
|
|
|
CXXLIBOBJ = $(GREPRESB:.cpp=.o)
|
|
|
|
# use "make -p -f/dev/null" to see the default rules and definitions
|
|
|
|
|
|
|
|
|
|
|
|
# Default target.
|
|
|
|
# Build C and C++ flags. Include path information must be placed here
|
|
|
|
all: applet_files build sizeafter
|
|
|
|
COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DEFS)
|
|
|
|
|
|
|
|
# COMMON_FLAGS += -gdwarf-2
|
|
|
|
build: elf hex
|
|
|
|
COMMON_FLAGS += -Os
|
|
|
|
|
|
|
|
COMMON_FLAGS += -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
|
|
|
applet_files: $(TARGET).pde
|
|
|
|
COMMON_FLAGS += -I.
|
|
|
|
# Here is the "preprocessing".
|
|
|
|
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
|
|
|
|
# It creates a .cpp file based with the same name as the .pde file.
|
|
|
|
COMMON_FLAGS += $(addprefix -I,$(EXTRA_DIRS))
|
|
|
|
# On top of the new .cpp file comes the WProgram.h header.
|
|
|
|
COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
|
|
|
|
# At the end there is a generic main() function attached.
|
|
|
|
COMMON_FLAGS += -Wl,--relax
|
|
|
|
# Then the .cpp file will be compiled. Errors during compile will
|
|
|
|
COMMON_FLAGS += -mcall-prologues
|
|
|
|
# refer to this new, automatically generated, file.
|
|
|
|
|
|
|
|
# Not the original .pde file you actually edit...
|
|
|
|
|
|
|
|
test -d applet || mkdir applet
|
|
|
|
|
|
|
|
# @ supresses printout of the cmdline itself; so only the out of echo is printed
|
|
|
|
|
|
|
|
@echo ALL OBJT: $(OBJT)
|
|
|
|
|
|
|
|
@echo ALL CXXLIBOBJ: $(CXXLIBOBJ)
|
|
|
|
|
|
|
|
# echo '#include "WProgram.h"' > applet/$(TARGET).cpp
|
|
|
|
|
|
|
|
@echo "#include \"WProgram.h\"\nvoid setup();\nvoid loop();\n" > applet/$(TARGET).cpp
|
|
|
|
|
|
|
|
cat $(TARGET).pde >> applet/$(TARGET).cpp
|
|
|
|
|
|
|
|
# no more need to cat main.cpp (v0022) - now it is compiled in
|
|
|
|
|
|
|
|
# cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elf: applet/$(TARGET).elf
|
|
|
|
|
|
|
|
hex: applet/$(TARGET).hex
|
|
|
|
|
|
|
|
eep: applet/$(TARGET).eep
|
|
|
|
|
|
|
|
lss: applet/$(TARGET).lss
|
|
|
|
|
|
|
|
sym: applet/$(TARGET).sym
|
|
|
|
|
|
|
|
|
|
|
|
CFLAGS = $(COMMON_FLAGS) -std=gnu99 -Wstrict-prototypes
|
|
|
|
# Program the device.
|
|
|
|
CXXFLAGS = $(COMMON_FLAGS)
|
|
|
|
upload: applet/$(TARGET).hex
|
|
|
|
|
|
|
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
|
|
|
# Replace standard build tools by avr tools
|
|
|
|
|
|
|
|
CC = $(AVRTOOLSPATH)avr-gcc
|
|
|
|
|
|
|
|
CXX = $(AVRTOOLSPATH)avr-g++
|
|
|
|
|
|
|
|
AR = @$(AVRTOOLSPATH)avr-ar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# "rm" must be able to delete a directory tree
|
|
|
|
|
|
|
|
RM = rm -rf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#=== rules ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# add rules for the C/C++ files where the .o file is placed in the TMPDIRPATH
|
|
|
|
|
|
|
|
# reuse existing variables as far as possible
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.o: %.c
|
|
|
|
|
|
|
|
@echo compile $<
|
|
|
|
|
|
|
|
@$(COMPILE.c) $(OUTPUT_OPTION) $<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.o: %.cc
|
|
|
|
|
|
|
|
@echo compile $<
|
|
|
|
|
|
|
|
@$(COMPILE.cc) $(OUTPUT_OPTION) $<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.o: %.cpp
|
|
|
|
# Display size of file.
|
|
|
|
@echo compile $<
|
|
|
|
HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
|
|
|
|
@$(COMPILE.cpp) $(OUTPUT_OPTION) $<
|
|
|
|
ELFSIZE = $(SIZE) applet/$(TARGET).elf
|
|
|
|
|
|
|
|
sizebefore:
|
|
|
|
|
|
|
|
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.s: %.c
|
|
|
|
sizeafter:
|
|
|
|
@$(COMPILE.c) $(OUTPUT_OPTION) -S $<
|
|
|
|
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.s: %.cc
|
|
|
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
|
|
|
@$(COMPILE.cc) $(OUTPUT_OPTION) -S $<
|
|
|
|
COFFCONVERT=$(OBJCOPY) --debugging \
|
|
|
|
|
|
|
|
--change-section-address .data-0x800000 \
|
|
|
|
|
|
|
|
--change-section-address .bss-0x800000 \
|
|
|
|
|
|
|
|
--change-section-address .noinit-0x800000 \
|
|
|
|
|
|
|
|
--change-section-address .eeprom-0x810000
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.s: %.cpp
|
|
|
|
coff: applet/$(TARGET).elf
|
|
|
|
@$(COMPILE.cpp) $(OUTPUT_OPTION) -S $<
|
|
|
|
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.dis: $(TMPDIRPATH)%.o
|
|
|
|
extcoff: $(TARGET).elf
|
|
|
|
@$(OBJDUMP) -S $< > $@
|
|
|
|
$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
|
|
|
|
|
|
|
|
|
|
|
|
.SUFFIXES: .elf .hex .pde
|
|
|
|
.SUFFIXES: .elf .hex .eep .lss .sym
|
|
|
|
|
|
|
|
|
|
|
|
.elf.hex:
|
|
|
|
.elf.hex:
|
|
|
|
@$(OBJCOPY) -O ihex -R .eeprom $< $@
|
|
|
|
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.cpp: %.pde
|
|
|
|
.elf.eep:
|
|
|
|
@cat $(ARDUINO_PATH)hardware/arduino/cores/arduino/main.cpp > $@
|
|
|
|
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
|
|
|
@cat $< >> $@
|
|
|
|
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
|
|
|
@echo >> $@
|
|
|
|
|
|
|
|
@echo 'extern "C" void __cxa_pure_virtual() { while (1); }' >> $@
|
|
|
|
# Create extended listing file from ELF output file.
|
|
|
|
|
|
|
|
.elf.lss:
|
|
|
|
|
|
|
|
$(OBJDUMP) -h -S $< > $@
|
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
all: tmpdir $(HEXNAME) assemblersource showsize
|
|
|
|
# Create a symbol table from ELF output file.
|
|
|
|
ls -al $(HEXNAME) $(ELFNAME)
|
|
|
|
.elf.sym:
|
|
|
|
|
|
|
|
$(NM) -n $< > $@
|
|
|
|
$(ELFNAME): $(LIBNAME)($(addprefix $(TMPDIRPATH),$(OBJFILES)))
|
|
|
|
|
|
|
|
$(LINK.o) $(COMMON_FLAGS) $(LIBNAME) $(LOADLIBES) $(LDLIBS) -o $@
|
|
|
|
# Link: create ELF output file from library.
|
|
|
|
|
|
|
|
# NOTE: applet/$(TARGET).cpp.o MUST BE BEFORE applet/core.a
|
|
|
|
$(LIBNAME)(): $(addprefix $(TMPDIRPATH),$(OBJFILES))
|
|
|
|
# in the dependency list, so its rule runs first!
|
|
|
|
|
|
|
|
applet/$(TARGET).elf: $(TARGET).pde applet/$(TARGET).cpp.o applet/core.a
|
|
|
|
#=== create temp directory ===
|
|
|
|
# $(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
|
|
|
|
# not really required, because it will be also created during the dependency handling
|
|
|
|
# changed as in IDE v0022: link cpp obj files
|
|
|
|
.PHONY: tmpdir
|
|
|
|
@echo $$(tput bold)$$(tput setaf 2) $(CC) $$(tput sgr0) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
|
|
|
|
tmpdir:
|
|
|
|
@$(CC) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
|
|
|
|
@test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH)
|
|
|
|
|
|
|
|
|
|
|
|
# added: cpp.o depends on cpp (and .pde which generates it)
|
|
|
|
#=== create assembler files for each C/C++ file ===
|
|
|
|
# $< "first item in the dependencies list"; $@ "left side of the :"; $^ "right side of the :"
|
|
|
|
.PHONY: assemblersource
|
|
|
|
# http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
|
|
|
|
assemblersource: $(addprefix $(TMPDIRPATH),$(ASSFILES)) $(addprefix $(TMPDIRPATH),$(DISFILES))
|
|
|
|
applet/$(TARGET).cpp.o: applet/$(TARGET).cpp
|
|
|
|
|
|
|
|
@echo $$(tput bold) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $< -o $@
|
|
|
|
|
|
|
|
@$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
|
|
|
|
#=== show the section sizes of the ELF file ===
|
|
|
|
|
|
|
|
.PHONY: showsize
|
|
|
|
#~ applet/core.a: $(OBJ)
|
|
|
|
showsize: $(ELFNAME)
|
|
|
|
#~ @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
|
|
|
|
$(SIZE) $<
|
|
|
|
|
|
|
|
|
|
|
|
applet/core.a: $(OBJT)
|
|
|
|
#=== clean up target ===
|
|
|
|
@for i in $(OBJT); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
|
|
|
|
# this is simple: the TMPDIRPATH is removed
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
# iterate through OBJ to find the original location; then build depending on source extension
|
|
|
|
|
|
|
|
# TODO: add handling of assembler files
|
|
|
|
|
|
|
|
applet/%.o:
|
|
|
|
|
|
|
|
@for iob in $(OBJ); do \
|
|
|
|
|
|
|
|
if [ "`basename $$iob`" = "`basename $@`" ]; then \
|
|
|
|
|
|
|
|
for ios in $(ALLSRC); do \
|
|
|
|
|
|
|
|
if [ "$${iob%%.*}" = "$${ios%%.*}" ]; then \
|
|
|
|
|
|
|
|
case $${ios##*.} in \
|
|
|
|
|
|
|
|
"cpp") \
|
|
|
|
|
|
|
|
echo "$$(tput bold)$$(tput setaf 1) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $$ios -o $@"; \
|
|
|
|
|
|
|
|
$(CXX) -c $(ALL_CXXFLAGS) $$ios -o $@;; \
|
|
|
|
|
|
|
|
"c") \
|
|
|
|
|
|
|
|
echo "$$(tput bold)$$(tput setaf 1) $(CC) $$(tput sgr0) -c $(ALL_CFLAGS) $$ios -o $@"; \
|
|
|
|
|
|
|
|
$(CC) -c $(ALL_CFLAGS) $$ios -o $@;; \
|
|
|
|
|
|
|
|
esac; \
|
|
|
|
|
|
|
|
fi; \
|
|
|
|
|
|
|
|
done; \
|
|
|
|
|
|
|
|
fi; \
|
|
|
|
|
|
|
|
done;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ # Compile: create object files from C++ source files.
|
|
|
|
|
|
|
|
#~ .cpp.o:
|
|
|
|
|
|
|
|
#~ $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ # Compile: create object files from C source files.
|
|
|
|
|
|
|
|
#~ .c.o:
|
|
|
|
|
|
|
|
#~ $(CC) -c $(ALL_CFLAGS) $< -o $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ # Compile: create assembler files from C source files.
|
|
|
|
|
|
|
|
#~ .c.s:
|
|
|
|
|
|
|
|
#~ $(CC) -S $(ALL_CFLAGS) $< -o $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ # Assemble: create object files from assembler source files.
|
|
|
|
|
|
|
|
#~ .S.o:
|
|
|
|
|
|
|
|
#~ $(CC) -c $(ALL_ASFLAGS) $< -o $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ # Automatic dependencies
|
|
|
|
|
|
|
|
#~ %.d: %.c
|
|
|
|
|
|
|
|
#~ $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#~ %.d: %.cpp
|
|
|
|
|
|
|
|
#~ $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Target: clean project.
|
|
|
|
clean:
|
|
|
|
clean:
|
|
|
|
$(RM) $(TMPDIRPATH)
|
|
|
|
$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
|
|
|
|
|
|
|
|
applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
|
|
|
|
# Program the device.
|
|
|
|
$(OBJT) applet/$(TARGET).cpp.o \
|
|
|
|
# step 1: reset the arduino board with the stty command
|
|
|
|
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
|
|
|
|
# step 2: user avrdude to upload the software
|
|
|
|
|
|
|
|
.PHONY: upload
|
|
|
|
|
|
|
|
upload: $(HEXNAME)
|
|
|
|
|
|
|
|
stty -F $(AVRDUDE_PORT) hupcl
|
|
|
|
|
|
|
|
$(AVRDUDE) $(AVRDUDE_FLAGS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# === dependency handling ===
|
|
|
|
|
|
|
|
# From the gnu make manual (section 4.14, Generating Prerequisites Automatically)
|
|
|
|
|
|
|
|
# Additionally (because this will be the first executed rule) TMPDIRPATH is created here.
|
|
|
|
|
|
|
|
# Instead of "sed" the "echo" command is used
|
|
|
|
|
|
|
|
# cd $(TMPDIRPATH); mkdir -p $(DIRS) 2> /dev/null; cd ..
|
|
|
|
|
|
|
|
DEPACTION=test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH);\
|
|
|
|
|
|
|
|
mkdir -p $(addprefix $(TMPDIRPATH),$(DIRS));\
|
|
|
|
|
|
|
|
set -e; echo -n $@ $(dir $@) > $@; $(CC) -MM $(COMMON_FLAGS) $< >> $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.d: %.c
|
|
|
|
|
|
|
|
@$(DEPACTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.d: %.cc
|
|
|
|
|
|
|
|
@$(DEPACTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(TMPDIRPATH)%.d: %.cpp
|
|
|
|
|
|
|
|
@$(DEPACTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Include dependency files. If a .d file is missing, a warning is created and the .d file is created
|
|
|
|
|
|
|
|
# This warning is not a problem (gnu make manual, section 3.3 Including Other Makefiles)
|
|
|
|
|
|
|
|
-include $(addprefix $(TMPDIRPATH),$(DEPFILES))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter
|
|
|
|