Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Forgot the makefile!

  • Loading branch information...
commit c1f8f1bc6bf325dc8315eb58f7d9aa3ba54f2dd3 1 parent 759dcfb
Limor "Ladyada" Fried ladyada authored

Showing 1 changed file with 434 additions and 0 deletions. Show diff stats Hide diff stats

  1. +434 0 firmware/Makefile
434 firmware/Makefile
... ... @@ -0,0 +1,434 @@
  1 +# Hey Emacs, this is a -*- makefile -*-
  2 +#
  3 +# WinAVR Sample makefile written by Eric B. Weddington, J�rg Wunsch, et al.
  4 +# Released to the Public Domain
  5 +# Please read the make user manual!
  6 +#
  7 +# Additional material for this makefile was submitted by:
  8 +# Tim Henigan
  9 +# Peter Fleury
  10 +# Reiner Patommel
  11 +# Sander Pool
  12 +# Frederik Rouleau
  13 +# Markus Pfaff
  14 +#
  15 +# On command line:
  16 +#
  17 +# make all = Make software.
  18 +#
  19 +# make clean = Clean out built project files.
  20 +#
  21 +# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
  22 +#
  23 +# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  24 +# 4.07 or greater).
  25 +#
  26 +# make program = Download the hex file to the device, using avrdude. Please
  27 +# customize the avrdude settings below first!
  28 +#
  29 +# make filename.s = Just compile filename.c into the assembler code only
  30 +#
  31 +# To rebuild project do "make clean" then "make all".
  32 +#
  33 +
  34 +
  35 +# MCU name
  36 +MCU = atmega48
  37 +
  38 +# Output format. (can be srec, ihex, binary)
  39 +FORMAT = ihex
  40 +
  41 +# Target file name (without extension).
  42 +TARGET = life
  43 +
  44 +
  45 +# List C source files here. (C dependencies are automatically generated.)
  46 +SRC = $(TARGET).c
  47 +
  48 +
  49 +# List Assembler source files here.
  50 +# Make them always end in a capital .S. Files ending in a lowercase .s
  51 +# will not be considered source files but generated files (assembler
  52 +# output from the compiler), and will be deleted upon "make clean"!
  53 +# Even though the DOS/Win* filesystem matches both .s and .S the same,
  54 +# it will preserve the spelling of the filenames, and gcc itself does
  55 +# care about how the name is spelled on its command-line.
  56 +ASRC =
  57 +
  58 +
  59 +
  60 +# Optimization level, can be [0, 1, 2, 3, s].
  61 +# 0 = turn off optimization. s = optimize for size.
  62 +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  63 +OPT = s
  64 +
  65 +# Debugging format.
  66 +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  67 +# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  68 +DEBUG = stabs
  69 +
  70 +# List any extra directories to look for include files here.
  71 +# Each directory must be seperated by a space.
  72 +EXTRAINCDIRS =
  73 +
  74 +
  75 +# Compiler flag to set the C Standard level.
  76 +# c89 - "ANSI" C
  77 +# gnu89 - c89 plus GCC extensions
  78 +# c99 - ISO C99 standard (not yet fully implemented)
  79 +# gnu99 - c99 plus GCC extensions
  80 +CSTANDARD = -std=gnu99
  81 +
  82 +# Place -D or -U options here
  83 +CDEFS =
  84 +
  85 +# Place -I options here
  86 +CINCS =
  87 +
  88 +
  89 +# Compiler flags.
  90 +# -g*: generate debugging information
  91 +# -O*: optimization level
  92 +# -f...: tuning, see GCC manual and avr-libc documentation
  93 +# -Wall...: warning level
  94 +# -Wa,...: tell GCC to pass this to the assembler.
  95 +# -adhlns...: create assembler listing
  96 +#CFLAGS = -g$(DEBUG)
  97 +CFLAGS += $(CDEFS) $(CINCS)
  98 +CFLAGS += -O$(OPT)
  99 +CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  100 +CFLAGS += -Wall -Wstrict-prototypes
  101 +CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  102 +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  103 +CFLAGS += $(CSTANDARD)
  104 +
  105 +
  106 +
  107 +# Assembler flags.
  108 +# -Wa,...: tell GCC to pass this to the assembler.
  109 +# -ahlms: create listing
  110 +# -gstabs: have the assembler create line number information; note that
  111 +# for use in COFF files, additional information about filenames
  112 +# and function names needs to be present in the assembler source
  113 +# files -- see avr-libc docs [FIXME: not yet described there]
  114 +ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  115 +
  116 +
  117 +
  118 +#Additional libraries.
  119 +
  120 +# Minimalistic printf version
  121 +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  122 +
  123 +# Floating point printf version (requires MATH_LIB = -lm below)
  124 +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  125 +
  126 +PRINTF_LIB =
  127 +
  128 +# Minimalistic scanf version
  129 +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  130 +
  131 +# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  132 +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  133 +
  134 +SCANF_LIB =
  135 +
  136 +MATH_LIB = -lm
  137 +
  138 +# External memory options
  139 +
  140 +# 64 KB of external RAM, starting after internal RAM (ATmega128!),
  141 +# used for variables (.data/.bss) and heap (malloc()).
  142 +#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  143 +
  144 +# 64 KB of external RAM, starting after internal RAM (ATmega128!),
  145 +# only used for heap (malloc()).
  146 +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  147 +
  148 +EXTMEMOPTS =
  149 +
  150 +# Linker flags.
  151 +# -Wl,...: tell GCC to pass this to linker.
  152 +# -Map: create map file
  153 +# --cref: add cross reference to map file
  154 +LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  155 +LDFLAGS += $(EXTMEMOPTS)
  156 +LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  157 +
  158 +
  159 +
  160 +
  161 +# Programming support using avrdude. Settings and variables.
  162 +
  163 +# Programming hardware: alf avr910 avrisp bascom bsd
  164 +# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  165 +#
  166 +# Type: avrdude -c ?
  167 +# to get a full listing.
  168 +#
  169 +AVRDUDE_PROGRAMMER = usbtiny
  170 +
  171 +# com1 = serial port. Use lpt1 to connect to parallel port.
  172 +AVRDUDE_PORT = usb # programmer connected to serial device
  173 +
  174 +AVRDUDE_WRITE_FLASH = -B 1 -U flash:w:$(TARGET).hex
  175 +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  176 +
  177 +
  178 +# Uncomment the following if you want avrdude's erase cycle counter.
  179 +# Note that this counter needs to be initialized first using -Yn,
  180 +# see avrdude manual.
  181 +#AVRDUDE_ERASE_COUNTER = -y
  182 +
  183 +# Uncomment the following if you do /not/ wish a verification to be
  184 +# performed after programming the device.
  185 +#AVRDUDE_NO_VERIFY = -V
  186 +
  187 +# Increase verbosity level. Please use this when submitting bug
  188 +# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  189 +# to submit bug reports.
  190 +#AVRDUDE_VERBOSE = -v -v
  191 +
  192 +AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  193 +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  194 +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  195 +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  196 +
  197 +
  198 +
  199 +# ---------------------------------------------------------------------------
  200 +
  201 +# Define directories, if needed.
  202 +DIRAVR = c:/winavr
  203 +DIRAVRBIN = $(DIRAVR)/bin
  204 +DIRAVRUTILS = $(DIRAVR)/utils/bin
  205 +DIRINC = .
  206 +DIRLIB = $(DIRAVR)/avr/lib
  207 +
  208 +
  209 +# Define programs and commands.
  210 +SHELL = sh
  211 +CC = avr-gcc
  212 +OBJCOPY = avr-objcopy
  213 +OBJDUMP = avr-objdump
  214 +SIZE = avr-size
  215 +NM = avr-nm
  216 +AVRDUDE = avrdude
  217 +REMOVE = rm -f
  218 +COPY = cp
  219 +
  220 +
  221 +
  222 +
  223 +# Define Messages
  224 +# English
  225 +MSG_ERRORS_NONE = Errors: none
  226 +MSG_BEGIN = -------- begin --------
  227 +MSG_END = -------- end --------
  228 +MSG_SIZE_BEFORE = Size before:
  229 +MSG_SIZE_AFTER = Size after:
  230 +MSG_COFF = Converting to AVR COFF:
  231 +MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  232 +MSG_FLASH = Creating load file for Flash:
  233 +MSG_EEPROM = Creating load file for EEPROM:
  234 +MSG_EXTENDED_LISTING = Creating Extended Listing:
  235 +MSG_SYMBOL_TABLE = Creating Symbol Table:
  236 +MSG_LINKING = Linking:
  237 +MSG_COMPILING = Compiling:
  238 +MSG_ASSEMBLING = Assembling:
  239 +MSG_CLEANING = Cleaning project:
  240 +
  241 +
  242 +
  243 +
  244 +# Define all object files.
  245 +OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  246 +
  247 +# Define all listing files.
  248 +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  249 +
  250 +
  251 +# Compiler flags to generate dependency files.
  252 +GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  253 +
  254 +
  255 +# Combine all necessary flags and optional flags.
  256 +# Add target processor to flags.
  257 +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  258 +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  259 +
  260 +
  261 +
  262 +
  263 +
  264 +# Default target.
  265 +all: begin gccversion sizebefore build sizeafter finished end
  266 +
  267 +build: elf hex eep lss sym
  268 +
  269 +elf: $(TARGET).elf
  270 +hex: $(TARGET).hex
  271 +eep: $(TARGET).eep
  272 +lss: $(TARGET).lss
  273 +sym: $(TARGET).sym
  274 +
  275 +
  276 +
  277 +# Eye candy.
  278 +# AVR Studio 3.x does not check make's exit code but relies on
  279 +# the following magic strings to be generated by the compile job.
  280 +begin:
  281 + @echo
  282 + @echo $(MSG_BEGIN)
  283 +
  284 +finished:
  285 + @echo $(MSG_ERRORS_NONE)
  286 +
  287 +end:
  288 + @echo $(MSG_END)
  289 + @echo
  290 +
  291 +
  292 +# Display size of file.
  293 +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  294 +ELFSIZE = $(SIZE) -A $(TARGET).elf
  295 +sizebefore:
  296 + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  297 +
  298 +sizeafter:
  299 + @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  300 +
  301 +
  302 +
  303 +# Display compiler version information.
  304 +gccversion :
  305 + @$(CC) --version
  306 +
  307 +
  308 +
  309 +# Program the device.
  310 +program: $(TARGET).hex
  311 + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  312 +
  313 +fuse:
  314 + $(AVRDUDE) $(AVRDUDE_FLAGS) -B 10 -u -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m
  315 +
  316 +all:
  317 + $(AVRDUDE) $(AVRDUDE_FLAGS) -B 10 -u -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m
  318 + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  319 +
  320 +
  321 +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  322 +COFFCONVERT=$(OBJCOPY) --debugging \
  323 +--change-section-address .data-0x800000 \
  324 +--change-section-address .bss-0x800000 \
  325 +--change-section-address .noinit-0x800000 \
  326 +--change-section-address .eeprom-0x810000
  327 +
  328 +
  329 +coff: $(TARGET).elf
  330 + @echo
  331 + @echo $(MSG_COFF) $(TARGET).cof
  332 + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  333 +
  334 +
  335 +extcoff: $(TARGET).elf
  336 + @echo
  337 + @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  338 + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  339 +
  340 +
  341 +
  342 +# Create final output files (.hex, .eep) from ELF output file.
  343 +%.hex: %.elf
  344 + @echo
  345 + @echo $(MSG_FLASH) $@
  346 + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  347 +
  348 +%.eep: %.elf
  349 + @echo
  350 + @echo $(MSG_EEPROM) $@
  351 + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  352 + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  353 +
  354 +# Create extended listing file from ELF output file.
  355 +%.lss: %.elf
  356 + @echo
  357 + @echo $(MSG_EXTENDED_LISTING) $@
  358 + $(OBJDUMP) -h -S $< > $@
  359 +
  360 +# Create a symbol table from ELF output file.
  361 +%.sym: %.elf
  362 + @echo
  363 + @echo $(MSG_SYMBOL_TABLE) $@
  364 + $(NM) -n $< > $@
  365 +
  366 +
  367 +
  368 +# Link: create ELF output file from object files.
  369 +.SECONDARY : $(TARGET).elf
  370 +.PRECIOUS : $(OBJ)
  371 +%.elf: $(OBJ)
  372 + @echo
  373 + @echo $(MSG_LINKING) $@
  374 + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  375 +
  376 +
  377 +# Compile: create object files from C source files.
  378 +%.o : %.c
  379 + @echo
  380 + @echo $(MSG_COMPILING) $<
  381 + $(CC) -c $(ALL_CFLAGS) $< -o $@
  382 +
  383 +
  384 +# Compile: create assembler files from C source files.
  385 +%.s : %.c
  386 + $(CC) -S $(ALL_CFLAGS) $< -o $@
  387 +
  388 +
  389 +# Assemble: create object files from assembler source files.
  390 +%.o : %.S
  391 + @echo
  392 + @echo $(MSG_ASSEMBLING) $<
  393 + $(CC) -c $(ALL_ASFLAGS) $< -o $@
  394 +
  395 +
  396 +
  397 +# Target: clean project.
  398 +clean: begin clean_list finished end
  399 +
  400 +clean_list :
  401 + @echo
  402 + @echo $(MSG_CLEANING)
  403 + $(REMOVE) $(TARGET).hex
  404 + $(REMOVE) $(TARGET).eep
  405 + $(REMOVE) $(TARGET).obj
  406 + $(REMOVE) $(TARGET).cof
  407 + $(REMOVE) $(TARGET).elf
  408 + $(REMOVE) $(TARGET).map
  409 + $(REMOVE) $(TARGET).obj
  410 + $(REMOVE) $(TARGET).a90
  411 + $(REMOVE) $(TARGET).sym
  412 + $(REMOVE) $(TARGET).lnk
  413 + $(REMOVE) $(TARGET).lss
  414 + $(REMOVE) $(OBJ)
  415 + $(REMOVE) $(LST)
  416 + $(REMOVE) $(SRC:.c=.s)
  417 + $(REMOVE) $(SRC:.c=.d)
  418 + $(REMOVE) .dep/*
  419 +
  420 +
  421 +
  422 +# Include the dependency files.
  423 +-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  424 +
  425 +
  426 +# Listing of phony targets.
  427 +.PHONY : all begin finish end sizebefore sizeafter gccversion \
  428 +build elf hex eep lss sym coff extcoff \
  429 +clean clean_list program
  430 +
  431 +
  432 +
  433 +
  434 +

0 comments on commit c1f8f1b

Please sign in to comment.
Something went wrong with that request. Please try again.