Chinaunix首页 | 论坛 | 博客
  • 博客访问: 732553
  • 博文数量: 77
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1173
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-16 11:20
个人简介

将技术做到极致...

文章分类

全部博文(77)

文章存档

2019年(3)

2015年(27)

2014年(47)

分类: LINUX

2014-06-17 15:55:29

    这里有一个相对比较好用的makefile模板,用来编译动态库的。
#####################################################################
#
# Work Environment:  Unix/Win32
#
######################################################

#
# Path to GNU Toolchain
#
TOOLS     = arm-unknown-linux-gnu-     //这里是你的交叉编译工具

#
# Tools used to build the library
#
CC = $(TOOLS)gcc
CPP = $(TOOLS)g++
AR = $(TOOLS)ar
REMOVE = rm -f
COPY = cp -f

ifdef DEBUG
LIBDBG = _debug
else
LIBDBG =
endif

LIBNAME      =   libxxxi$(LIBDBG).a
LIBNAME_SHARED    =   libxxx$(LIBDBG).so
LIBSONAME     =   libxxx$(LIBDBG).so


# Source, Include and Build directories
SRCDIR = ./src      //源文件路径
INCDIR = ./inc -I../api/inc   //头文件路径
RELDIR  = ./build 
OBJDIR    = ./build

VPATH = $(SRCDIR)

#####################################################################
# Rules for building source files
#
#Compiler flags
CFLAGS = -Wall -Wno-comment -c -fPIC
CFLAGS += -D_MAKE_ARM_LINUX_ -DMAKE_VIKING
CFLAGS += -I. -I $(INCDIR)
# Check if debug or release build
ifndef DEBUG
CFLAGS += -Os
else
CFLAGS += -O0 -g3 -D_DEBUG    //-O0不优化,-g gdb调试
endif

####################################################################
# Source file list
#
SRC=$(wildcard $(VPATH)/*.c)
CPPSRC=$(wildcard $(VPATH)/*.cpp)

# Define all object files.
COBJ = $(patsubst $(VPATH)/%.c,%.o, $(SRC))
CPPOBJ += $(patsubst $(VPATH)/%.cpp,%.o, $(CPPSRC))

#DEPS = $(addprefix $(OBJDIR)/, $(patsubst %.o,%.d, $(COBJ)))

# Default target.
default: all

all: $(LIBNAME)

$(LIBNAME): copyfiles $(COBJ) $(CPPOBJ) buildlib package

# Compile: create object files from C source files.
$(COBJ): %.o : %.c
 @echo "Compiling..."
 $(CC) $(CFLAGS) $< -o $(OBJDIR)/$@

# Compile: create object files from CPP source files.
$(CPPOBJ): %.o : %.cpp
 @echo "Compiling..."
 $(CPP) $(CFLAGS) $< -o $(OBJDIR)/$@
 
depend: $(subst .o,.deps,$(COBJ)$(CPPOBJ))

%.deps: %.c
 $(CC) $(CFLAGS) -MM $< > $(OBJDIR)/$@
 
buildlib:
 @echo "Building Library...  $(LIBNAME)"
 $(AR) r $(OBJDIR)/$(LIBNAME) $(addprefix $(OBJDIR)/, $(COBJ) $(CPPOBJ))
 $(CC) -shared -Wl,-soname,$(LIBSONAME) -o $(OBJDIR)/$(LIBNAME_SHARED)  $(addprefix $(OBJDIR)/, $(COBJ) $(CPPOBJ)) -lc
 
copyfiles:
 @echo "Copying Files"
 @echo $(DEPS)
# cp -f ../ARM/inc/hyctypes.h ./inc/

package:
 @echo "Creating Release Package...  $(LIBNAME)"
 @rm -f ReleasePackage/*
 @cp -f build/*.a ReleasePackage/
 @cp -f build/*.so* ReleasePackage/
 @cp -f inc/xxx.h ./ReleasePackage/
 @cp -f inc/xxxxxx.h ./ReleasePackage/

clean:
 @rm -f ReleasePackage/*
 @rm -f build/*

阅读(2078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~