Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new Makefile and Makefile.targets added, based on the template

  • Loading branch information...
commit b8a78b4c5c72959aa69fcb2fdc8be9d088d67aea 1 parent 6d7b5cf
@joaopizani authored
Showing with 338 additions and 0 deletions.
  1. +108 −0 Makefile
  2. +230 −0 Makefile.targets
View
108 Makefile
@@ -0,0 +1,108 @@
+######### AVR Project Makefile Template #########
+###### Copyright (C) 2003-2005,Pat Deegan, ######
+###### Psychogenic Inc ######
+###### All Rights Reserved ######
+###### ######
+###### You are free to use this code as part ######
+###### of your own applications provided ######
+###### you keep this copyright notice intact ######
+###### and acknowledge its authorship with ######
+###### the words: ######
+###### ######
+###### "Contains software by Pat Deegan of ######
+###### Psychogenic Inc (www.psychogenic.com)" ######
+###### ######
+###### If you use it as part of a web site ######
+###### please include a link to our site, ######
+###### http://electrons.psychogenic.com or ######
+###### http://www.psychogenic.com ######
+####################################################
+
+## With heavy modifications to suit Arduino's oddities related to
+## bootloader and programmer, and also including the option to generate
+## and install a static library (.a archive) from this same Makefile.
+##
+## This makefile includes two targets for simulation using simulavr:
+## The first target (simulate-gdb) will run your program with simulavr as
+## an AVR-GDB server and imeediately launch and connect AVR-GDB to it.
+## The second target (simulate-vcd) allows you to run your program under
+## simulavr and collect waveform traces in VCD format for later analysis.
+##
+## These modifications were done by
+##
+## João Paulo Pizani Flor <joaopizani@gmail.com>
+## http://joaopizani.hopto.org
+
+##### Target Specific Details
+##### Customize these for your project
+
+# Name of target controller
+# (e.g. 'at90s8515', see avr-gcc's mmcu options for possible values)
+MCU=atmega168 # This is the MCU of Arduino Duemilanove
+
+# target controller clock frequency in Hz
+MCU_FREQ=16000000 # This is Arduino Duemilanove's freq
+
+# id to use with programmer - default: PROGRAMMER_MCU=$(MCU)
+PROGRAMMER_MCU=$(MCU)
+
+# Name of our project - (use a single word, e.g. 'myproject')
+PROJECTNAME=avr-utils
+
+# Set LIBRARY if the project is a static lib, leave undefined otherwise
+LIBRARY=1
+
+# Source files. Space-separated list C/C++/Assembly source files:
+PRJSRC=src/timers-atmega168.c \
+ src/timers-atmega168p.c \
+ src/assert_helpers.c \
+ src/sim_debug.c
+
+# Header files of the project. They will be installed in the case of a lib.
+PRJHEADERS=src/timers-atmega168.h \
+ src/timers-atmega168p.h \
+ src/assert_helpers.h \
+ src/sim_debug.h
+
+# additional includes and libraries to link in are defined in paths.def
+include paths.def
+INC=${EXT_INCFLAGS}
+LIBS=${EXT_LIBFLAGS}
+
+# additional macro definition flags
+EXT_DEFS=
+
+# Optimization level - use s (size opt), 1, 2, 3 or 0 (off)
+OPTLEVEL=1
+
+
+##### AVR Dude 'writeflash' options
+AVRDUDE_PROGRAMMERID=arduino
+AVRDUDE_PORT=/dev/ttyUSB0
+AVRDUDE_BAUD=-b 19200 # 19200 baud for Arduino Duemilanove
+
+
+##### Simulation options. Change only what you think is necessary
+SIM_MCU=$(PROGRAMMER_MCU)
+SIM_EXIT_ADDR=0xDE
+SIM_WRITE_ADDR=0xFF
+SIM_READ_ADDR=0xFE
+
+#### Leave these undefined if you want to accept the defaults. Defaults are:
+#### SIM_TIME=200 (ms), SIM_DIR=sim, SIM_TRACES=$(SIM_DIR)/traces-selected
+SIM_TIME=
+SIM_DIR=
+SIM_TRACES=
+
+
+####################################################
+##### Config Done #####
+##### #####
+##### Now include non-variable definitions #####
+##### and the make targets themselves, which #####
+##### are in Makefile.targets #####
+##### #####
+####################################################
+
+include Makefile.targets
+
View
230 Makefile.targets
@@ -0,0 +1,230 @@
+####################################################
+##### #####
+##### You shouldn't need to edit anything #####
+##### below to use the makefile but may wish #####
+##### to override a few of the flags #####
+##### nonetheless #####
+##### #####
+####################################################
+
+##### Macro definitions, CPU frequency and simulation virtual I/O
+DEFS=-DF_CPU=$(MCU_FREQ) \
+ -DSIM_WRITE="(*((volatile char *) $(SIM_WRITE_ADDR)))" \
+ -DSIM_READ="(*((volatile char *) $(SIM_READ_ADDR)))" \
+ -DSIM_EXIT="(*((volatile char *) $(SIM_EXIT_ADDR)))"
+
+
+##### Simulation definitions
+ifndef SIM_DIR
+SIM_DIR=sim
+endif
+
+SIM_STDOUT_FILENAME=$(PROJECTNAME)-sim-stdout.txt
+SIM_STDERR_FILENAME=$(PROJECTNAME)-sim-stderr.txt
+SIM_WAVES_FILENAME=$(PROJECTNAME)-wav.vcd
+SIM_TRACES_FILENAME=$(PROJECTNAME)-traces
+
+ifndef SIM_TRACES
+SIM_TRACES=$(SIM_DIR)/$(SIM_TRACES_FILENAME)
+endif
+
+ifndef SIM_TIME
+SIM_TIME=200
+endif
+
+SIM_STDOUT=$(SIM_DIR)/$(SIM_STDOUT_FILENAME)
+SIM_STDERR=$(SIM_DIR)/$(SIM_STDERR_FILENAME)
+SIM_WAVES=$(SIM_DIR)/$(SIM_WAVES_FILENAME)
+
+
+##### Executables
+CC=avr-gcc
+AR=avr-ar
+OBJCOPY=avr-objcopy
+OBJDUMP=avr-objdump
+SIZE=avr-size
+AVRDUDE=avrdude
+REMOVE=rm -f
+
+
+##### Compiler, linker, assembler, archiver flags
+# HEXFORMAT -- format for .hex file output
+HEXFORMAT=ihex
+
+# compiler flags
+CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
+ -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char \
+ -Wall -Wstrict-prototypes -Wa,-ahlms=$(firstword $(filter %.lst, $(<:.c=.lst))) \
+ $(DEFS)
+
+# c++ specific flags
+CPPFLAGS=-fno-exceptions \
+ -Wa,-ahlms=$(firstword \
+ $(filter %.lst, $(<:.cpp=.lst)) \
+ $(filter %.lst, $(<:.cc=.lst)) \
+ $(filter %.lst, $(<:.C=.lst)))
+
+# assembler flags
+ASMFLAGS =-I. $(INC) -mmcu=$(MCU) -x assembler-with-cpp \
+ -Wa,-gstabs,-ahlms=$(firstword $(<:.S=.lst) $(<.s=.lst))
+
+# linker flags
+LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) -lm $(LIBS)
+
+# static library archiver (ar) flags
+ARFLAGS=cqs
+
+
+
+##### Automatic target names
+DUMPTRG=$(PROJECTNAME).s
+HEXROMTRG=$(PROJECTNAME).hex
+HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex
+GDBINITFILE=gdbinit-$(PROJECTNAME)
+INSTALL_PREFIX=$(PREFIX)
+INCLUDE_PREFIX=$(INSTALL_PREFIX)/include/$(PROJECTNAME)
+LIB_PREFIX=$(INSTALL_PREFIX)/lib/$(PROJECTNAME)
+
+EXETRG=$(PROJECTNAME).out
+LIBTRG=lib$(PROJECTNAME).a
+ifdef LIBRARY
+ TRG=$(LIBTRG)
+else
+ TRG=$(EXETRG)
+endif
+
+
+
+##### Define all object files.
+# Start by splitting source files by type
+CPPFILES=$(filter %.cpp, $(PRJSRC))
+CCFILES=$(filter %.cc, $(PRJSRC))
+BIGCFILES=$(filter %.C, $(PRJSRC))
+CFILES=$(filter %.c, $(PRJSRC))
+ASMFILES=$(filter %.S, $(PRJSRC))
+
+# List all object files we need to create
+OBJDEPS=$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(BIGCFILES:.C=.o) $(CCFILES:.cc=.o) $(ASMFILES:.S=.o)
+
+# Define all lst files.
+LST=$(filter %.lst, $(OBJDEPS:.o=.lst))
+
+# All the possible generated assembly files (.s files)
+GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))
+
+
+
+##### Enough definitions, now the make stuff
+.SUFFIXES : .c .cc .cpp .C .o .out .s .S .hex .ee.hex .h .hh .hpp
+.PHONY: writeflash install clean stats gdbinit
+
+# Make targets:
+# all, disasm, stats, hex, writeflash, install, clean, simulate-{gdb,vcd}
+all: $(TRG)
+
+disasm: $(DUMPTRG) stats
+
+stats: $(TRG)
+ $(OBJDUMP) -h $(TRG)
+ $(SIZE) $(TRG)
+
+hex: $(HEXTRG)
+
+writeflash: hex
+ $(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) -p $(PROGRAMMER_MCU) \
+ -P $(AVRDUDE_PORT) -e $(AVRDUDE_BAUD) -U flash:w:$(HEXROMTRG)
+
+install: $(LIBTRG)
+ install -d $(LIB_PREFIX)
+ install $(LIBTRG) $(LIB_PREFIX)
+ifdef PRJHEADERS
+ install -d $(INCLUDE_PREFIX)
+ install $(PRJHEADERS) $(INCLUDE_PREFIX)
+endif
+
+###### Generating the targets
+$(DUMPTRG): $(TRG)
+ $(OBJDUMP) -S $< > $@
+
+$(EXETRG): $(OBJDEPS)
+ $(CC) -o $(TRG) $(OBJDEPS) $(LDFLAGS)
+
+$(LIBTRG): $(OBJDEPS)
+ $(REMOVE) $@
+ $(AR) $(ARFLAGS) $@ $(OBJDEPS)
+
+###### Generating intermediary files
+# asm from C
+%.s: %.c
+ $(CC) -S $(CFLAGS) $< -o $@
+
+# asm from (hand coded) asm
+%.s: %.S
+ $(CC) -S $(ASMFLAGS) $< > $@
+
+# asm from C++
+.cpp.s .cc.s .C.s :
+ $(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@
+
+# object from C
+.c.o:
+ $(CC) $(CFLAGS) -c $< -o $@
+
+# object from C++ (.cc, .cpp, .C files)
+.cc.o .cpp.o .C.o :
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+# object from asm
+.S.o :
+ $(CC) $(ASMFLAGS) -c $< -o $@
+
+###### Generating hex files
+.out.hex:
+ $(OBJCOPY) -j .text -j .data -O $(HEXFORMAT) $< $@
+
+.out.ee.hex:
+ $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O $(HEXFORMAT) $< $@
+
+
+###### Generating a gdb initialisation file
+gdbinit: $(GDBINITFILE)
+
+$(GDBINITFILE): $(EXETRG)
+ @echo "file $(EXETRG)" > $(GDBINITFILE)
+ @echo "target remote localhost:1212" \
+ >> $(GDBINITFILE)
+ @echo "load" >> $(GDBINITFILE)
+ @echo "break main" >> $(GDBINITFILE)
+ @echo "continue" >> $(GDBINITFILE)
+ @echo
+ @echo "Use 'avr-gdb -x $(GDBINITFILE)'"
+
+
+###### Simulation targets, using simulavr and (possibly) avr-gdb
+simulate-gdb: $(GDBINITFILE)
+ mkdir -p $(SIM_DIR)
+ simulavr -d $(SIM_MCU) -F $(MCU_FREQ) -f $(EXETRG) \
+ -W $(SIM_WRITE_ADDR),- -R $(SIM_READ_ADDR),- -e $(SIM_EXIT_ADDR) \
+ -g 2> $(SIM_STDERR) 1> $(SIM_STDOUT) &
+ @sleep 1
+ avr-gdbtui -x $(GDBINITFILE)
+
+simulate-vcd: $(EXETRG)
+ mkdir -p $(SIM_DIR)
+ simulavr -d $(SIM_MCU) -F $(MCU_FREQ) -f $(EXETRG) \
+ -W $(SIM_WRITE_ADDR),- -R $(SIM_READ_ADDR),- -e $(SIM_EXIT_ADDR) \
+ -c vcd:$(SIM_TRACES):$(SIM_WAVES) -m $(SIM_TIME)000000
+
+
+
+##### Cleanup
+clean:
+ $(REMOVE) $(LIBTRG) $(LIBTRG).map
+ $(REMOVE) $(EXETRG) $(EXETRG).map $(DUMPTRG)
+ $(REMOVE) $(OBJDEPS)
+ $(REMOVE) $(LST) $(GDBINITFILE)
+ $(REMOVE) $(GENASMFILES)
+ $(REMOVE) $(HEXTRG)
+ $(REMOVE) $(SIM_STDOUT) $(SIM_STDERR) $(SIM_WAVES)
+ $(REMOVE) *~
+
Please sign in to comment.
Something went wrong with that request. Please try again.