Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | # GRPC global makefile |
| 2 | # This currently builds C and C++ code. |
| 3 | <%! |
| 4 | from copy import deepcopy |
| 5 | import re |
| 6 | |
| 7 | def excluded(filename, exclude_res): |
| 8 | for r in exclude_res: |
| 9 | if r.match(filename): |
| 10 | return True |
| 11 | return False |
| 12 | %> |
| 13 | |
| 14 | <% |
| 15 | altlibs = [] |
| 16 | for lib in libs: |
| 17 | for alt in lib.get('alternates', []): |
| 18 | new = deepcopy(lib) |
| 19 | new.name = alt.name |
| 20 | new.alternates = [] |
| 21 | exclude_res = [re.compile(str) for str in alt.get('exclude_res', [])] |
| 22 | |
| 23 | src = [file for file in new.get('src', []) if not excluded(file, exclude_res)] |
| 24 | src.extend(alt.get('include_src', [])) |
| 25 | new.src = src |
| 26 | |
| 27 | headers = [file for file in new.get('headers', []) if not excluded(file, exclude_res)] |
| 28 | headers.extend(alt.get('include_headers', [])) |
| 29 | new.headers = headers |
| 30 | |
| 31 | public_headers = [file for file in new.get('public_headers', []) if not excluded(file, exclude_res)] |
| 32 | public_headers.extend(alt.get('include_public_headers', [])) |
| 33 | new.public_headers = public_headers |
| 34 | |
| 35 | for prop in alt.properties: |
| 36 | new[prop.name] = prop.value |
| 37 | |
| 38 | altlibs.append(new) |
| 39 | libs.extend(altlibs) |
| 40 | |
| 41 | protos_dict = {} |
| 42 | proto_re = re.compile('\.proto$') |
| 43 | for lib in libs: |
| 44 | for src in lib.src: |
| 45 | if proto_re.match(src): |
| 46 | protos_dict[src] = True |
| 47 | for tgt in targets: |
| 48 | for src in tgt.src: |
| 49 | if proto_re.match(src): |
| 50 | protos_dict[src] = True |
| 51 | |
| 52 | protos = [] |
| 53 | for k, v in protos_dict: |
| 54 | protos.append(k) |
| 55 | %> |
| 56 | |
| 57 | # General settings. |
| 58 | # You may want to change these depending on your system. |
| 59 | |
| 60 | prefix ?= /usr/local |
| 61 | |
| 62 | PROTOC = protoc |
| 63 | CC = gcc |
| 64 | CXX = g++ |
| 65 | LD = gcc |
| 66 | LDXX = g++ |
| 67 | AR = ar |
| 68 | STRIP = strip --strip-unneeded |
| 69 | INSTALL = install -D |
| 70 | RM = rm -f |
| 71 | |
| 72 | ifeq ($(DEBUG),) |
| 73 | CPPFLAGS += -O2 |
| 74 | DEFINES += NDEBUG |
| 75 | else |
| 76 | CPPFLAGS += -O0 |
| 77 | DEFINES += _DEBUG DEBUG |
| 78 | endif |
| 79 | |
| 80 | CFLAGS += -std=c89 -pedantic |
| 81 | CXXFLAGS += -std=c++11 |
| 82 | CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long |
| 83 | LDFLAGS += -g -pthread -fPIC |
| 84 | |
| 85 | INCLUDES = . include gens |
| 86 | LIBS = rt m z event event_pthreads pthread |
| 87 | LIBSXX = protobuf |
| 88 | LIBS_SECURE = ssl crypto dl |
| 89 | |
| 90 | ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),) |
| 91 | GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest |
| 92 | else |
| 93 | GTEST_LIB = -lgtest |
| 94 | endif |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame^] | 95 | GTEST_LIB += -lgflags |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 96 | ifeq ($(V),1) |
| 97 | E = @: |
| 98 | Q = |
| 99 | else |
| 100 | E = @echo |
| 101 | Q = @ |
| 102 | endif |
| 103 | |
| 104 | VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build} |
| 105 | |
| 106 | CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) |
| 107 | CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) |
| 108 | |
| 109 | LDFLAGS += $(ARCH_FLAGS) |
| 110 | LDLIBS += $(addprefix -l, $(LIBS)) |
| 111 | LDLIBSXX += $(addprefix -l, $(LIBSXX)) |
| 112 | LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) |
| 113 | |
| 114 | .SECONDARY = %.pb.h %.pb.cc |
| 115 | |
| 116 | all: static shared\ |
| 117 | % for tgt in targets: |
| 118 | % if tgt.build == 'all': |
| 119 | bins/${tgt.name}\ |
| 120 | % endif |
| 121 | % endfor |
| 122 | |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 123 | static: static_c static_cxx |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 124 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 125 | static_c: dep_c\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 126 | % for lib in libs: |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 127 | % if lib.build == 'all' and not lib.get('c++', False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 128 | libs/lib${lib.name}.a\ |
| 129 | % endif |
| 130 | % endfor |
| 131 | |
| 132 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 133 | static_cxx: dep_cxx\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 134 | % for lib in libs: |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 135 | % if lib.build == 'all' and lib.get('c++', False): |
| 136 | libs/lib${lib.name}.a\ |
| 137 | % endif |
| 138 | % endfor |
| 139 | |
| 140 | |
| 141 | shared: shared_c shared_cxx |
| 142 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 143 | shared_c: dep_c\ |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 144 | % for lib in libs: |
| 145 | % if lib.build == 'all' and not lib.get('c++', False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 146 | libs/lib${lib.name}.so.$(VERSION)\ |
| 147 | % endif |
| 148 | % endfor |
| 149 | |
| 150 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 151 | shared_cxx: dep_cxx\ |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 152 | % for lib in libs: |
| 153 | % if lib.build == 'all' and lib.get('c++', False): |
| 154 | libs/lib${lib.name}.so.$(VERSION)\ |
| 155 | % endif |
| 156 | % endfor |
| 157 | |
| 158 | |
| 159 | privatelibs: privatelibs_c privatelibs_cxx |
| 160 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 161 | privatelibs_c: dep_c\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 162 | % for lib in libs: |
| 163 | % if lib.build == 'private': |
| 164 | libs/lib${lib.name}.a\ |
| 165 | % endif |
| 166 | % endfor |
| 167 | |
| 168 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 169 | privatelibs_cxx: dep_cxx\ |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 170 | % for lib in libs: |
| 171 | % if lib.build == 'private': |
| 172 | libs/lib${lib.name}.a\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 173 | % endif |
| 174 | % endfor |
| 175 | |
| 176 | |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 177 | buildtests: buildtests_c buildtests_cxx |
| 178 | |
| 179 | buildtests_c: privatelibs_c\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 180 | % for tgt in targets: |
| 181 | % if tgt.build == 'test' and not tgt.get('c++', False): |
| 182 | bins/${tgt.name}\ |
| 183 | % endif |
| 184 | % endfor |
| 185 | |
| 186 | |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 187 | buildtests_cxx: privatelibs_cxx\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 188 | % for tgt in targets: |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 189 | % if tgt.build == 'test' and tgt.get('c++', False): |
| 190 | bins/${tgt.name}\ |
| 191 | % endif |
| 192 | % endfor |
| 193 | |
| 194 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 195 | test: test_c test_cxx |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 196 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 197 | test_c: buildtests_c |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 198 | % for tgt in targets: |
| 199 | % if tgt.build == 'test' and tgt.get('run', True) and not tgt.get('c++', False): |
| 200 | $(E) "[RUN] Testing ${tgt.name}" |
| 201 | $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) |
| 202 | % endif |
| 203 | % endfor |
| 204 | |
| 205 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 206 | test_cxx: buildtests_cxx |
nnoble | 29e1d29 | 2014-12-01 10:27:40 -0800 | [diff] [blame] | 207 | % for tgt in targets: |
| 208 | % if tgt.build == 'test' and tgt.get('run', True) and tgt.get('c++', False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 209 | $(E) "[RUN] Testing ${tgt.name}" |
| 210 | $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) |
| 211 | % endif |
| 212 | % endfor |
| 213 | |
| 214 | |
| 215 | tools: privatelibs\ |
| 216 | % for tgt in targets: |
| 217 | % if tgt.build == 'tool': |
| 218 | bins/${tgt.name}\ |
| 219 | % endif |
| 220 | % endfor |
| 221 | |
| 222 | |
| 223 | buildbenchmarks: privatelibs\ |
| 224 | % for tgt in targets: |
| 225 | % if tgt.build == 'benchmark': |
| 226 | bins/${tgt.name}\ |
| 227 | % endif |
| 228 | % endfor |
| 229 | |
| 230 | |
| 231 | benchmarks: buildbenchmarks |
| 232 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 233 | strip: strip-static strip-shared |
| 234 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 235 | strip-static_c: static_c |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 236 | % for lib in libs: |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 237 | % if not lib.get("c++", False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 238 | % if lib.build == "all": |
| 239 | $(E) "[STRIP] Stripping lib${lib.name}.a" |
| 240 | $(Q) $(STRIP) libs/lib${lib.name}.a |
| 241 | % endif |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 242 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 243 | % endfor |
| 244 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 245 | strip-static_cxx: static_cxx |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 246 | % for lib in libs: |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 247 | % if lib.get("c++", False): |
| 248 | % if lib.build == "all": |
| 249 | $(E) "[STRIP] Stripping lib${lib.name}.a" |
| 250 | $(Q) $(STRIP) libs/lib${lib.name}.a |
| 251 | % endif |
| 252 | % endif |
| 253 | % endfor |
| 254 | |
| 255 | strip-shared_c: shared_c |
| 256 | % for lib in libs: |
| 257 | % if not lib.get("c++", False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 258 | % if lib.build == "all": |
| 259 | $(E) "[STRIP] Stripping lib${lib.name}.so" |
| 260 | $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION) |
| 261 | % endif |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 262 | % endif |
| 263 | % endfor |
| 264 | |
| 265 | strip-shared_cxx: shared_cxx |
| 266 | % for lib in libs: |
| 267 | % if lib.get("c++", False): |
| 268 | % if lib.build == "all": |
| 269 | $(E) "[STRIP] Stripping lib${lib.name}.so" |
| 270 | $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION) |
| 271 | % endif |
| 272 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 273 | % endfor |
| 274 | |
| 275 | gens/%.pb.cc : %.proto |
| 276 | $(E) "[PROTOC] Generating protobuf CC file from $<" |
| 277 | $(Q) mkdir -p `dirname $@` |
| 278 | $(Q) $(PROTOC) --cpp_out=gens $< |
| 279 | |
| 280 | deps/%.dep : %.c |
| 281 | $(E) "[DEP] Generating dependencies for $<" |
| 282 | $(Q) mkdir -p `dirname $@` |
| 283 | $(Q) $(CC) $(CFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@ |
| 284 | |
| 285 | deps/%.dep : gens/%.pb.cc |
| 286 | $(E) "[DEP] Generating dependencies for $<" |
| 287 | $(Q) mkdir -p `dirname $@` |
| 288 | $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@ |
| 289 | |
| 290 | deps/%.dep : %.cc |
| 291 | $(E) "[DEP] Generating dependencies for $<" |
| 292 | $(Q) mkdir -p `dirname $@` |
| 293 | $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@ |
| 294 | |
| 295 | objs/%.o : %.c |
| 296 | $(E) "[C] Compiling $<" |
| 297 | $(Q) mkdir -p `dirname $@` |
| 298 | $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< |
| 299 | |
| 300 | objs/%.o : gens/%.pb.cc |
| 301 | $(E) "[CXX] Compiling $<" |
| 302 | $(Q) mkdir -p `dirname $@` |
| 303 | $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< |
| 304 | |
| 305 | objs/%.o : %.cc |
| 306 | $(E) "[CXX] Compiling $<" |
| 307 | $(Q) mkdir -p `dirname $@` |
| 308 | $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< |
| 309 | |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 310 | dep: dep_c dep_cxx |
| 311 | |
| 312 | dep_c:\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 313 | % for lib in libs: |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 314 | % if not lib.get('c++', False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 315 | deps_lib${lib.name}\ |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 316 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 317 | % endfor |
| 318 | % for tgt in targets: |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 319 | % if not tgt.get('c++', False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 320 | deps_${tgt.name}\ |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 321 | % endif |
| 322 | % endfor |
| 323 | |
| 324 | |
| 325 | dep_cxx:\ |
| 326 | % for lib in libs: |
| 327 | % if lib.get('c++', False): |
| 328 | deps_lib${lib.name}\ |
| 329 | % endif |
| 330 | % endfor |
| 331 | % for tgt in targets: |
| 332 | % if tgt.get('c++', False): |
| 333 | deps_${tgt.name}\ |
| 334 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 335 | % endfor |
| 336 | |
| 337 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 338 | install: install_c install_cxx |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 339 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 340 | install_c: install-headers_c install-static_c install-shared_c |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 341 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 342 | install_cxx: install-headers_cxx install-static_cxx install-shared_cxx |
| 343 | |
| 344 | install-headers: install-headers_c install-headers_cxx |
| 345 | |
| 346 | install-headers_c: |
| 347 | $(E) "[INSTALL] Installing public C headers" |
| 348 | $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 |
| 349 | |
| 350 | install-headers_cxx: |
| 351 | $(E) "[INSTALL] Installing public C++ headers" |
| 352 | $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 |
| 353 | |
| 354 | install-static: install-static_c install-static_cxx |
| 355 | |
| 356 | install-static_c: static_c strip-static_c |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 357 | % for lib in libs: |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 358 | % if not lib.get("c++", False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 359 | % if lib.build == "all": |
| 360 | $(E) "[INSTALL] Installing lib${lib.name}.a" |
| 361 | $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a |
| 362 | % endif |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 363 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 364 | % endfor |
| 365 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 366 | install-static_cxx: static_cxx strip-static_cxx |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 367 | % for lib in libs: |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 368 | % if lib.get("c++", False): |
| 369 | % if lib.build == "all": |
| 370 | $(E) "[INSTALL] Installing lib${lib.name}.a" |
| 371 | $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a |
| 372 | % endif |
| 373 | % endif |
| 374 | % endfor |
| 375 | |
| 376 | install-shared_c: shared_c strip-shared_c |
| 377 | % for lib in libs: |
| 378 | % if not lib.get("c++", False): |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 379 | % if lib.build == "all": |
| 380 | $(E) "[INSTALL] Installing lib${lib.name}.so" |
| 381 | $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION) |
| 382 | % endif |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 383 | % endif |
| 384 | % endfor |
| 385 | |
| 386 | install-shared_cxx: shared_cxx strip-shared_cxx |
| 387 | % for lib in libs: |
| 388 | % if lib.get("c++", False): |
| 389 | % if lib.build == "all": |
| 390 | $(E) "[INSTALL] Installing lib${lib.name}.so" |
| 391 | $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION) |
| 392 | % endif |
| 393 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 394 | % endfor |
| 395 | |
| 396 | clean:\ |
| 397 | % for lib in libs: |
| 398 | clean_lib${lib.name}\ |
| 399 | % endfor |
| 400 | % for tgt in targets: |
| 401 | clean_${tgt.name}\ |
| 402 | % endfor |
| 403 | |
| 404 | $(Q) $(RM) -r deps objs libs bins gens |
| 405 | |
| 406 | |
| 407 | # The various libraries |
| 408 | |
| 409 | % for lib in libs: |
| 410 | ${makelib(lib)} |
| 411 | % endfor |
| 412 | |
| 413 | |
| 414 | # All of the test targets |
| 415 | |
| 416 | % for tgt in targets: |
| 417 | ${maketarget(tgt)} |
| 418 | % endfor |
| 419 | |
| 420 | <%def name="makelib(lib)"> |
| 421 | LIB${lib.name.upper()}_SRC = \\ |
| 422 | |
| 423 | % for src in lib.src: |
| 424 | ${src} \\ |
| 425 | |
| 426 | % endfor |
| 427 | |
| 428 | % if "public_headers" in lib: |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 429 | % if lib.get("c++", False): |
| 430 | PUBLIC_HEADERS_CXX += \\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 431 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 432 | % else: |
| 433 | PUBLIC_HEADERS_C += \\ |
| 434 | |
| 435 | % endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 436 | % for hdr in lib.public_headers: |
| 437 | ${hdr} \\ |
| 438 | |
| 439 | % endfor |
| 440 | % endif |
| 441 | |
| 442 | LIB${lib.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC)))) |
| 443 | LIB${lib.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(LIB${lib.name.upper()}_SRC)))) |
| 444 | |
| 445 | libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS) |
| 446 | $(E) "[AR] Creating $@" |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 447 | $(Q) mkdir -p `dirname $@` |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 448 | $(Q) $(AR) rcs libs/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) |
| 449 | |
| 450 | % if lib.build == "all": |
| 451 | libs/lib${lib.name}.so.$(VERSION): $(LIB${lib.name.upper()}_OBJS) |
| 452 | $(E) "[LD] Linking $@" |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 453 | $(Q) mkdir -p `dirname $@` |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 454 | % if lib.get('c++', False): |
| 455 | $(Q) $(LDXX) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \ |
| 456 | % else: |
| 457 | $(Q) $(LD) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \ |
| 458 | % endif |
| 459 | -o libs/lib${lib.name}.so.$(VERSION) $(LIB${lib.name.upper()}_OBJS) $(LDLIBS)\ |
| 460 | % if lib.secure: |
| 461 | $(LDLIBS_SECURE) |
| 462 | % endif |
| 463 | % endif |
| 464 | |
| 465 | |
| 466 | deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS) |
| 467 | |
| 468 | ifneq ($(MAKECMDGOALS),clean) |
| 469 | -include $(LIB${lib.name.upper()}_DEPS) |
| 470 | endif |
| 471 | |
| 472 | clean_lib${lib.name}: |
| 473 | $(E) "[CLEAN] Cleaning lib${lib.name} files" |
| 474 | $(Q) $(RM) $(LIB${lib.name.upper()}_OBJS) |
| 475 | $(Q) $(RM) $(LIB${lib.name.upper()}_DEPS) |
| 476 | $(Q) $(RM) libs/lib${lib.name}.a |
| 477 | $(Q) $(RM) libs/lib${lib.name}.so.$(VERSION) |
| 478 | </%def> |
| 479 | |
| 480 | <%def name="maketarget(tgt)"> |
| 481 | ${tgt.name.upper()}_SRC = \\ |
| 482 | |
| 483 | % for src in tgt.src: |
| 484 | ${src} \\ |
| 485 | |
| 486 | % endfor |
| 487 | |
| 488 | ${tgt.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC)))) |
| 489 | ${tgt.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(${tgt.name.upper()}_SRC)))) |
| 490 | |
| 491 | bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\ |
| 492 | % for dep in tgt.deps: |
| 493 | libs/lib${dep}.a\ |
| 494 | % endfor |
| 495 | |
| 496 | $(E) "[LD] Linking $@" |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 497 | $(Q) mkdir -p `dirname $@` |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 498 | % if tgt.get("c++", False): |
| 499 | $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS) $(GTEST_LIB) -Llibs\ |
| 500 | % else: |
| 501 | $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS) -Llibs\ |
| 502 | % endif |
| 503 | % for dep in tgt.deps: |
| 504 | -l${dep}\ |
| 505 | % endfor |
| 506 | % if tgt.get("c++", False): |
| 507 | $(LDLIBSXX)\ |
| 508 | % endif |
| 509 | $(LDLIBS)\ |
| 510 | % if tgt.get('secure', True): |
| 511 | $(LDLIBS_SECURE)\ |
| 512 | % endif |
| 513 | -o bins/${tgt.name} |
| 514 | |
| 515 | deps_${tgt.name}: $(${tgt.name.upper()}_DEPS) |
| 516 | |
| 517 | ifneq ($(MAKECMDGOALS),clean) |
| 518 | -include $(${tgt.name.upper()}_DEPS) |
| 519 | endif |
| 520 | |
| 521 | clean_${tgt.name}: |
| 522 | $(E) "[CLEAN] Cleaning ${tgt.name} files" |
| 523 | $(Q) $(RM) $(${tgt.name.upper()}_OBJS) |
| 524 | $(Q) $(RM) $(${tgt.name.upper()}_DEPS) |
| 525 | $(Q) $(RM) bins/${tgt.name} |
| 526 | </%def> |
| 527 | |
nnoble | 85a4926 | 2014-12-08 18:14:03 -0800 | [diff] [blame] | 528 | .PHONY: all strip tools \ |
| 529 | buildtests buildtests_c buildtests_cxx \ |
| 530 | test test_c test_cxx \ |
| 531 | install install_c install_cxx \ |
| 532 | install-headers install-headers_c install-headers_cxx \ |
| 533 | install-shared install-shared_c install-shared_cxx \ |
| 534 | install-static install-static_c install-static_cxx \ |
| 535 | strip strip-shared strip-static \ |
| 536 | strip_c strip-shared_c strip-static_c \ |
| 537 | strip_cxx strip-shared_cxx strip-static_cxx \ |
| 538 | clean\ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 539 | % for lib in libs: |
| 540 | deps_lib${lib.name} clean_lib${lib.name}\ |
| 541 | % endfor |
| 542 | % for tgt in targets: |
| 543 | deps_${tgt.name} clean_${tgt.name}\ |
| 544 | % endfor |
| 545 | |