First look at a makefile Example:
1 /*identify the toolchain and take a simple alias for it*/2CC = arm-linux-GCC 3LD = arm-linux-LD4AR = arm-linux-ar5Objcopy = arm-linux-objcopy6OBJDUMP = arm-linux-Objdump7 /*indicates the location of the header file*/8Includedir: = $ (shellpwd)/include9 /*-wall hint Warning,-O2 represents optimization options, optimal optimization,-fno-builtin represents itself to implement some library functions, if not added this option will conflict*/TenCFLAGS: =-wall-o2-fno-Builtin One /*-nostdinc,-nostdlib means that the two libraries are not used, and-i$ (includedir) means linking to the header file*/ ACppflags: =-nostdinc-i$ (Includedir)-nostdlib - - /*make these defined variables effective*/ the export CC AR LD objcopy OBJDUMP includedir CFLAGS cppflags - - /** Compile the. o file and the. A static library generated under the lib/directory together into an. elf file*/ -OBJS: = START.O main.o uart.o clock.o lcd.o lib/LIBC.A + - Lcd70.bin: $ (OBJS) +${LD}-tlcd70.lds-o lcd70.elf $^//The main place used here is the location of the code indicated by Tlcd70.lds, the linker script. A${objcopy}-o binary-S lcd70.elf [email protected] at${objdump}-D lcd70.elf >Lcd70.dis - - /*indicates pseudo-target, i.e. no dependent file*/ -. phony:lib/LIBC.A - /*go to the directory to execute make command production. A static library*/ -lib/LIBC.A: inCD Lib; Make; cd.. - to%.o:%. C +${CC} $ (cppflags) $ (CFLAGS)-c-o [email protected] $< - the%.o:%. S *${CC} $ (cppflags) $ (CFLAGS)-c-o [email protected] $< $ Panax Notoginseng Clean : - MakeClean-C Lib the RM-F *.bin *.elf *.dis *.O
Makefile for production of static libraries :
string . O VSPRINTF.O /* production of static libraries */ LIBC.A: $ (OBJS) -r-o [email protected] $^ /* generates. o files for. C and. s files */%.o:%. C -c-o [email protected ] $<%.o:%. S -c-o [email protected] $< clean: rm -F LIBC.A *.o
Linker script:
sections{ 0x40000000; // indicates the start run address of the program . Text: { START.O// indicates the first file to run * (. Text) } . Data: { * (. data) } . BSS: { * (. BSS) } }
More complex makefile with the LDS script programming