my work Makefile
时间:2007-05-28 来源:qfox
###########################################################
# Jasper Makefile
# @author qiuf
# Description:
# The makefile searches in <SRCDIRS> directories for the source files
# with extensions specified in .c, then compiles the sources
# and finally produces the <TARGET>, the executable file, by linking
# the objectives.
#
# BUG: make driver/ not very well
# Usage:
# $ make compile and link the program.
# $ make objs compile only (no linking. Rarely used).
# $ make dep create dependecy files only (Rarely used).
# $ make lib ar libjapser.a
# $ make clean clean the objectives and dependencies.
# $ make cleanall clean the objectives, dependencies and executable.
# $ make rebuild rebuild the program. The same as make clean && make all.
# the final bulid elf file
TARGET := Jasper
# add your source dir here!
SRCDIRS := app vfs fs vos codec unicode test driver/src
# gdb_dir, the dir that gdb.exe in, copy TARGET to GDB dir to download
GDBDIR := ../lupine_gdb_5
# OBJDIR, the objects and dependecies
#OBJSDIR = objects
# ecos install dir
ECOSDIR := ./install
# use ecos make rules
include $(ECOSDIR)/include/pkgconf/ecos.mak
# search dir
#vpath %.c $(SRCDIRS)
#vpath %.o $(SRCDIRS)
VPATH=$(SRCDIRS) ./include driver/include
# complier
CC := $(ECOS_COMMAND_PREFIX)gcc
# linker
LD := $(ECOS_COMMAND_PREFIX)ld
# ar
AR := $(ECOS_COMMAND_PREFIX)ar
# objdump
OBJDUMP := $(ECOS_COMMAND_PREFIX)objdump
# objcopy
OBJCOPY := $(ECOS_COMMAND_PREFIX)objcopy
# complie options
CFLAGS = $(ECOS_GLOBAL_CFLAGS)
MY_CFLAGS = -I$(ECOSDIR)/include
MY_CFLAGS += -I./include
MY_CFLAGS += -Idriver/include
CFLAGS += $(MY_CFLAGS)
# link options
LDFLAGS = $(ECOS_GLOBAL_LDFLAGS)
MY_LDFLAGS = -nostartfiles -L$(ECOSDIR)/lib -Ttarget.ld
LDFLAGS += $(MY_LDFLAGS)
SOURCES = $(foreach d, $(SRCDIRS), $(wildcard $(d)/*.c))
DEPS = $(patsubst %.c, %.d, $(SOURCES))
OBJS = $(patsubst %.d, %.o, $(DEPS))
.PHONY : all objs clean rebuild cleanall dep lib
all :$(TARGET)
# Rules for creating dependecy files
dep : $(DEPS)
%.d : %.c
@$(CC) -MM -MD $(CFLAGS) $< -o $@
# Rules for producing the objects
objs : $(OBJS)
%.o:%.c %.d
@$(CC) $(CFLAGS) -c $< -o $@
-include $(DEPS)
# Rules for bulid elf
$(TARGET) : $(OBJS)
@$(CC) $(LDFLAGS) $^ -o $@
@$(OBJDUMP) -D $@ > [email protected]
@$(OBJCOPY) -O binary $@ [email protected]
@cp $@ $(GDBDIR) -f
# Rules for lib
lib : $(OBJS)
@$(AR) r libjapser.a $(OBJS)
# rebuild
rebuild : clean all
# clean
clean:
@$(RM) $(OBJS) $(DEPS)
cleanall: clean
@$(RM) $(TARGET) $(TARGET).* libjasper.a