#============ MCU selection ========================
# MCU name
MCU = atmega8
#============== Output format selection ====================
# Output format. (can be srec, ihex)
FORMAT = ihex
#=============
Target file name (without extension).
TARGET = main
#============== Optimization level selection ===================
# Optimization level (can be 0, 1, 2, 3, s)
# (Note: 3 is not always the best optimization level. See avr-libc FAQ)
OPT = s
#============= C source files list ("\" is a newline character) =======
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c timer.c extdrv.c adc.c sd2k.c mylib.c
#============== ASM source files list ===================
# List Assembler source files here.
ASRC =
#============= C compilation options ========================
# Optional compiler flags.
CFLAGS = -g -O$(OPT) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)
#============= Assembler options========================
# Optional assembler flags.
ASFLAGS = -Wa,-ahlms=$(<:.s=.lst), -gstabs
#=============== Connector options========================
# Optional linker flags.
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
#=============== Additional library flags=====================
# Additional library flags (-lm = math library).
LIBFLAGS = = -lm
#********************************************************************************
# WinAVR Sample makefile (c) 2002-2003 Eric B. Weddington
# Released to the Public Domain
# Please read the make user manual!
#
# On command line:
# make all = Make software.
# make clean = Clean out built project files.
# make coff = Convert ELF to COFF using objtool.
#
# To rebuild project do make clean then make all.
#
#***********************************************************************************
#=============
# Define directories, if needed.
DIRAVR = c:/ele/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
#============ Define commands (tool software name) ============
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
REMOVE = rm -f
COPY = cp
ELFCOFF = objtool
#============= Definition of some strings and acquisition of data=======
HEXSIZE = @avr-size --target=$(FORMAT) $(TARGET).hex
ELFSIZE = @avr-size $(TARGET).elf
FINISH = @echo Errors: none
BEGIN = @echo -------- begin --------
END = @echo -------- end --------
#============= Specify all linking files===============
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.s=.o)
#============== Specify all listing files===============
# Define all listing files.
LST = $(ASRC:.s=.lst) $(SRC:.c=.lst)
#=============== Specify all .d files==================
# Define all listing files.
ALLD = $(SRC:.c=.d) $(ASRC:.c=.d)
#============== Compile all optional and required option flags, increase processing flags =
# Combine all necessary flags and optional flags. Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
ALL_LDFLAGS = -mmcu=$(MCU) $(LDFLAGS)
#============== Default processing (referring to when executing make, equivalent to executing make all), the real compilation process, super important, to understand!!! ==
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).cof sizeafter finished end
# Start->gcc copyright information>old file size>compile to generate .elf----->generate .hex----->generate .eep----->generate .lss----->generate .cof>new file size--->finish>end
#*******************************************************************************
#============= Some compilation information to be output============
# Eye candy.
begin:
$(BEGIN)
finished:
$(FINISH)
end:
$(END)
#============== Display file size information (before and after) ==
# Display size of file.
sizebefore:
@echo Size before:
-$(HEXSIZE)
sizeafter:
@echo Size after:
$(HEXSIZE)
#=============== Display compiler version information ===================
# Display compiler version information.
gccversion :
$(CC) --version
#=============== Function: Convert ELF file to COFF file for simulation/debugging in AVR Studio. ==
# Target: Convert ELF to COFF for use in debugging / simulating in AVR Studio.
coff: $(TARGET).cof end
%.cof: %.elf
$(ELFCOFF) loadelf $< mapfile $*.map writecof $@
#================ Generate final output files (.hex,.eep) from ELF output files ==
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
#=============== ==
# Create extended listing file from ELF output file.
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
#=============== ==
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
$(CC) $(ALL_LDFLAGS) $(OBJ) $(LIBFLAGS) --output $@
#=============== Compile: Generate OBJ files (.o) from C source files ==
# Compile: create object files from C source files.
%.o : %.c
$(CC) -c $(ALL_CFLAGS) $< -o $@
#===============
Assembly: Generate OBJ files (.o) from assembler source files.
%.o : %.s
$(CC) -c $(ALL_ASFLAGS) $< -o $@
3=============== Function: Clear the last compilation result==
# Target: clean project.
clean: begin clean_list finished end
clean_list :
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(RE MOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(TARGET).cof
$(REMOVE) $(OBJ) $
(REMOVE) $(LST)
$(REMOVE) $(ALLD)
#================================================================
# Automatically generate C source code dependencies. (Code taken from the GNU make user manual.)
# Note that this will work with sh (bash) and sed that is shipped 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 $@ : /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 clean clean_list
The original text comes from a makefile example of winavr. The main modifications I made are:
1. make all adds the generation of cof files
2. make clean deletes *.o and other files
3. There are other minor changes, but I forgot
to explain:
make clean:
used to clear the last compilation result (if the *.h file is changed, make clean must be executed first, then make all)
make all:
compile all (if only *,c files are changed, make clean is not required)
Previous article:Notes on using avr studio - Issues related to cannot find '*.elf'
Next article:Solution to AVRStudio 6 delay function error
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- PCB technology: PROTEL's metal slot method
- [ATmega4809 Curiosity Nano Review] Using MCC to configure TCA
- The shield affects the sensitivity, and the inductor close to the DCDC affects the sensitivity
- EEWORLD University Hall----Live Replay: Introduction to Intel FPGA Programmable Acceleration Platform, Approaching AI, Data Center, Genetic Engineering and Other Major Projects
- TMS320F28379D Create Project
- Teach you how to make a mini inverter 1.5V-220V at home
- Asynchronous Timing Design in ASIC.pdf
- [Repost] "Very Silly" Circuit Problem
- E840-DTU device connection to Alibaba Cloud test
- Interface corresponding to SNVS_TAMPER3 signal