###############################################################################
# Copyright (c) 2008 Montage Tech - All Rights Reserved
# Owner: Yongmin Du
# Michael Qiu
###############################################################################
#
# make options:
# prj=[test] Currently, we only support test project. If no prj
# setted in command line, Makefile will read the
# default project value stored in config.mk
# arch=[x86|ckcore|mips] Override the default value set in platform.mk, if
# current one is not the same as previous one, system
# automatically remove "obj" and "out" before compile.
# debug=[1|0] Override the default debug flag in platform.mk
# unit=[1|0] Override the default unit flag in platform.mk
# test_mode=[0|1|2] Override the defualt test_mode flag platform.mk
# 0 means automated test. If the arch is x86, System
# will stick this option to 0 nomatterwhat you set on
# command line.
# 1 means basic mode
# 2 means console mode
# cunit_self_test=[0|1] override the default self_test flag in platform.mk
# clean clear object files and .bin .elf and .map files
# out Output the .bin .elf and .map files in "out" folder
# superclean Remove "out" and "obj" folder.
###############################################################################
# Top Directory
###############################################################################
TOPDIR = .$(shell pwd | sed 's/\(.*\)\/wizards\(.*\)/\2/g' \
|sed 's/\/[0-9a-zA-Z]*/\/../g')
prjtype = dvbs
DEFAULTPRJ = "prj = $(prj)"
-include $(TOPDIR)/config/$(prj)/$(prj).mk
###############################################################################
# Build Relative Directories
###############################################################################
OUTDIR = $(TOPDIR)/out/$(prj)/$(arch)
OBJDIR = $(TOPDIR)/obj/$(prj)/$(arch)
LIBDIR = $(TOPDIR)/lib/$(arch)
BINDIR = $(TOPDIR)/config/$(prj)/binary
TOOLS = $(TOPDIR)/tools
INFO = $(OUT)/info
BIN = $(OUTDIR)/bin
OBJPATH = $(OBJDIR)$(shell pwd | sed 's/\(.*\)\/wizards\(.*\)/\2/g')
###############################################################################
# Tool Chain
###############################################################################
CROSS = mips-elf-
AS = $(CROSS)as
CC = $(CROSS)gcc
LD = $(CROSS)ld
AR = $(CROSS)ar
OD = $(CROSS)objdump
OC = $(CROSS)objcopy
GS = $(CROSS)gasp
NM = $(CROSS)nm
RD = $(CROSS)readelf
STRIP = $(CROSS)strip
SIZE = $(CROSS)size
LIBTOOL = $(CROSS)libtool
CAT = cat
LS = ls
XARGS = xargs
RM = rm
CP = cp
MKDIR = mkdir
ECHO = echo
SED = sed
FIND = find
MAKE= make
tmpword = $(addprefix +,$@)
keyword = $(addsuffix +,$(tmpword))
dirword = $(shell pwd | sed 's/\(.*\)\/wizards\(.*\)/\2/g')/$@
objpath = $(shell pwd | sed 's/\(.*\)\/wizards\(.*\)/\2/g')
objword = $(objpath)/$*.c
objall = $(objpath)/*
objnull = $(objpath)/!
LIBINC = /usr/local/mips-elf/mips-elf/include/
GCCINC = /usr/local/mips-elf/lib/gcc/mips-elf/4.1.1/include
HOSTOS = $(shell uname -o)
ifeq "$(HOSTOS)" "GNU/Linux"
MKIMG = $(TOOLS)/mkimg_mips
ANCHOR = $(TOOLS)/anchor/anchor
LZMA = lzma
else
MKIMG = $(TOOLS)/mkimg_mips.exe
ANCHOR = $(TOOLS)/anchor/anchor.exe
LZMA = $(TOOLS)/lzma.exe
endif
version = 0
###############################################################################
# Build Options
###############################################################################
INC= -I$(LIBINC) -I$(GCCINC) $(LOCALINC)
OPTIMIZE_DEFINES = -O$(optimize)
MACRODEF += -DARCH=MIPS
ifeq "$(magic)" "1"
MACRODEF += -DCHIP_MAGIC
endif
ifeq "$(MIPS32FLAG)" "TRUE"
MIPS16FLAG =
endif
ifeq "$(OPTIFLAG)" "TRUE"
OPTIMIZE_DEFINES = -O$(OPTIOPTION)
endif
LD_FILE ?= $(TOPDIR)/link_mips.ld
CFLAGS ?= $(INC) $(MACRODEF) $(OPTIMIZE_DEFINES) $(DEBUG_DEFINES) \
-G0 -EL -mips1 -Wa,-xgot -nostartfiles -nodefaultlibs -Wall \
-Wno-pointer-sign $(MIPS16FLAG) -Werror -msoft-float \
-ffunction-sections
AFLAGS ?= -EL -mips1
LDFLAGS ?= --oformat elf32-littlemips -gc-sections -T$(LD_FILE) -L$(LIBDIR)
###############################################################################
# Build Targets
###############################################################################
.PHONY: all
all: PREBUILD $(patsubst %,$(OBJPATH)/%, $(OBJS)) $(SUBDIRS)
.PHONY: dbg
dbg: all AFTERBUILD
@$(ECHO) $(LDFLAGS) -o $(OUTDIR)/wizards.elf > $(OBJDIR)/.link.tmp
@$(CP) $(LIBDIR)/new.o $(OBJDIR)
@$(FIND) $(OBJDIR) -name "*.o" -type f -print |sort -d >> $(OBJDIR)/.link.tmp
@$(ECHO) -lm -lc -lgcc >> $(OBJDIR)/.link.tmp
@$(CAT) $(OBJDIR)/.link.tmp | $(XARGS) $(LD) -M > $(OUTDIR)/wizards.map
@mips-elf-objdump -x -D --source $(OUTDIR)/wizards.elf \
>$(OUTDIR)/wizard_full.s
@$(SED) 's/-.*$$//g' $(OBJDIR)/.link.tmp | $(XARGS) $(SIZE) \
> $(OUTDIR)/wizards.siz
@$(SIZE) $(OUTDIR)/wizards.elf >> $(OUTDIR)/wizards.siz
@$(ECHO) Build with optimize=$(OPTIMIZE_DEFINES) \
debug=$(debug) unit=$(unit) >> $(OUTDIR)/wizards.siz
ifeq "$(debug)" "0"
@-$(RM) -f $(OUTDIR)/wizards.dbg
else
$(CP) $(OUTDIR)/wizards.elf $(OUTDIR)/wizards.dbg
endif
@$(STRIP) $(OUTDIR)/wizards.elf
@mips-elf-objdump -Dz $(OUTDIR)/wizards.elf >$(OUTDIR)/wizard_strip.s
@$(OC) -O binary $(OUTDIR)/wizards.elf $(OUTDIR)/wizards.bin
.PHONY: out
out: dbg HANDLE_OUTPUT
@$(RM) -f $(OBJDIR)/.link.tmp
@$(ECHO) Build done
PREBUILD:
ifeq "$(MAKELEVEL)" "0"
@$(ECHO) Build with \"prj=$(prj) arch=$(arch) mips16=$(mips16) cache=$(cache) optimize=$(optimize) assert=$(assert) print=$(print) \
debug=$(debug) test_mode=$(test_mode) cunit_self_test=$(cunit_self_test) bootloader=$(bootloader)\"
-@$(MKDIR) -p $(OUTDIR)
-@$(MKDIR) -p $(OBJDIR)
endif
.PHONY: $(SUBDIRS)
ifneq "$(strip $(SUBDIRS))" ""
$(SUBDIRS):
$(if $(findstring $(dirword),$(MODGROUP)),@$(ECHO) "Enter $(findstring $(dirword),$(MODGROUP)")")
$(if $(findstring $(dirword),$(MODGROUP)),@$(MAKE) -C $@ all)
endif
.PHONY: clean superclean
SUBDIRS_CLEAN = $(patsubst %,%_clean,$(SUBDIRS))
clean:
$(RM) -rf $(TOPDIR)/obj/$(prj)
$(SUBDIRS_CLEAN):
@$(MAKE) -C $(patsubst %_clean,%,$@) clean unit=1
superclean:
$(RM) -rf $(TOPDIR)/obj $(TOPDIR)/out
###############################################################################
# Pattern Rules.
###############################################################################
define compiling-obj
@$(ECHO) "Generating $(OBJPATH)/$*.d ..."
@$(ECHO) "Compiling $< ..."
@$(CC) -c $(CFLAGS) -o $@ $<
endef
.SUFFIXES : .o .c .s .d
-include $(OBJS:%.o=$(OBJPATH)/%.d)
$(OBJPATH)/cache.o: $(TOPDIR)/src/hal/arch/mips/cache.s
-@$(MKDIR) -p $(OBJPATH)
$(CC) -mips32 -O0 -EL -nostartfiles -nodefaultlibs -Wall -c -o $@ $<
$(OBJPATH)/%.o: %.s
-@$(MKDIR) -p $(OBJPATH)
@$(ECHO) '['$<']'
@$(AS) $(AFLAGS) -o $@ $<
$(OBJPATH)/%.o: %.c
-@$(MKDIR) -p $(OBJPATH)
$(CC) -MM $(CFLAGS) $< > $(OBJPATH)/$*.p
@$(SED) -e 's#^$*#$(OBJPATH)/$*#' < $(OBJPATH)/$*.p > $(OBJPATH)/$*.d
@$(SED) -e 's#^$*#$(OBJPATH)/$*#' -e 's/#.*//' -e 's/^[^:]*: *//' \
-e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' \
< $(OBJPATH)/$*.p >> $(OBJPATH)/$*.d
@$(RM) -f $(OBJPATH)/$*.p
$(if $(findstring $(objall),$(MODGROUP)), $(compiling-obj), \
$(if $(findstring $(objword),$(MODGROUP)),$(compiling-obj)))
$(TOPDIR)/config.mk: $(TOPDIR)/default.mk
$(ECHO) $(DEFAULTPRJ) > $@
阅读(1367) | 评论(0) | 转发(0) |