• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2CXX ?= g++
3CC ?= gcc
4LINK ?= $(CXX)
5SHARED_LINK ?= $(CXX)
6AR ?= ar
7STRIP ?= strip
8
9# The following macro will turn on combined
10# compilation and dependency generation
11COMBINED_COMPILE_AND_DEPEND:=1
12
13override SYSLIBS = -lc -lm -ldl -lstdc++ -lpthread
14
15SHARED_CFLAGS ?= -fPIC
16SHARED_CXXFLAGS ?= -fPIC
17SHARED_PRE_LDFLAGS ?= -shared -Wl,-Bsymbolic -Wl,--allow-multiple-definition -Wl,--whole-archive
18SHARED_POST_LDFLAGS ?= -Wl,-no-whole-archive -Wl,--no-undefined $(SYSLIBS)
19SONAME_ARG := -Wl,-h,
20
21STRIP_FLAGS := --strip-unneeded
22AR_ARGS := rl # make sure to leave a space at the end
23
24
25OUTLINKFLAG := -o
26CO := -c -o # make sure to leave a space at the end
27
28
29#Make all warnings into errors.
30FLAG_COMPILE_WARNINGS_AS_ERRORS := -Werror
31
32STAT_LIB_EXT:=a
33SHARED_LIB_EXT:=so
34SHARED_ARCHIVE_LIB_EXT:=sa
35OBJ_EXT := o
36LIBCOMPFLAG:=-L
37DEBUG_CXXFLAGS?=-g
38RELEASE_CPPFLAGS?=-DNDEBUG
39OPT_CXXFLAG?=-O3
40INCDIRS += -I$(BUILD_ROOT)/installed_include
41CXXFLAGS?=-Wall -Wno-non-virtual-dtor
42
43#########################################################
44# $(call make-depend,source-file,object-file,depend-file,xflags)
45define make-depend
46  $(quiet) $(CXX) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) -MM $1 |        \
47   $(SED) -e 's,\($(notdir $2)\) *:,$2: ,' -e 's,$(BUILD_ROOT),$$(BUILD_ROOT),'  -e 's,$(SRC_ROOT),$$(SRC_ROOT),' > $3.tmp
48  $(quiet) $(CP) $3.tmp $3
49  $(quiet) $(SED) -e 's/#.*//'  \
50	-e 's/^[^:]*: *//'      \
51	-e 's/ *\\$$//'		\
52	-e '/^$$/ d'		\
53	-e 's/$$/ :/'  $3.tmp >> $3
54  $(quiet) $(RM) $3.tmp
55endef
56#########################################################
57
58
59ifneq ($(strip $(COMBINED_COMPILE_AND_DEPEND)),)
60#########################################################
61# $(call combined-cxx-compile-depend,source-file,object-file,depend-file,xflags)
62define combined-cxx-compile-depend
63  $(quiet) $(CXX) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) -MMD $(CO)$2 $1
64  $(quiet) $(SED) -e '/^ *\\ *$$/ d' -e 's,$(BUILD_ROOT),$$(BUILD_ROOT),'  -e 's,$(SRC_ROOT),$$(SRC_ROOT),' $3 > $3.tmp
65  $(quiet) $(CP) $3.tmp $3
66  $(quiet) $(SED) -e 's/#.*//'  \
67	-e 's/^[^:]*: *//'      \
68	-e 's/ *\\$$//'		\
69	-e '/^$$/ d'		\
70	-e 's/$$/ :/'  $3.tmp >> $3
71  $(quiet) $(RM) $3.tmp
72endef
73#########################################################
74
75# $(call combined-cc-compile-depend,source-file,object-file,depend-file,xflags)
76define combined-cc-compile-depend
77  $(quiet) $(CC) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) -MMD $(CO)$2 $1
78  $(quiet) $(SED) -e '/^ *\\ *$$/ d' -e 's,$(BUILD_ROOT),$$(BUILD_ROOT),'  -e 's,$(SRC_ROOT),$$(SRC_ROOT),' $3 > $3.tmp
79  $(quiet) $(CP) $3.tmp $3
80  $(quiet) $(SED) -e 's/#.*//'  \
81	-e 's/^[^:]*: *//'      \
82	-e 's/ *\\$$//'		\
83	-e '/^$$/ d'		\
84	-e 's/$$/ :/'  $3.tmp >> $3
85  $(quiet) $(RM) $3.tmp
86endef
87#########################################################
88
89define assembly-compile
90  $(quiet) $(CXX) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) -MD $(CO)$2 $1
91endef
92#########################################################
93endif
94
95
96#########################################################
97
98define generate_prog
99  $(quiet) $(LINK) $(BINDING) $(OUTLINKFLAG)$1 $($2_compiled_objs) $(filter $(LIBCOMPFLAG)%,$($2_LDFLAGS)) \
100  $(PRE_LDFLAGS) $(XOBJECTS)  $(filter-out $(LIBCOMPFLAG)%,$($2_LDFLAGS)) $(POST_LDFLAGS) $(SYSLIBS)
101  $(if $(filter release,$(strip $(DEFAULT_LIBMODE))),$(call strip_binary,$1))
102endef
103
104#########################################################
105
106define generate_static_lib
107  $(quiet) $(AR) $(AR_ARGS)$1  $2
108endef
109
110#########################################################
111
112define generate_shared-archive_lib
113  $(quiet) $(AR) $(AR_ARGS)$1  $2
114endef
115
116
117#########################################################
118
119define generate_shared_lib
120  $(quiet) $(SHARED_LINK) $(SHARED_PRE_LDFLAGS) $(SONAME_ARG)$(notdir $1) -o $1 $2 $(SHARED_POST_LDFLAGS)
121  $(if $(filter release,$(strip $(DEFAULT_LIBMODE))),$(call strip_binary,$1))
122endef
123
124define strip_binary
125  $(quiet) $(STRIP) $(STRIP_FLAGS) $1
126endef
127