该Makefile实现了对ARM7TDMI平台程序的基本编译链接,使用了GNUARM(www.gnuarm.com)的arm-elf-gcc toolchains,供参考:
#### File Definition ####
TARGET = s44btest
#c files
CSRC = $(SRCPATH)/main.c $(SRCPATH)/44blib.c $(SRCPATH)/led.c
#assember files
ASRC = $(SRCPATH)/start.S $(SRCPATH)/lowlevel_init.S $(SRCPATH)/44BLIB_A.S
# Define all object files.
AOBJ = $(ASRC:.S=.o)
COBJ = $(CSRC:.c=.o)
CPPOBJ = $(CPPSRC:.cpp=.o)
#### Destination path Definition ####
TOP := .
SRCPATH= ./SRC
INC = -I$(TOP)/INC
OBJPATH= ./obj
#### ARM tool Definition ####
CROSS_COMPILE= arm-elf-
ARMLINK= $(CROSS_COMPILE)ld
ARMAS = $(CROSS_COMPILE)as
ARMCC = $(CROSS_COMPILE)gcc
ARMCPP = $(CROSS_COMPILE)g++
### target options ###
CPU= arm7tdmi
MARCH = armv4
#### Option Definition ####
TOOLSPATH = /cygdrive/c/Program/ Files/GNUARM
LFLAGS = -Bstatic -Tlink.lds
LFLAGS += -L$(TOOLSPATH)/arm-elf/lib
LFLAGS += -L$(TOOLSPATH)/lib/gcc/arm-elf/4.3.2
LFLAGS += -lm -lgcc
AFLAGS = -g -march=$(MARCH) -mcpu=$(CPU) $(INC)
CFLAGS := -g -mcpu=$(CPU) -march=$(MARCH)
CFLAGS += -O2 -Wall -c -Wstrict-prototypes -fomit-frame-pointer -ffreestanding
CFLAGS += -DGCC
CFLAGS += $(INC)
CPPFLAGS = -g -mcpu=$(CPU) -march=$(MARCH) $(INC)
#### build ####
#target build
all: $(TARGET).elf
$(TARGET).elf: $(AOBJ) $(COBJ) $(CPPOBJ) Makefile
@echo "linking..."
$(ARMLINK) -o $(TARGET).elf $(AOBJ) $(COBJ) $(CPPOBJ) $(LFLAGS)
# Compile: create object files from C source files. ARM/Thumb
$(COBJ) : %.o : %.c
@echo "compile c files"
$(ARMCC) -c $(CFLAGS) $< -o $@
# Compile: create object files from C++ source files. ARM/Thumb
$(CPPOBJ) : %.o : %.cpp
@echo "compile cpp files"
$(ARMCPP) -c $(CFLAGS) $< -o $@
# Assemble: create object files from assembler source files. ARM/Thumb
$(AOBJ) : %.o : %.S
@echo "compile as files"
$(ARMAS) $(AFLAGS) $< -o $@
#### clean the objs ###
clean:
rm $(TARGET).elf $(COBJ) $(CPPOBJ) $(AOBJ)
# Listing of phony targets.
.phony : clean
链接描述文件(link.lds)
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
. = 0xC1000000;
. = ALIGN(4);
.text :{
_text_start = .;
*start.o;
*(.text)
_text_end = .;
}
. = ALIGN(4);
.data :{
_data_start = .;
*(.data)
_data_end = .;
}
. = ALIGN(4);
.bss (NOLOAD) : {
__bss_start = .;
*(.bss) . = ALIGN(4);
__bss_end = .; }
}