📄 makefile
字号:
#******************************************************************************
#
# Makefile for an LPC-projects using gcc.
# by Martin Thomas, Kaiserslautern, Germany, eversmith@heizung-thomas.de
#
# - A lot of information comes from a makefile for nmake
# by R O SoftWare (BK).
# - gnu-make-adaption based on the WINAVR sample-makefile
# written by Eric B. Weddington, J鰎g Wunsch, et al.
#
# General remarks:
# - (At least) the GNU-tools "sh" and "make" have to be in the %PATH%.
# They are if WINAVR has been installed with the default options.
# - You may have to change the pathes to your compiler/tools see
# section "Define programs and commands" below
#
#******************************************************************************
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#
# To program into a LPC do "make program" (LPC21ISP used here)
#
## Create ROM-Image (final)
RUN_MODE=ROM_RUN
## Create RAM-Image (debugging)
#RUN_MODE=RAM_RUN
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = ledswitch
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c
# additional source files
# SRC+=
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (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,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
#
# for LPC:
ASRC = build/crt0.S
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = 0
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS = ./include
# Compiler flag to set the C Standard level.
CSTANDARD_C89 = c89
CSTANDARD_GNU89 = gnu89
CSTANDARD_C99 = c99
CSTANDARD_GNU99 = gnu99
CSTANDARD = -std=$(CSTANDARD_GNU99)
# Compiler flags.
# -g: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
MCU = arm7tdmi
CFLAGS = -g
CFLAGS += -D$(RUN_MODE)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CLAGS += -Wall -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations \
CLAGS += -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch \
CLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
#Additional libraries.
# TODO - still from WINAVR
PRINTF_LIB_NONE =
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
PRINTF_LIB = $(PRINTF_LIB_NONE)
MATH_LIB = -lm
# Linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
####LDFLAGS = -Wl,-Map=$(TARGET).map,--cref $(PRINTF_LIB) $(MATH_LIB)
##LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,-nostdlib
LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref
ifeq ($(RUN_MODE),RAM_RUN)
LDFLAGS +=-Tbuild/RAM.ld
else
LDFLAGS +=-Tbuild/ROM.ld
endif
# ---------------------------------------------------------------------------
# Programming support using lpc21isp
# (c) Martin Maurer (Martin.Maurer@clibb.de)
# Settings and variables:
LPC21ISP_PORT = com1
LPC21ISP_BAUD = 19200
LPC21ISP_XTAL = 14746
LPC21ISP_FLASHFILE = $(TARGET).hex
# ---------------------------------------------------------------------------
# Define directories, if needed.
# mind that "sh" expects unix-style slash not ms backslah for separation
# TODO: use env. var PROGRAMFILES, add gnu-tools to PATH
# wuff-wuff: for German Windows - please change to your needs
DIRPRG = c:/Programme
DIRGNUARM = $(DIRPRG)/GNUARM
DIRGNUARMBIN = $(DIRGNUARM)/bin
DIRGNUARMUTILS = $(DIRGNUARM)/utils/bin
DIRINC = .
DIRLIB = $(DIRGNUARM)/lib
# Define programs and commands.
# partly relies on the tools that come with WINAVR (sh, make ...)
SHELL = sh
CC = $(DIRGNUARMBIN)/arm-elf-gcc
OBJCOPY = $(DIRGNUARMBIN)/arm-elf-objcopy
OBJDUMP = $(DIRGNUARMBIN)/arm-elf-objdump
SIZE = $(DIRGNUARMBIN)/arm-elf-size.exe
NM = $(DIRGNUARMBIN)/arm-elf-nm
# M. Maurer's ISP-Tool located in the project-directory here:
LPC21ISP = ./lpc21isp
REMOVE = rm -f
REMOVEDIR = rmdir
COPY = cp
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin -------- $(value FOO) $(eval PRG_PATH)
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_FLASH = Creating load file for Flash:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_LPC21_RESETREMINDER = You may have to enable the bootloader and\
reset the device now
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Compiler flags to generate dependency files.GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
MCU=arm7tdmi
ALL_CFLAGS = -mcpu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter finished end
#build: elf hex eep lss sym
build: elf hex lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
lss: $(TARGET).lss
sym: $(TARGET).sym
# Eye candy.
begin:
@echo
@echo $(MSG_BEGIN)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex
@echo
@echo $(MSG_BEGIN)
@echo $(MSG_LPC21_RESETREMINDER)
$(LPC21ISP) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL)
@echo $(MSG_END)
# Create final output files (.hex) from ELF output file.
%.hex: %.elf
@echo @echo $(MSG_FLASH) $@ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
# 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) $@
$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --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 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) $(REMOVE) $(TARGET).hex
# $(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) .dep/*
$(REMOVEDIR) .dep
# Include the dependency files.-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
#.PHONY : all begin finish end sizebefore sizeafter gccversion \
#build elf hex eep lss sym coff extcoff \
#clean clean_list program
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex lss sym coff extcoff \
clean clean_list program
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -