ArduinoAm29F010

Annotated Makefile

25:d6482c4f3bb2
2015-03-09 Paul Boddie Added software notes, Dual ROM Adaptor wiring details, and moved the Arduino interfacing details above the general technical notes.
paul@2 1
TARGET = $(notdir $(CURDIR))
paul@2 2
INSTALL_DIR = ../arduino-1.0.5
paul@2 3
PORT = /dev/ttyUSB0
paul@2 4
UPLOAD_RATE = 57600 # 19200
paul@2 5
AVRDUDE_PROGRAMMER = stk500v1
paul@2 6
MCU = atmega328p # atmega168
paul@2 7
F_CPU = 16000000
paul@2 8
paul@2 9
EXTRA_SRC =
paul@2 10
EXTRA_CXXSRC =
paul@2 11
EXTRA_CINCS =
paul@2 12
EXTRA_CXXINCS =
paul@2 13
paul@2 14
paul@2 15
### Internal definitions.
paul@2 16
paul@2 17
paul@2 18
ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
paul@2 19
VARIANT = $(INSTALL_DIR)/hardware/arduino/variants/standard
paul@2 20
SRC = $(ARDUINO)/wiring.c \
paul@2 21
	$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
paul@2 22
	$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_shift.c \
paul@2 23
	$(ARDUINO)/WInterrupts.c $(EXTRA_SRC)
paul@2 24
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
paul@2 25
	$(ARDUINO)/Print.cpp $(ARDUINO)/WString.cpp \
paul@2 26
	$(ARDUINO)/Stream.cpp $(EXTRA_CXXSRC)
paul@2 27
FORMAT = ihex
paul@2 28
paul@2 29
# Name of this Makefile (used for "make depend").
paul@2 30
MAKEFILE = Makefile
paul@2 31
paul@2 32
# Debugging format.
paul@2 33
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
paul@2 34
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
paul@2 35
DEBUG = stabs
paul@2 36
paul@2 37
# Place -D or -U options here
paul@2 38
CDEFS = -DF_CPU=$(F_CPU)
paul@2 39
CXXDEFS = -DF_CPU=$(F_CPU)
paul@2 40
paul@2 41
# Place -I options here
paul@2 42
CINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CINCS)
paul@2 43
CXXINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CXXINCS)
paul@2 44
paul@2 45
# Compiler flag to set the C Standard level.
paul@2 46
# c89   - "ANSI" C
paul@2 47
# gnu89 - c89 plus GCC extensions
paul@2 48
# c99   - ISO C99 standard (not yet fully implemented)
paul@2 49
# gnu99 - c99 plus GCC extensions
paul@2 50
CSTANDARD = -std=gnu99
paul@2 51
CDEBUG = -g$(DEBUG)
paul@2 52
CWARN = -Wall -Wstrict-prototypes
paul@2 53
paul@2 54
OPT = s
paul@2 55
paul@2 56
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
paul@2 57
CXXFLAGS = $(CXXDEFS) $(CXXINCS) -O$(OPT)
paul@2 58
LDFLAGS = -lm
paul@2 59
paul@2 60
# Combine all necessary flags and optional flags.
paul@2 61
# Add target processor to flags.
paul@2 62
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
paul@2 63
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
paul@2 64
paul@2 65
# Programming support using avrdude. Settings and variables.
paul@2 66
AVRDUDE_PORT = $(PORT)
paul@2 67
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
paul@2 68
AVRDUDE_FLAGS = -V -F -C /etc/avrdude.conf \
paul@2 69
	-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
paul@2 70
	-b $(UPLOAD_RATE)
paul@2 71
paul@2 72
# Program settings
paul@2 73
CC = avr-gcc
paul@2 74
CXX = avr-g++
paul@2 75
LD = avr-ld
paul@2 76
OBJCOPY = avr-objcopy
paul@2 77
OBJDUMP = avr-objdump
paul@2 78
AR  = avr-ar
paul@2 79
SIZE = avr-size
paul@2 80
NM = avr-nm
paul@2 81
AVRDUDE = avrdude
paul@2 82
REMOVE = rm -f
paul@2 83
MV = mv -f
paul@2 84
paul@2 85
# Define all object files.
paul@2 86
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o)
paul@2 87
paul@2 88
# Default target.
paul@2 89
all: applet_files build sizeafter
paul@2 90
paul@2 91
build: elf hex
paul@2 92
paul@2 93
applet_files: $(TARGET).cpp
paul@2 94
	test -d applet || mkdir applet
paul@2 95
	cat $(ARDUINO)/main.cpp > applet/$(TARGET).cpp
paul@2 96
	cat $(TARGET).cpp >> applet/$(TARGET).cpp
paul@2 97
paul@2 98
elf: applet/$(TARGET).elf
paul@2 99
hex: applet/$(TARGET).hex
paul@2 100
paul@2 101
# Program the device.
paul@2 102
upload: applet/$(TARGET).hex
paul@2 103
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
paul@2 104
paul@2 105
# Display size of file.
paul@2 106
HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
paul@2 107
ELFSIZE = $(SIZE) applet/$(TARGET).elf
paul@2 108
paul@2 109
sizebefore:
paul@2 110
	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
paul@2 111
paul@2 112
sizeafter:
paul@2 113
	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
paul@2 114
paul@2 115
paul@2 116
### File-specific processing.
paul@2 117
paul@2 118
paul@2 119
.SUFFIXES: .elf .hex .eep .lss .sym
paul@2 120
paul@2 121
.elf.hex:
paul@2 122
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
paul@2 123
paul@2 124
applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a
paul@2 125
	$(CXX) $(ALL_CXXFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
paul@2 126
paul@2 127
applet/core.a: $(OBJ)
paul@2 128
	@for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
paul@2 129
paul@2 130
# Compile: create object files from C++ source files.
paul@2 131
.cpp.o:
paul@2 132
	$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
paul@2 133
paul@2 134
# Compile: create object files from C source files.
paul@2 135
.c.o:
paul@2 136
	$(CC) -c $(ALL_CFLAGS) $< -o $@
paul@2 137
paul@2 138
# Target: clean project.
paul@2 139
clean:
paul@2 140
	$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).elf applet/$(TARGET).cpp \
paul@2 141
	applet/$(TARGET).map applet/core.a $(OBJ)
paul@2 142
paul@2 143
.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter