AVR GCC Makefile

xiaoxiao2021-03-06  41

# Winavr Sample Makefile Written By Eric B. Weddington, Jörg Wunsch, et al.

# Ratingd to the public domain

# Please read the make user manual!

#

# Additional material for this makefile WAS Submitted by:

# Tim Henigan

# Peter Fleury

# Reiner Patommel

# Sander pool

# Frederik Rouleau

# Markus PFAFF

#

# Com line:

#

# Make all = make Software.

#

# make clean = Clean Out Built Project Files.

#

# Make coff = Convert Elf To AVR Coff (for use with avr studio 3.x or vmlab).

#

# Make ExtCoff = Convert Elf To AVR Extended Coff (for use with avr studio

# 4.07 or greater.

#

# make program = Download the hex file to the device, using avrdude. please

# Customize The Avrdude Settings Below First!

#

# make filename.s = just compile filename.c = Just Compile Filename.c Into the assembler code onL

#

# To rebuild project do "make clean" the "make all".

#

# MCU Name

MCU = atmega8

# Output Format. (Can Be SREC, IHEX, BINARY)

Format = Ihex

# Target File Name (without Extension).

Target = EOS300D

# Optimization Level, Can Be [0, 1, 2, 3, s]. 0 Turns OFF OPTIZATION.

# (NOTE: 3 IS Not Always The Best Optimization Level. See avr-libc faq.)

Opt = s

# List c Source Files Here. (C Dependencies Are Automatic Or generated.)

SRC = $ (Target) .c

# I i i More Tan One Source File, Append Them Above, or Modify and

# uncomment the folowing:

#Src = foo.c bar.c

# You can also wrap lines by appending a backslash to the end of the line:

#SRC = Baz.c /

# xyzzy.c

# List assemembler source files here.

# Make the always end in a capital .s. Files Ending in a lowercase .s

# WILL NOT BE CONSIDES (Assembler # Output from the Compiler), And will be deleted upon "make clean"!

# Even though the dos / win * filesystem matches Both .s and .s the same,

# ip Will Preserve The Spelling of The FileNames, And GCC Itself Does

# Care About How The Name Is Spelled on Its Command-Line.

ASRC =

# List Any Extra Directories To Look for Include Files Here.

# Each Directory Must Be Sepend by a space.

EXTRAINCDIRS =

#Botional compiler flags.

# -g: generate debugging information (for gdb, or for cool conversion)

#- *: Optimization Level

# -f ...: tuning, see gcc manual and avr-libc documentation

# -Wall ...: Warning Level

# -Wa, ...: tell gcc to pass this to the assemble.

# -ahlms: Create Assembler Listing

CFLAGS = -g -o $ (OPT) /

-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums /

-Wall -wstrict-prototypes /

-Wa, -adhlns = $ (<:. c = .lst) /

$ (PatSubst%, - I%, $ (extraincDirs)

# Set a "Language Standard" Compiler Flag.

# Unmark Just One Line Below To Set The Language Standard To Use.

# gnu99 = c99 gnu extensions. See gcc manual for more information.

#Cflags = -std = c89

#Cflags = -std = gnu89

#Cflags = -std = c99

CFLAGS = -std = gnu99

#Botional assembler flags.

# -Wa, ...: tell gcc to pass this to the assemble.

# -ahlms: CREATE LISTING

# -gstabs: Have the assembler create line number information; note that

# for use in coff files, additional information about filenames

# and function name Needs to be present in the assemembler SOURCE

# Files - See avr-libc docs [fixme: not yet described there] asflags = -wa, -adhlns = $ (<: s = .lst), - gstabs

# Optional Linker Flags.

# -Wl, ...: tell gcc to pass this to linker.

# -Map: CREATE MAP FILE

# --cref: add cross refrence to map file

LDFLAGS = -wl, -map = $ (target) .map, - CREF

# Additional Libraries

# Minimalistic Printf Version

# Ldflags = -wl, -u, vfprintf -lprintf_min

# Floating point printf version (required) (required) (required) (required) (Requires -LM Below)

#LDFLAGS = -wl, -u, vfprintf -lprintf_fltf_flt

# -lm = Math Library

LDFLAGS = -LM

# Programming Support Using Avrdude. Settings and Variables.

# Programming Hardware: ALF AVR910 Avrisp Bascom BSD

# DT006 PAVR Picoweb Pony-STK200 SP12 STK200 STK500

#

# TYPE: AVRDE -C?

# TO GET A FULL LISTING.

#

Avrdude_Programmer = STK500

Avrdude_Port = Com1 # Programmer Connected to Serial Device

#Avrdude_port = LPT1 # Programmer Connected to Parallel Port

Avrdude_Write_Flash = -u Flash: W: $ (Target) .hex. HEX

#Avrdude_write_eeprom = -u EEPROM: W: $ (Target) .eep

Avrdude_flags = -p $ (mcu) -p $ (avrdude_port) -c $ (avrdude_programmer)

# UNComment The Following if you want avrdude's Erase Cycle Counter.

# Note That Thiscenter Needs to Be Initialized First Using -yn,

# See avrdude manual.

#Avrdude_rase = -y

# Uncomment the folowing if you do / not / wish a verification to be

# Performed After Programming The Device.

#Avrdude_flags = -V

# Increase verbosity level. Please use this when submitting bug

# Reports About avrdude. See

# to submit bug reports.

#Avrdude_flags = -V -V

# ------------------------------------------------- -------------------------- # Define Directories, if Needed.

Diravr = C: / WinAVR

Diravrbin = $ (diravr) / bin

Diravrutils = $ (Diravr) / Utils / Bin

Dirinc =.

Dirlib = $ (DIRAVR) / AVR / LIB

# Define Programs and Commands.

Shell = sh

CC = AVR-GCC

Objcopy = avr-objcopy

Objdump = avr-objdump

SIZE = AVR-SIZE

# Programming Support Using Avrdude.

Avrdude = avrdude

REMOVE = RM -F

COPY = CP

HEXSIZE = $ (size) - Target = $ (Format) $ (target) .hex

Elfsize = $ (size) -a $ (target) .elf

# Define Messages

# 中文 #

MSG_ERRORS_NONE = Errors: None

Msg_begin = -------- Begin --------

MSG_END = -------- End --------

MSG_SIZE_BEFORE = Size Before:

MSG_SIZE_AFTER = SIZE AFTER:

MSG_Coff = Converting to AVR COFF:

MSG_EXTENDED_COFF = Converting to AVR Extended Coff:

MSG_Flash = CREATING Load File Flash:

Msg_eeprom = CREATING LOAD FILE EEPROM:

MSG_EXTENDED_LISTING = CREANG EXTENDED LISTING:

MSG_SYMBOL_TABLE = CREATING SYMBOL TABLE:

MSG_LINKING = lineing:

MSG_compiling = compling:

MSG_ASSEMBLING = askMBLING:

Msg_cleaning = Cleaning Project:

# Define all Object Files.

Obj = $ (src: .c = .o) $ (asrc: .s = .o)

# Define all Listing Files.

LST = $ (asrc: .s = .lst) $ (src: .c = .lst)

# Combine All Necessary Flags and Optional Flags.

# Add target processor to flags.

All_cflags = -mmcu = $ (mcu) -i. $ (Cflags)

All_ASFLAGS = -MMCU = $ (MCU) -i. -X assemer-with-cpp $ (asflags)

# Default Target.

All: Begin Gccversion Sizebefore $ (Target) .elf $ (target) .hex $ (target) .eep /

$ (Target) .lss $ (target) .ssym sizeafter finished end

# Eye Candy. # Avr studio 3.x does not check make's exit code but limited

# The folly piped by the compile job.

Begin:

@echo

@echo $ (msg_begin)

Finished:

@ec_errors_none

End:

@echo $ (msg_end)

@echo

# Display size of file.

Sizebefore:

@IF [-f $ (target) .elf]; the echo; echo $ (msg_size_before); $ (ELFSIZE); Echo; Fi

SizeAfter:

@IF [-f $ (target) .elf]; Then Echo; Echo $ (MSG_SIZE_AFTER); $ (ECHO; Echo; Fi

# Display Compiler Version Information.

gccversion:

@ $ (Cc) --Version

# Convert Elf To Coff for Use in Debugging / Simulating in

# AVR Studio or Vmlab.

Coffconvert = $ (Objcopy) --debugging /

--Change-section-address .data-0x800000 /

--Change-section-address .BSS-0x800000 /

--change-section-address - number-0x800000 /

--Change-section-address .eepRom-0x810000

Coff: $ (target) .elf

@echo

@echo $ (msg_coff) $ (Target) .cof

$ (Coffconvert) -o Coff-AVR $ (Target) .cof

ExtCoff: $ (target) .elf

@echo

@echo $ (msg_extended_coff) $ (target) .cof

$ (Coffconvert) -o coff-ext-avr $ <$ (target) .cof

# Program The Device.

Program: $ (target). Hex $ (Target) .eep

$ (Avrdude_flags) $ (avrdude_write_flash) $ (avrdude_write_eeprom)

# Create final output files (.hex, .eep) from Elf output file.

% .hex:% .elf

@echo

@echo $ (msg_flash) $ @

$ (OBJCOPY) -O $ (Format) -r .eeprom $ @ @ @ @

% .eep:% .elf

@echo

@echo $ (msg_eeprom) $ @

$ (Objcopy) -j .eProm --set-section-flags = .eeprom = "alloc, load" /

--change-section-lma .eeprom = 0-$ $ (format) $$ @

# Create Extended Listing File from Elf Output File.

% .LSS:% .elf

@echo

@Echo $ (MSG_EXTENDED_LISTING) $ @

$ (Objdump) -h -s $ @ @ @ @

# Create a symbol Table from Elf Output File.

% .SYM:% .elf

@echo

@echo $ (msg_symbol_table) $ @

AVR-NM -N $> $ @

# Link: Create Elf Output File from Object Files.

.Secondary: $ (Target) .elf

.Precious: $ (bj)

% .elf: $ (obj)

@echo

@echo $ (msg_linking) $ @

$ (Cc) $ (all_cflags) $ (b) --output $ @ $ (ldflags)

# Compile: CREATE Object Files from c Source Files.

% .O:% .c

@echo

@echo $ (msg_compiling) $ <

$ (Cc) -c $ (all_cflags) $ <-o $ @

# Compile: CREATE Assembler Files from C Source Files.

% .s:% .c

$ (Cc) -s $ (all_cflags) $ <-o $ @

# Assemble: Create Object Files from ask Assembler Source Files.

% .O:% .s

@echo

@echo $ (msg_assembling) $ <

$ (Cc) -c $ (all_asflags) $ <-O $ @

# Target: Clean Project.

Clean: Begin Clean_List Finished End

Clean_list:

@echo

@echo $ (msg_cleaning)

$ (REARGET). HEX

$ (REMOVE) $ (Target) .eep

$ (REARGET) .OBJ

$ (REARGET) .cof

$ (REARGET) .elf

$ (REARGET) .map .map

$ (REARGET) .OBJ

$ (REARGET) .A90

$ (REMOVE) $ (Target) .ssym

$ (REMOVE) $ (target) .lnk

$ (REMOVE) $ (target) .lss

$ (REMOVE) $ (OBJ)

$ (REMOVE) $ (LST)

$ (Transove) $ (src: .c = .s)

$ (Remote) $ (src: .c = .d)

# Automatically Generate C Source Code Dependencies.

# (Code Originally Taken from The GNU Make User Manual and Modified

# (See Readme.txt Credits).).).

#

# Note That this Will Work with sh (bash) and seat is sales with WinAVR

# (See the Shell Variable Defined Above).

# This may not work with other shells or other seds.

#

% .d:% .c

Set -e; $ (cc) -mm $ (all_cflags) $

| SED 'S, / (. * /) /. o [:] *, / 1.o /1.d:, g'> $ @; /

[-S $ @] || RM -F $ @ # remove the '-' if you want to see the dependency files generated.

-include $ (src: .c = .d)

# Listing of phony targets.

.Phony: All Begin Finish End Sizebefore SizeAfter Gccversion Coff ExtCoff /

Clean Clean_List Program

转载请注明原文地址:https://www.9cbs.com/read-58392.html

New Post(0)