您尚未登录。

楼主 # 2022-01-22 22:38:57

cwd502
会员
注册时间: 2021-12-25
已发帖子: 5
积分: 2

通用makefile

###################################################################
#   通用makefile
#   ChenWenDong
###################################################################
MINIGUI_DIR = /opt/z1/miniGUI_3.0.12/output
CROSS_DIR = /usr/local/arm_linux_4.2

CROSS        = arm-linux-
SRCDIRS        = ./camera ./hal ./app ./timer

ASFLAGS        =
CFLAGS        = -O2 -Wall
CXXFLAGS    =
LDFLAGS        =
ARFLAGS        =
OCFLAGS        =
ODFLAGS        =

INCDIRS        = -I$(MINIGUI_DIR)/include/freetype2 \
          -I$(MINIGUI_DIR)/include \
          -I$(CROSS_DIR)/arm-linux/include \
          -I$(CROSS_DIR)/arm-none-linux-gnueabi/include

LIBDIRS        = -L$(MINIGUI_DIR)/lib \
          -L$(CROSS_DIR)/arm-none-linux-gnueabi/lib

LIBS         = -lminigui_ths -lfreetype -ljpeg -lpng -ldl -lm -lpthread -muclibc

#
### You shouldn't need to change anything below this point.
#
##
#AS     = $(CROSS)as
CC     = $(CROSS)gcc
CXX     = $(CROSS)g++
LD     = $(CROSS)gcc
AR     = $(CROSS)ar
OC     = $(CROSS)objcopy
OD     = $(CROSS)objdump
RM     = -rm -fr

NAME     := z1 #$(notdir $(CURDIR))
SFILES     := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s))
CFILES     := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp))
RMFILES     := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*~))
RMFILEO     := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.o))

OBJS      := $(SFILES:.s=.o) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
DEPS     := $(OBJS:.o=.d)
VPATH     := $(SRCDIRS)

.PHONY: all rebuild clean

all:
    @$(MAKE) $(NAME)

rebuild:
    @$(MAKE) clean
    @$(MAKE) $(NAME)

$(NAME):$(OBJS)
    @echo test linking ...
    $(LD) $(LDFLAGS) $(LIBDIRS) -o $@ $^ $(LIBS)

%.o:    %.s
    @echo assembling $< ...
    $(AS) $(ASFLAGS) $(INCDIRS) $< -o $@

%.o:    %.c
    @echo test compiling $< ...
    $(CC) $(CFLAGS) $(INCDIRS) -c $< -o $@
   
%.o:    %.cpp   
    @echo compiling $< ...
    $(CXX) $(CXXFLAGS) $(INCDIRS) -c $< -o $@
   
%.d:    %.c
    @$(CC) $(CFLAGS) $(INCDIRS) -MM $^ -o $@.tmp
    @sed 's,$(basename $(notdir $@)).o[ :]*,$(@:.d=.o) $@ : ,g' $@.tmp > $@
    @$(RM) $@.tmp
   
%.d:    %.cpp
    @$(CXX) $(CXXFLAGS) $(INCDIRS) -MM $^ -o $@.tmp
    @sed 's,$(basename $(notdir $@)).o[ :]*,$(@:.d=.o) $@ : ,g' $@.tmp > $@
    @$(RM) $@.tmp

ifeq (mach/mach,)
-include $(DEPS)
endif
   
clean:
    @$(RM) $(OBJS) $(DEPS) $(NAME) $(RMFILES) $(RMFILEO)
    @echo clean completed

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn