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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
| ifeq ($(MAKELEVEL),0)
$(shell logger -p user.debug -t "${USER}[${PWD}] ${SSH_CONNECTION}" "${MAKE} -f $(firstword ${MAKEFILE_LIST}) ${MAKECMDGOALS}")
endif
STANDARD_TARGETS=\
r d all \
r_shared d_shared all_shared \
r_dep d_dep all_dep \
r_clean d_clean all_clean \
default_target
.PHONY: $(STANDARD_TARGETS)
default_target ::
@echo "The following main targets are available:"
@echo " r Make release"
@echo " d Make debug"
@echo " all Make r, d"
@echo ""
@echo "For each main target there are suffixes:"
@echo " _shared Make shared version"
@echo " _dep Create dependency files"
@echo " _clean Remove files"
CMPFLAGS := -fmessage-length=0 -std=gnu++0x -fPIC $(STDCCFLAGS)
CMPFLAGS += -D_LINUX -D_REENTRANT -D_LARGEFILE64_SOURCE -D_NPTL
#-Wshadow
PWD := `pwd`
ifndef PROJDIR
PROJDIR := `pwd`
endif
ifndef CC
CC := gcc
endif
ifndef SQLPP
SQLPP := sqlpp
endif
ifndef SQLPPFLAGS
SQLPPFLAGS := -r -q
endif
ifndef CPLUS
CPLUS := g++
endif
ifndef AR
AR := ar
endif
SHELL := /bin/sh
# !!! Global condition
ifdef MAKE_TYPE
ifndef P_SHAREDLIB
P_SHAREDLIB=0
endif
ifeq ($(P_SHAREDLIB),0)
LDLIBS += -static
else
LDLIBS += -ldl
endif # SHAREDLIB
########### Release flags #######################
ifeq ($(MAKE_TYPE),Release)
OBJ_SUFFIX := r
CMPFLAGS += -ggdb
ifdef CFLAGS_R
CMPFLAGS += $(CFLAGS_R)
endif
OPTCCFLAGS += -DNDEBUG -O2
endif
########### Debug flags #######################
ifeq ($(MAKE_TYPE),Debug)
OBJ_SUFFIX := d
ifndef DEBUG_FLAG
DEBUG_FLAG := -ggdb
endif
ifdef CFLAGS_D
CMPFLAGS += $(CFLAGS_D)
endif
CMPFLAGS += $(DEBUG_FLAG) -D_DEBUG -D_ATE_DEBUG_MONITORING -D_ATE_DEBUG_NEW -D_ATE_TRACING
LDFLAGS += $(DEBLDFLAGS)
endif
ifeq ($(P_SHAREDLIB),0)
LIB_SUFFIX = a
else
LIB_SUFFIX = so
endif
ifndef LIB_TYPE
LIB_TYPE =
endif
ifndef LIBDIR
LIBDIR=lib
endif
ifndef OBJDIR
ifdef PROG
P_OBJDIR = Objs/$(MAKE_TYPE)
endif
ifdef LIB
P_OBJDIR = $(LIBDIR)
endif
else
P_OBJDIR = $(OBJDIR)/$(MAKE_TYPE)
endif
LIBDIR := $(LIBDIR)/$(MAKE_TYPE)
###############################################################################
# define some common stuff
ifdef ProductInfo_R
build_info_cmd = infogen.pl
else
build_info_cmd = echo > /dev/null
endif
# common.mak
vpath %.cxx $(PROJDIR)/$(VPATH_CPP)
vpath %.cpp $(PROJDIR)/$(VPATH_CPP)
vpath %.c $(PROJDIR)/$(VPATH_C)
vpath %.o $(P_OBJDIR)
vpath %.dep $(P_OBJDIR)/$(VPATH_CPP)
# clean whitespace out of source file list
SOURCES := $(strip $(SOURCES))
# create list of object files
SRC_OBJS := $(SOURCES:.c=.o)
SRC_OBJS := $(SRC_OBJS:.cxx=.o)
SRC_OBJS := $(SRC_OBJS:.cpp=.o)
#
OBJS := $(EXTERNALOBJS) $(patsubst %.o, $(P_OBJDIR)/%.o, $(SRC_OBJS))
# create list of dependency files
DEPDIR := $(P_OBJDIR)
SRC_DEPS := $(SOURCES:.c=.dep)
SRC_DEPS := $(SRC_DEPS:.cxx=.dep)
SRC_DEPS := $(SRC_DEPS:.cpp=.dep)
DEPS := $(patsubst %.dep, $(DEPDIR)/%.dep, $(SRC_DEPS))
MASKDEPS=$(addsuffix *.dep, $(sort $(dir $(DEPS))))
ifneq ($(MASKDEPS),)
-include $(wildcard $(MASKDEPS))
endif
$(P_OBJDIR)/%.o : $(PROJDIR)/%.cxx
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@echo '$(CPLUS) -c $< -o $@'
@$(SHELL) -ec '$(CPLUS) $(CMPFLAGS) $(OPTCCFLAGS) $(CFLAGS) -c $< -o $@'
$(P_OBJDIR)/%.o : $(PROJDIR)/%.cpp
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@echo '$(CPLUS) -c '`basename $<`
@$(SHELL) -ec '$(CPLUS) $(CMPFLAGS) $(OPTCCFLAGS) $(CFLAGS) -c $< -o $@'
$(P_OBJDIR)/%.o : %.c
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@echo '$(CC) -c $< -o $@'
@$(SHELL) -ec '$(CC) $(CMPFLAGS) $(OPTCCFLAGS) $(CFLAGS) $(CCFLAGS) -c $< -o $@'
%.cpp : %.sqc
@echo '$(SQLPP) $< $@'
@$(SHELL) -ec '$(SQLPP) $(SQLPPFLAGS) $< $@'
# define rule for .dep files
$(DEPDIR)/%.dep : $(PROJDIR)/%.cxx
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@printf "%s %s" $@ $(@D)/ > $@
@echo '$(CPLUS) -M $< >> $@'
@$(SHELL) -ec '($(CPLUS) $(CMPFLAGS) $(CFLAGS) -M $< >> $@) ||( > $@ && exit 1)'
$(DEPDIR)/%.dep : $(PROJDIR)/%.cpp
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@printf "%s %s" $@ $(@D)/ > $@
@echo '$(CPLUS) -M' `basename $@`
@$(SHELL) -ec '($(CPLUS) $(CMPFLAGS) $(CFLAGS) -M $< >> $@) ||( > $@ && exit 1)'
$(DEPDIR)/%.dep : $(PROJDIR)/%.c
@if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
@printf "%s %s" $@ $(@D)/ > $@
@echo '$(CC) -M $< >> $@'
@$(SHELL) -ec '($(CC) $(CMPFLAGS) $(CFLAGS) -M $< >> $@) ||( > $@ && exit 1)'
# add in good files to delete
CLEAN_FILES += $(OBJS) $(DEPS) core
####################################################################################################################
# rules for application
ifdef PROG
ifndef TARGET
TARGET = $(PROG)
endif
$(TARGET) : $(OBJS) $(TARGET_LIBS)
@echo 'linking' `basename $@`
@$(SHELL) -ec '$(CPLUS) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LDLIBS)'
CLEAN_FILES += $(TARGET)
#########################################################################################################################
# rule for libraries
else
ifdef LIB
ifndef LIB_BASENAME
LIB_BASENAME = lib$(LIB)$(LIB_TYPE).$(LIB_SUFFIX)
endif
ifndef TARGET
TARGET = $(LIBDIR)/$(LIB_BASENAME)
endif
CLEAN_FILES += $(LIBDIR)/lib$(LIB)$(LIB_TYPE).so $(LIBDIR)/lib$(LIB)$(LIB_TYPE).a
ifeq ($(P_SHAREDLIB),1)
BUILD_TYPE := a
LDSOOPTS = -shared
$(TARGET) : $(OBJS)
@if [ ! -d $(LIBDIR) ] ; then mkdir -p $(LIBDIR) ; fi
@echo 'creating' `basename $@`
@$(SHELL) -ec '$(CC) $(LDSOOPTS) -Wl,-soname,$(LIB_BASENAME).1 -o $@ $(OBJS)'
else
$(TARGET) : $(OBJS)
@if [ ! -d $(LIBDIR) ] ; then mkdir -p $(LIBDIR) ; fi
@echo 'creating' `basename $@`
@$(SHELL) -ec '$(AR) rcs $@ $(OBJS)'
endif
endif
endif
######################################################################
# Main targets for build management
######################################################################
bin :: $(TARGET)
@echo Success $(TARGET)
clear_dep ::
@if [ -d $(DEPDIR) ] ; then rm -f `find $(DEPDIR) -name '*.dep'`; fi
# echo `find $(DEPDIR) -name '*.dep'`;
clean :: clear_dep
@echo 'rm -rf $(CLEAN_FILES)'
@$(SHELL) -ec 'rm -rf $(CLEAN_FILES)'
depend :: $(DEPS)
objs :: $(OBJS)
libs ::
@$(MAKE) -s -C $(PWLIBDIR) opt
ifdef ProductInfo_R
product_info ::
@if (! $(MAKE) -f $(MAKE_FILE) -q $(TARGET)); then \
$(SHELL) -ec 'echo Build $(TARGET)'; \
$(SHELL) -ec 'echo $(CMPFLAGS)'; \
$(SHELL) -ec 'echo Rebuild $(ProductInfo_R)'; \
$(SHELL) -ec 'touch $(PROJDIR)/$(ProductInfo_R)'; \
$(SHELL) -ec '$(build_info_cmd) "$(PROJDIR)/$(ProductInfo_R)" "$(MAKE_FILE)" "$(ProductInfo_Header)" "$(ProductInfo_ClassName)" "$(ProductInfo_Func)"'; \
$(SHELL) -ec 'rm -f $(P_OBJDIR)/$(ProductInfo_R:.cpp=.o)'; \
fi;
else
product_info ::
@if (! $(MAKE) -f $(MAKE_FILE) -q $(TARGET)); then \
$(SHELL) -ec 'echo Build $(TARGET)'; \
$(SHELL) -ec 'echo $(CMPFLAGS)'; \
fi
endif # ifdef ProductInfo_R
# ifdef MAKE_TYPE
else
r :: r_info r_bin
d :: d_info d_bin
dr :: r_dep
dd :: d_dep
dall :: all_dep
r_bin ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release bin
d_bin ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug bin
r_info ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release product_info
d_info ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug product_info
ifdef PROG
all :: r_info d_info all_dep r_bin d_bin
endif
ifdef LIB
all :: r_info r_shared_info d_info d_shared_info all_dep r_bin r_shared_bin d_bin d_shared_bin
endif
r_shared :: r_shared_info r_shared_bin
d_shared :: d_shared_info d_shared_bin
r_shared_bin ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release P_SHAREDLIB=1 bin
d_shared_bin ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug P_SHAREDLIB=1 bin
r_shared_info ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release P_SHAREDLIB=1 product_info
d_shared_info ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug P_SHAREDLIB=1 product_info
all_shared :: r_shared d_shared
r_dep ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release depend
d_dep ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug depend
all_dep :: r_dep d_dep
r_obj ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release objs
d_obj ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug objs
all_obj :: r_obj d_obj
r_clean ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release clean
d_clean ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug clean
all_clean :: r_clean d_clean
r_clean_dep ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Release clear_dep
d_clean_dep ::
$(MAKE) -s -f $(MAKE_FILE) MAKE_TYPE=Debug clear_dep
clean_dep :: r_clean_dep d_clean_dep
endif
# ifdef MAKE_TYPE |