編譯系統搭建 小例子 ----- ydb

TOPDIR  := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

export  TOPDIR

include $(TOPDIR)/config.mk

PLATFORM_LIBS += --no-warn-mismatch -L \

 $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) \

 -lgcc

LIBS  := lib/libc.a drivers/libdrivers.a

OBJECTS := init.o lowlevel.o board.o  main.o 

.PHONY : $(LIBS)

SUBDIRS := lib drivers

LDFLAGS := -Bstatic -Tvmlinux.lds -start-group $(LIBS) --end-group $(PLATFORM_LIBS) \

   -Ttext $(TEXT_BASE)

CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)

all:image.bin

image.bin:vmlinux

$(OBJCOPY) -O binary $< $@

vmlinux:$(OBJECTS) $(SUBDIRS) $(LIBS)

$(LD) -o $@  $(OBJECTS) $(LDFLAGS)

.o:.c

$(CC) -c $(CFLAGS) $< -o $@

.PHONY : $(SUBDIRS)

$(SUBDIRS):

make -C $@ all

clean:

find -type f \

   \( -name "*.bin" -o -name "*.srec" -o -name "*.a" \

-o -name "*.o" \)  -exec rm -f {} \;

rm image.srec image.bin vmlinux -f

//config.mk

CROSS:=  arm-linux-

LD := $(CROSS)ld

CC :=  $(CROSS)gcc

OBJCOPY := $(CROSS)objcopy

gccincdir := $(shell $(CC) -print-file-name=include)

CPPFLAGS := -Wall -Wstrict-prototypes -msoft-float -nostdinc -nostdlib\

-fno-common -fno-builtin  -I$(TOPDIR) -I$(TOPDIR)/include \

-isystem $(gccincdir) -march=armv5 -pipe

CFLAGS := -Os

TEXT_BASE =  0x1fffc000

//config.h

#ifndef __CONFIG_H

#define __CONFIG_H

#define CFG_SERIAL_BAUD 38400

#define CONFIG_MX31_DEBUG_CONSOLE 3

#endif

//lib  makefile

include $(TOPDIR)/config.mk

LIB = libc.a

OBJS = vsprintf.o string.o stubs.o

all:$(LIB)

$(LIB): $(OBJS)

$(AR) crv $@ $(OBJS)

//driver

include $(TOPDIR)/config.mk

LIB = libdrivers.a 

OBJS = serial.o 

all:$(LIB)

$(LIB): $(OBJS)

$(AR) crv $@ $(OBJS)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章