十月 27
這是我用來寫code 的makefile, 很好用喔
##
## FILE: Makefile
##
## Date: 2006/08/17
##
## Author: Hao Tseng
##
## Descriptio: Makefile for vtssd86 program
##
## MODIFICATION HISTORY:
## Date By Version Change Description
##============================================================
## 2006/08/17 create this file
## 2006/10/25 modify for linux environment
##------------------------------------------------------------------------------
PROGRAM_NAME = vtssd86
# |
# | Include Files
# |
AINCLUDES =
CINCLUDES =
# |
# | Object files
# |
OBJECTS = \
$(OBJ)/source_code_cpp.cpp.o \
$(OBJ)/source_code_asm.S.o \
$(OBJ)/source_code_c.c.o
# |
# | Put the file name that you want to compile only
# | and generate asm file
ASMFILES =
# |
# | Tool chain definition
# |
GNU_TOOLS_PREFIX =
AS = $(GNU_TOOLS_PREFIX)as
CC = $(GNU_TOOLS_PREFIX)gcc
CPP = $(GNU_TOOLS_PREFIX)g++
AR = $(GNU_TOOLS_PREFIX)ar
LD = $(GNU_TOOLS_PREFIX)ld
OC = $(GNU_TOOLS_PREFIX)objcopy
NM = $(GNU_TOOLS_PREFIX)nm
OD = $(GNU_TOOLS_PREFIX)objdump
SZ = $(GNU_TOOLS_PREFIX)size
# | A special echo that prints prettily
E = @echo \\\# `date +%Y.%m.%d.%H:%M:%S` ---
# | Silence is golden... put "S=" (s equals nothing) on
# | the command line to get verbose output.
#S =
S = @
# |
# | directory for objects & other output files
# |
OBJ = ./obj
OUTPUT = ./output
ASMDIR = ./asm_output
# |
# | And the source directory? Is right here.
# |
SRC = .
# |
# | Include paths and such
# |
INCLUDE_PATHS = \
-I ./inc \
-I ../inc \
# +------------------------------------
# | Switches for the compiler, the assembler,
# | and the linker
# |
DebugFlags = -g -O2
ASFlags = \
$(INCLUDE_PATHS) \
$(DebugFlags) \
-W -c
CCFlags = \
$(INCLUDE_PATHS) \
$(DebugFlags) \
-W -c
CPPFlags = \
$(CCFlags)
# +----------------------------------------
# | Rules
# +----------------------------------------
default : elf
$(OBJ)/%.cpp.o : $(SRC)/%.cpp $(CINCLUDES)
$(E) Compiling $<
$(S)$(CPP) $(CPPFlags) $< -o $@
$(OBJ)/%.S.o : $(SRC)/%.S $(AINCLUDES)
$(E) Assembling $<
$(S)$(CC) $(ASFlags) $< -o $@
$(OBJ)/%.c.o : $(SRC)/%.c $(CINCLUDES)
$(E) Compiling $<
$(S)$(CC) $(CCFlags) $< -o $@
$(ASMDIR)/%.c.s : $(SRC)/%.c $(CINCLUDES)
$(E) Compiling only $<
$(S)$(CC) $(CCFlags) $< -S -o $@
$(OBJ) :
$(E) Making $@/ directory
$(S)mkdir $@
$(OUTPUT) :
$(E) Making $@/ directory
$(S)mkdir $@
$(ASMDIR) :
$(E) Making $@/ directory
$(S)mkdir $@
clean : $(OBJ) $(OUTPUT) $(ASMDIR)
$(E) Removing objects
$(S)rm -rf $(OBJ)
$(S)rm -rf $(OUTPUT)
$(S)rm -rf $(ASMDIR)/*
# +-------------------------------------
# | Linking
# +-------------------------------------
LFLAGS =
#LFLAGS = \
# -g \
# -T ./linkleon.ld \
# -e _hardreset \
# -g -N -nostdlib
#LIBs declaraction
# "-lrt" is used for posix timer functions.
# "-lstdc++" is used for C++ code.
# "-lpthread" is used for pthread functions.
LIBS = -lgcc -lstdc++ -lm -lrt -lpthread
$(OUTPUT)/$(PROGRAM_NAME).elf : $(OBJ) $(OBJECTS) $(OUTPUT)
$(E) Linking $@
$(S)$(CC) $(LFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) The Program size
$(S)$(SZ) $(OUTPUT)/$(PROGRAM_NAME).elf
# |
# | S-Record
# |
$(OUTPUT)/$(PROGRAM_NAME).srec : $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) Converting $(PROGRAM_NAME).elf to S-Record
$(S)$(OC) -O srec $(OUTPUT)/$(PROGRAM_NAME).elf $(OUTPUT)/$(PROGRAM_NAME).srec
# |
# | Handy auxilliary files
# |
$(OUTPUT)/$(PROGRAM_NAME).nm : $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) Making $(PROGRAM_NAME).nm
$(S)$(NM) $(OUTPUT)/$(PROGRAM_NAME).elf | sort > $(OUTPUT)/$(PROGRAM_NAME).nm
$(OUTPUT)/$(PROGRAM_NAME).objdump : $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) Making $(PROGRAM_NAME).objdump
$(S)$(OD) $(OUTPUT)/$(PROGRAM_NAME).elf -d -S > $(OUTPUT)/$(PROGRAM_NAME).objdump
$(OUTPUT)/$(PROGRAM_NAME).dat : $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) Making $(PROGRAM_NAME).dat
$(S)$(OD) $(OUTPUT)/$(PROGRAM_NAME).elf -s > $(OUTPUT)/$(PROGRAM_NAME).dat
$(OUTPUT)/$(PROGRAM_NAME).bin : $(OUTPUT)/$(PROGRAM_NAME).elf
$(E) Converting $(OUTPUT)/$(PROGRAM_NAME).elf to Binary
$(S)$(OC) -O binary $(OUTPUT)/$(PROGRAM_NAME).elf $(OUTPUT)/$(PROGRAM_NAME).bin
# +-------------------------------------
# | Shortcut Targets
# |
srec : $(OUTPUT)/$(PROGRAM_NAME).srec
elf : $(OUTPUT)/$(PROGRAM_NAME).elf
bin : $(OUTPUT)/$(PROGRAM_NAME).dat $(OUTPUT)/$(PROGRAM_NAME).bin
aux : $(OUTPUT)/$(PROGRAM_NAME).nm $(OUTPUT)/$(PROGRAM_NAME).objdump
asm : $(ASMDIR) $(ASMFILES)
bootcode :
$(E) Make the boot code
$(S)cd boot; make bin
all : elf srec aux bin
help :
@echo
@echo Program name: $(PROGRAM_NAME)
@echo
@echo Available makefile targets:
@echo
@echo " make clean -- erase intermediate files"
@echo " make srec -- convert elf to S-Record"
@echo " make elf -- only make the .elf file"
@echo " make aux -- generate .nm and .objdump files"
@echo " make bin -- generate .dat and .bin files"
@echo " make asm -- generate .c.s files"
@echo " make all -- do all of above"
@echo " make bootcode -- make boot rom .elf & .bin file(in boot directory)"
@echo
@echo Add the option "S=" for a more verbose output
@echo
# end of file