Makefile 同时编译静态库和动态库
[code lang=”cpp”]# XJ通用工具类库编译
# LiXiujie
# 20151010

DIR_SRC = ./src
DIR_INC = ./include
DIR_LIB = ./lib
SRC = $(wildcard ${DIR_SRC}/*.cpp)
OBJS = $(patsubst %.cpp,${DIR_SRC}/%.o,$(notdir ${SRC}))

LocalDate = $(shell date +"%Y%m%d")
LocalTime = $(shell date +"%H%M%S")
LocalYear = $(shell date +"%y")
LocalMonth = $(shell date +"%m")
LocalDay = $(shell date +"%d")

RM = rm -fr
AR = ar crv
CC = g++
FLAG = -g -D__DEBUG__ -w
SHARED = -shared
##XJ_FPIC = -fPIC

LIB_OBJECT_SO = libXJUtilClass.so.$(LocalYear).$(LocalMonth).$(LocalDay)
LIB_OBJECT_A = libXJUtilClass.a.$(LocalYear).$(LocalMonth).$(LocalDay)

TARGET = $(LIB_OBJECT_SO) $(LIB_OBJECT_A)

LIB_PATH = -L/usr/lib64 -L/lib64 -L/usr/local/lib -L/usr/local/apr/lib\
-L$(HOME)/lib -L$(HOME)/lib/public \
-L$(TUXDIR)/lib \
-L${HOME}/lib/json \
-L$(ORACLE_HOME)/lib -L$(ORACLE_HOME)/precomp/lib \
-L$(ORACLE_HOME)/rdbms/lib -L$(ORACLE_HOME)/sqlplus/lib \
-L$(ORACLE_HOME)/network/lib -L$(ORACLE_HOME)/plsql/lib \
-L../lib -Llib

INC_PATH = -I${HOME}/include -I$(HOME)/include/public \
-I$(ORACLE_HOME)/rdbms/public -I$(ORACLE_HOME)/rdbms/demo \
-I$(ORACLE_HOME)/precomp/public -I$(ORACLE_HOME)/plsql/public \
-I$(ORACLE_HOME)/include \
-I../include -I$(DIR_INC)

all:
-rm -f $(OBJS)
make so
-rm -f $(OBJS)
make a
@echo $(LIB_OBJECT_SO) "OK"
@echo $(LIB_OBJECT_A) "OK"

so: $(LIB_OBJECT_SO)

a: $(LIB_OBJECT_A)

${DIR_SRC}/%.o:${DIR_SRC}/%.cpp
$(CC) -c $< $(INC_PATH) $(FLAG) $(XJ_FPIC) -o $@

$(LIB_OBJECT_SO): XJ_FPIC = -fPIC

$(LIB_OBJECT_SO): $(OBJS)
$(CC) $? $(FLAG) $(LIB_PATH) $(INC_PATH) $(SHARED) -o $(DIR_LIB)/$@
@echo "["$@"]Compile complete"

$(LIB_OBJECT_A): XJ_FPIC =
$(LIB_OBJECT_A): $(OBJS)
$(AR) $(DIR_LIB)/$@ $(OBJS)
@echo "["$@"]Compile complete"

clean:
@echo remove all object files and lib
-rm -f $(DIR_LIB)/* $(OBJS) *.o

demo:
$(CC) XJStringUtilMain.cpp -o mainXJStringUtil $(INC_PATH) -lXJUtilClass [/code]

发表评论