-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
146 lines (107 loc) · 3.32 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
################################################################################
# Author: chenyigeng
# Date: 2013-07-06
# Desc: the makefile is for compiling all project
################################################################################
# the distinguish between = and := ,to a=$(a), := will be assiged only once,= will be compile error.
#set your project name
PRJ_NAME =LdpApiServer
#PRJ_NAME=libtest.so
#set your project type : choose one below
#PRJ_TYPE = g++ -shared -fPIC
PRJ_TYPE = g++
#PRJ_TYPE = ar -r
#set Debug or Release
Compile_Flag = Debug
#Compile_Flag = Release
#set your output path
Output:= ./objs
#set your source folder
SRC:= ./src
#add the lib you used here
#LIBS := -lLib1 -lLib2 -lLib3
LIBS := -lpthread -lssl -lcrypto -lrt -ldl -lm
#¾²Ì¬¿âÒª·ÅÔÚºóÃæÁ´½Ó
STATIC_LIBS:= ./lib/redis/libhiredis.a ./lib/json/libjson_linux-gcc-4.4.7_libmt.a ./lib/mysql/libmysqlclient.a ./lib/mysql/libmysqlservices.a
#LIBPATH := -Lpath1 -Lpath2 -Lpath3
LIBPATH :=
INCLUDEPATH:= -I/usr/inclde -I./include/ -I./include/mysql -I./include/mysql/mysql -I./include/mysql/mysql/psi
# INCLUDEPATH := -I/usr/lib/XXX/include
###################################
#DON"T MODIFY THE BELOWS
#combine output folder
FinalOutput := $(Output)/
#list all dirs
SUBDIRS := $(shell find $(SRC) -type d)
#CLEAN2 := $(shell find $(Output) -type f|xargs rm)
#flags in makefile
DEBUG_FLAG = -O0 -g3 -Wall -c -fmessage-length=0
RELEASE_FLAG = -O3 -Wall -c -fmessage-length=0
RM:= rm -rf
#set compile flag
ifeq ($(Compile_Flag),Debug)
CFLAGS := $(DEBUG_FLAG)
else
CFLAGS := $(RELEASE_FLAG)
endif
#prepare files
CPP_SRCS:=$(shell find $(SRC) -name *.cpp)
CPP_OBJS:=$(CPP_SRCS:%.cpp=$(FinalOutput)%.o)
CC_SRCS:=$(shell find $(SRC) -name *.cc)
CC_OBJS:=$(CC_SRCS:%.cc=$(FinalOutput)%.o)
C_SRCS:=$(shell find $(SRC) -name *.c)
C_OBJS:=$(C_SRCS:%.c=$(FinalOutput)%.o)
OBJS+=$(CPP_OBJS)
OBJS+=$(CC_OBJS)
OBJS+=$(C_OBJS)
#all target
#OBJS_CNT:=$(shell find ./ -type d -name $(Output)|wc -l)
OBJS_CNT:=$(shell find ./ -type d -wholename $(Output)|wc -l)
ifeq ($(OBJS_CNT),1)
ALL_TARTET+=$(PRJ_NAME)
else
ALL_TARTET+=dir
ALL_TARTET+=$(PRJ_NAME)
endif
all:$(ALL_TARTET)
#all1 :$(PRJ_NAME)
#all2 :dir $(PRJ_NAME)
dir:
mkdir -p $(FinalOutput);
for val in $(SUBDIRS);do \
mkdir -p $(FinalOutput)$${val}; \
done;
#tool invocations
$(PRJ_NAME):$(OBJS)
@echo 'Building target: $@'
@echo 'Invoking:GCC C++ Linker'
$(PRJ_TYPE) $(LIBS) $(LIBPATH) -o "$@" $^ $(STATIC_LIBS)
@echo 'Finished building target: $@'
@echo ' '
$(FinalOutput)%o:./%cpp
@echo 'Building file: $<'
@echo 'Invoking:GCC C++ Compiler'
$(PRJ_TYPE) $(CFLAGS) $(INCLUDEPATH) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(FinalOutput)%o:./%cc
@echo 'Building file: $<'
@echo 'Invoking:GCC C++ Compiler'
$(PRJ_TYPE) $(CFLAGS) $(INCLUDEPATH) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(FinalOutput)%o:./%c
@echo 'Building file: $<'
@echo 'Invoking:GCC C++ Compiler'
$(PRJ_TYPE) $(CFLAGS) $(INCLUDEPATH) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
#other targets
clean:
-$(shell find $(Output) -type f|xargs rm) $(RM) $(PRJ_NAME)
-@echo ' '
clean2:
-$(RM) $(Output) $(PRJ_NAME)
-@echo ' '
.PHONY:all clean
.SECONDARY: