Translated and modified AVR-gcc3.3 makefile. (Usage: make clean /make all)

Publisher:火箭少年Latest update time:2017-01-03 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#============ 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)


Reference address:Translated and modified AVR-gcc3.3 makefile. (Usage: make clean /make all)

Previous article:Notes on using avr studio - Issues related to cannot find '*.elf'
Next article:Solution to AVRStudio 6 delay function error

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号