James Kuszmaul | 82f6c04 | 2021-01-17 11:30:16 -0800 | [diff] [blame] | 1 | # |
| 2 | # re.mk - common make rules |
| 3 | # |
| 4 | # Copyright (C) 2010 Creytiv.com |
| 5 | # |
| 6 | # Imported variables: |
| 7 | # |
| 8 | # ARCH Target architecture |
| 9 | # CC Compiler |
| 10 | # CROSS_COMPILE Cross-compiler prefix (optional) |
| 11 | # EXTRA_CFLAGS Extra compiler flags appended to CFLAGS |
| 12 | # EXTRA_LFLAGS Extra linker flags appended to LFLAGS |
| 13 | # GCOV If non-empty, enable GNU Coverage testing |
| 14 | # GPROF If non-empty, enable GNU Profiling |
| 15 | # OPT_SIZE If non-empty, optimize for size |
| 16 | # OPT_SPEED If non-empty, optimize for speed |
| 17 | # PROJECT Project name |
| 18 | # RELEASE Release build |
| 19 | # SYSROOT System root of library and include files |
| 20 | # SYSROOT_ALT Alternative system root of library and include files |
| 21 | # USE_OPENSSL If non-empty, link to libssl library |
| 22 | # USE_ZLIB If non-empty, link to libz library |
| 23 | # VERSION Version number |
| 24 | # |
| 25 | # Exported variables: |
| 26 | # |
| 27 | # APP_LFLAGS Linker flags for applications using modules |
| 28 | # BIN_SUFFIX Suffix for binary executables |
| 29 | # CC Compiler |
| 30 | # CCACHE Compiler ccache tool |
| 31 | # CFLAGS Compiler flags |
| 32 | # DFLAGS Dependency generator flags |
| 33 | # LFLAGS Common linker flags |
| 34 | # LIBS Libraries to link against |
| 35 | # LIB_SUFFIX Suffix for shared libraries |
| 36 | # MOD_LFLAGS Linker flags for dynamic modules |
| 37 | # MOD_SUFFIX Suffix for dynamic modules |
| 38 | # SH_LFLAGS Linker flags for shared libraries |
| 39 | # USE_TLS Defined if TLS is available |
| 40 | # USE_DTLS Defined if DTLS is available |
| 41 | # |
| 42 | |
| 43 | |
| 44 | ifneq ($(RELEASE),) |
| 45 | CFLAGS += -DRELEASE |
| 46 | OPT_SPEED=1 |
| 47 | endif |
| 48 | |
| 49 | |
| 50 | # Default system root |
| 51 | ifeq ($(SYSROOT),) |
| 52 | SYSROOT := /usr |
| 53 | endif |
| 54 | |
| 55 | # Alternative Systemroot |
| 56 | ifeq ($(SYSROOT_ALT),) |
| 57 | SYSROOT_ALT := $(shell [ -d /sw/include ] && echo "/sw") |
| 58 | endif |
| 59 | ifeq ($(SYSROOT_ALT),) |
| 60 | SYSROOT_ALT := $(shell [ -d /opt/local/include ] && echo "/opt/local") |
| 61 | endif |
| 62 | |
| 63 | ifneq ($(SYSROOT_ALT),) |
| 64 | CFLAGS += -I$(SYSROOT_ALT)/include |
| 65 | LFLAGS += -L$(SYSROOT_ALT)/lib |
| 66 | endif |
| 67 | |
| 68 | |
| 69 | ############################################################################## |
| 70 | # |
| 71 | # Compiler section |
| 72 | # |
| 73 | # find compiler name & version |
| 74 | |
| 75 | ifeq ($(CC),) |
| 76 | CC := gcc |
| 77 | endif |
| 78 | ifeq ($(CC),cc) |
| 79 | CC := gcc |
| 80 | endif |
| 81 | LD := $(CC) |
| 82 | CC_LONGVER := $(shell if $(CC) -v 2>/dev/null; then \ |
| 83 | $(CC) -v 2>&1 ;\ |
| 84 | else \ |
| 85 | $(CC) -V 2>&1 ; \ |
| 86 | fi ) |
| 87 | |
| 88 | # find-out the compiler's name |
| 89 | |
| 90 | ifneq (,$(findstring gcc, $(CC_LONGVER))) |
| 91 | CC_NAME := gcc |
| 92 | CC_VER := $(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|\ |
| 93 | cut -d" " -f 3|\ |
| 94 | sed -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\ |
| 95 | -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') |
| 96 | # sun sed is a little brain damaged => this complicated expression |
| 97 | MKDEP := $(CC) -MM |
| 98 | #transform gcc version into 2.9x, 3.x or 4.x |
| 99 | CC_SHORTVER := $(shell echo "$(CC_VER)" | cut -d" " -f 2| \ |
| 100 | sed -e 's/[^0-9]*-\(.*\)/\1/'| \ |
| 101 | sed -e 's/2\.9.*/2.9x/' -e 's/3\.[0-3]\..*/3.0/' -e \ |
| 102 | 's/3\.[0-3]/3.0/' -e 's/3\.[4-9]\..*/3.4/' -e\ |
| 103 | 's/3\.[4-9]/3.4/' -e 's/4\.[0-9]\..*/4.x/' -e\ |
| 104 | 's/4\.[0-9]/4.x/' ) |
| 105 | endif |
| 106 | |
| 107 | ifeq ($(CC_NAME),) |
| 108 | ifneq (,$(findstring clang, $(CC_LONGVER))) |
| 109 | CC_NAME := clang |
| 110 | CC_SHORTVER := $(shell echo "$(CC_LONGVER)"|head -n 1| \ |
| 111 | sed -e 's/.*version \([0-9]\.[0-9]\).*/\1/g' ) |
| 112 | CC_VER := $(CC) $(CC_SHORTVER) |
| 113 | MKDEP := $(CC) -MM |
| 114 | endif |
| 115 | endif |
| 116 | |
| 117 | ifeq ($(CC_NAME),) |
| 118 | ifneq (, $(findstring Sun, $(CC_LONGVER))) |
| 119 | CC_NAME := suncc |
| 120 | CC_SHORTVER := $(shell echo "$(CC_LONGVER)"|head -n 1| \ |
| 121 | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' ) |
| 122 | CC_VER := $(CC) $(CC_SHORTVER) |
| 123 | MKDEP := $(CC) -xM1 |
| 124 | endif |
| 125 | endif |
| 126 | |
| 127 | ifeq ($(CC_NAME),) |
| 128 | ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER))) |
| 129 | # very nice: gcc compatible |
| 130 | CC_NAME := icc |
| 131 | CC_FULLVER := $(shell echo "$(CC_LONGVER)"|head -n 1| \ |
| 132 | sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g') |
| 133 | CC_SHORTVER := $(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 ) |
| 134 | CC_VER := $(CC) $(CC_FULLVER) |
| 135 | MKDEP := $(CC) -MM |
| 136 | endif |
| 137 | endif |
| 138 | |
| 139 | |
| 140 | ifeq (,$(CC_NAME)) |
| 141 | #not found |
| 142 | CC_NAME := $(CC) |
| 143 | CC_SHORTVER := unknown |
| 144 | CC_VER := unknown |
| 145 | MKDEP := gcc -MM |
| 146 | $(warning Unknown compiler $(CC)\; supported compilers: \ |
| 147 | gcc, clang, sun cc, intel icc ) |
| 148 | endif |
| 149 | |
| 150 | |
| 151 | # Compiler warning flags |
| 152 | CFLAGS += -Wall |
| 153 | CFLAGS += -Wmissing-declarations |
| 154 | CFLAGS += -Wmissing-prototypes |
| 155 | CFLAGS += -Wstrict-prototypes |
| 156 | CFLAGS += -Wbad-function-cast |
| 157 | CFLAGS += -Wsign-compare |
| 158 | CFLAGS += -Wnested-externs |
| 159 | CFLAGS += -Wshadow |
| 160 | CFLAGS += -Waggregate-return |
| 161 | CFLAGS += -Wcast-align |
| 162 | |
| 163 | |
| 164 | ifeq ($(CC_SHORTVER),4.x) |
| 165 | CFLAGS += -Wextra |
| 166 | CFLAGS += -Wold-style-definition |
| 167 | CFLAGS += -Wdeclaration-after-statement |
| 168 | endif |
| 169 | |
| 170 | CFLAGS += -g |
| 171 | ifneq ($(OPT_SPEED),) |
| 172 | CFLAGS += -O3 # Optimize for speed - takes longer to compile! |
| 173 | OPTIMIZE := 1 |
| 174 | endif |
| 175 | ifneq ($(OPT_SIZE),) |
| 176 | CFLAGS += -Os # Optimize for size - takes longer to compile! |
| 177 | OPTIMIZE := 1 |
| 178 | endif |
| 179 | |
| 180 | ifneq ($(OPTIMIZE),) |
| 181 | CFLAGS += -Wuninitialized |
| 182 | ifneq ($(CC_SHORTVER), 2.9x) |
| 183 | CFLAGS += -Wno-strict-aliasing |
| 184 | endif |
| 185 | endif |
| 186 | |
| 187 | # Compiler dependency flags |
| 188 | ifeq ($(CC_SHORTVER), 2.9x) |
| 189 | DFLAGS = -MD |
| 190 | else |
| 191 | DFLAGS = -MD -MF $(@:.o=.d) -MT $@ |
| 192 | endif |
| 193 | |
| 194 | |
| 195 | ############################################################################## |
| 196 | # |
| 197 | # OS section |
| 198 | # |
| 199 | |
| 200 | MACHINE := $(shell $(CC) -dumpmachine) |
| 201 | |
| 202 | ifeq ($(CROSS_COMPILE),) |
| 203 | OS := $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]") |
| 204 | endif |
| 205 | |
| 206 | |
| 207 | ifneq ($(strip $(filter i386-mingw32 i486-mingw32 i586-mingw32msvc \ |
| 208 | i686-w64-mingw32 x86_64-w64-mingw32 mingw32, \ |
| 209 | $(MACHINE))),) |
| 210 | OS := win32 |
| 211 | ifeq ($(MACHINE), mingw32) |
| 212 | CROSS_COMPILE := |
| 213 | endif |
| 214 | endif |
| 215 | |
| 216 | |
| 217 | # default |
| 218 | LIB_SUFFIX := .so |
| 219 | MOD_SUFFIX := .so |
| 220 | BIN_SUFFIX := |
| 221 | |
| 222 | ifeq ($(OS),solaris) |
| 223 | CFLAGS += -fPIC -DSOLARIS |
| 224 | LIBS += -ldl -lresolv -lsocket -lnsl |
| 225 | LFLAGS += -fPIC |
| 226 | SH_LFLAGS += -G |
| 227 | MOD_LFLAGS += |
| 228 | APP_LFLAGS += |
| 229 | AR := ar |
| 230 | AFLAGS := cru |
| 231 | endif |
| 232 | ifeq ($(OS),linux) |
| 233 | CFLAGS += -fPIC -DLINUX |
| 234 | LIBS += -ldl |
| 235 | LFLAGS += -fPIC |
| 236 | SH_LFLAGS += -shared |
| 237 | MOD_LFLAGS += |
| 238 | APP_LFLAGS += -rdynamic |
| 239 | AR := ar |
| 240 | AFLAGS := crD |
| 241 | endif |
| 242 | ifeq ($(OS),gnu) |
| 243 | CFLAGS += -fPIC -DGNU |
| 244 | LIBS += -ldl |
| 245 | LFLAGS += -fPIC |
| 246 | SH_LFLAGS += -shared |
| 247 | MOD_LFLAGS += |
| 248 | APP_LFLAGS += -rdynamic |
| 249 | AR := ar |
| 250 | AFLAGS := cru |
| 251 | endif |
| 252 | ifeq ($(OS),darwin) |
| 253 | CFLAGS += -fPIC -dynamic -DDARWIN |
| 254 | ifneq (,$(findstring Apple, $(CC_LONGVER))) |
| 255 | CFLAGS += -Wshorten-64-to-32 |
| 256 | endif |
| 257 | DFLAGS := -MD |
| 258 | LIBS += -lresolv |
| 259 | LFLAGS += -fPIC |
| 260 | SH_LFLAGS += -dynamiclib |
| 261 | ifeq ($(CC_NAME),gcc) |
| 262 | SH_LFLAGS += -dylib |
| 263 | endif |
| 264 | ifneq ($(VERSION),) |
| 265 | SH_LFLAGS += -current_version $(VERSION) |
| 266 | SH_LFLAGS += -compatibility_version $(VERSION) |
| 267 | endif |
| 268 | MOD_LFLAGS += -undefined dynamic_lookup |
| 269 | APP_LFLAGS += |
| 270 | AR := ar |
| 271 | AFLAGS := cru |
| 272 | LIB_SUFFIX := .dylib |
| 273 | HAVE_KQUEUE := 1 |
| 274 | endif |
| 275 | ifeq ($(OS),netbsd) |
| 276 | CFLAGS += -fPIC -DNETBSD |
| 277 | LFLAGS += -fPIC |
| 278 | SH_LFLAGS += -shared |
| 279 | MOD_LFLAGS += |
| 280 | APP_LFLAGS += -rdynamic |
| 281 | AR := ar |
| 282 | AFLAGS := cru |
| 283 | HAVE_KQUEUE := 1 |
| 284 | endif |
| 285 | ifeq ($(OS),freebsd) |
| 286 | CFLAGS += -fPIC -DFREEBSD |
| 287 | LFLAGS += -fPIC |
| 288 | SH_LFLAGS += -shared |
| 289 | MOD_LFLAGS += |
| 290 | APP_LFLAGS += -rdynamic |
| 291 | AR := ar |
| 292 | AFLAGS := cru |
| 293 | HAVE_KQUEUE := 1 |
| 294 | endif |
| 295 | ifeq ($(OS),gnu/kfreebsd) |
| 296 | CFLAGS += -fPIC -DKFREEBSD -D_GNU_SOURCE |
| 297 | LFLAGS += -fPIC |
| 298 | SH_LFLAGS += -shared |
| 299 | MOD_LFLAGS += |
| 300 | APP_LFLAGS += -rdynamic |
| 301 | AR := ar |
| 302 | AFLAGS := cru |
| 303 | HAVE_KQUEUE := 1 |
| 304 | endif |
| 305 | ifeq ($(OS),dragonfly) |
| 306 | CFLAGS += -fPIC -DDRAGONFLY |
| 307 | LFLAGS += -fPIC |
| 308 | SH_LFLAGS += -shared |
| 309 | MOD_LFLAGS += |
| 310 | APP_LFLAGS += -rdynamic |
| 311 | AR := ar |
| 312 | AFLAGS := cru |
| 313 | HAVE_KQUEUE := 1 |
| 314 | endif |
| 315 | ifeq ($(OS),openbsd) |
| 316 | CFLAGS += -fPIC -DOPENBSD |
| 317 | LFLAGS += -fPIC |
| 318 | SH_LFLAGS += -shared |
| 319 | MOD_LFLAGS += |
| 320 | APP_LFLAGS += -rdynamic |
| 321 | AR := ar |
| 322 | AFLAGS := cru |
| 323 | HAVE_KQUEUE := 1 |
| 324 | HAVE_ARC4RANDOM := 1 |
| 325 | endif |
| 326 | ifeq ($(OS),win32) |
| 327 | CFLAGS += -DWIN32 -D_WIN32_WINNT=0x0501 -D__ssize_t_defined |
| 328 | LIBS += -lwsock32 -lws2_32 -liphlpapi |
| 329 | LFLAGS += |
| 330 | SH_LFLAGS += -shared |
| 331 | MOD_LFLAGS += |
| 332 | APP_LFLAGS += -Wl,--export-all-symbols |
| 333 | AR := ar |
| 334 | AFLAGS := cru |
| 335 | CROSS_COMPILE ?= $(MACHINE)- |
| 336 | RANLIB := $(CROSS_COMPILE)ranlib |
| 337 | LIB_SUFFIX := .dll |
| 338 | MOD_SUFFIX := .dll |
| 339 | BIN_SUFFIX := .exe |
| 340 | SYSROOT := /usr/$(MACHINE)/ |
| 341 | endif |
| 342 | |
| 343 | CFLAGS += -DOS=\"$(OS)\" |
| 344 | |
| 345 | ifeq ($(CC_SHORTVER),2.9x) |
| 346 | CFLAGS += -Wno-long-long |
| 347 | else |
| 348 | CFLAGS += -std=c99 |
| 349 | PEDANTIC := 1 |
| 350 | endif # CC_SHORTVER |
| 351 | |
| 352 | ifneq ($(PEDANTIC),) |
| 353 | CFLAGS += -pedantic |
| 354 | endif |
| 355 | |
| 356 | |
| 357 | ifeq ($(OS),) |
| 358 | $(warning Could not detect OS) |
| 359 | endif |
| 360 | |
| 361 | |
| 362 | ############################################################################## |
| 363 | # |
| 364 | # Architecture section |
| 365 | # |
| 366 | |
| 367 | |
| 368 | ifeq ($(ARCH),) |
| 369 | ifeq ($(CC_NAME),$(filter $(CC_NAME),gcc clang)) |
| 370 | PREDEF := $(shell $(CC) -dM -E -x c $(EXTRA_CFLAGS) $(CFLAGS) /dev/null) |
| 371 | |
| 372 | ifneq ($(strip $(filter i386 __i386__ __i386 _M_IX86 __X86__ _X86_, \ |
| 373 | $(PREDEF))),) |
| 374 | ARCH := i386 |
| 375 | endif |
| 376 | |
| 377 | ifneq ($(strip $(filter __i486__,$(PREDEF))),) |
| 378 | ARCH := i486 |
| 379 | endif |
| 380 | |
| 381 | ifneq ($(strip $(filter __i586__,$(PREDEF))),) |
| 382 | ARCH := i586 |
| 383 | endif |
| 384 | |
| 385 | ifneq ($(strip $(filter __i686__ ,$(PREDEF))),) |
| 386 | ARCH := i686 |
| 387 | endif |
| 388 | |
| 389 | ifneq ($(strip $(filter __amd64__ __amd64 __x86_64__ __x86_64, \ |
| 390 | $(PREDEF))),) |
| 391 | ARCH := x86_64 |
| 392 | endif |
| 393 | |
| 394 | ifneq ($(strip $(filter __arm__ __thumb__,$(PREDEF))),) |
| 395 | |
| 396 | ifneq ($(strip $(filter __ARM_ARCH_6__,$(PREDEF))),) |
| 397 | ARCH := arm6 |
| 398 | else |
| 399 | ARCH := arm |
| 400 | endif |
| 401 | |
| 402 | endif |
| 403 | |
| 404 | ifneq ($(strip $(filter __arm64__ ,$(PREDEF))),) |
| 405 | ARCH := arm64 |
| 406 | endif |
| 407 | |
| 408 | ifneq ($(strip $(filter __mips__ __mips, $(PREDEF))),) |
| 409 | ARCH := mips |
| 410 | endif |
| 411 | |
| 412 | ifneq ($(strip $(filter __powerpc __powerpc__ __POWERPC__ __ppc__ \ |
| 413 | _ARCH_PPC, $(PREDEF))),) |
| 414 | ARCH := ppc |
| 415 | endif |
| 416 | |
| 417 | ifneq ($(strip $(filter __ppc64__ _ARCH_PPC64 , $(PREDEF))),) |
| 418 | ARCH := ppc64 |
| 419 | endif |
| 420 | |
| 421 | ifneq ($(strip $(filter __sparc__ __sparc __sparcv8 , $(PREDEF))),) |
| 422 | |
| 423 | ifneq ($(strip $(filter __sparcv9 __sparc_v9__ , $(PREDEF))),) |
| 424 | ARCH := sparc64 |
| 425 | else |
| 426 | ARCH := sparc |
| 427 | endif |
| 428 | |
| 429 | endif |
| 430 | |
| 431 | endif |
| 432 | endif |
| 433 | |
| 434 | |
| 435 | ifeq ($(ARCH),) |
| 436 | $(warning Could not detect ARCH) |
| 437 | endif |
| 438 | |
| 439 | |
| 440 | CFLAGS += -DARCH=\"$(ARCH)\" |
| 441 | |
| 442 | ifeq ($(ARCH),mipsel) |
| 443 | CFLAGS += -march=mips32 |
| 444 | endif |
| 445 | |
| 446 | |
| 447 | ############################################################################## |
| 448 | # |
| 449 | # External libraries section |
| 450 | # |
| 451 | |
| 452 | USE_OPENSSL := $(shell [ -f $(SYSROOT)/include/openssl/ssl.h ] || \ |
| 453 | [ -f $(SYSROOT)/local/include/openssl/ssl.h ] || \ |
| 454 | [ -f $(SYSROOT_ALT)/include/openssl/ssl.h ] && echo "yes") |
| 455 | |
| 456 | ifneq ($(USE_OPENSSL),) |
| 457 | CFLAGS += -DUSE_OPENSSL -DUSE_TLS |
| 458 | LIBS += -lssl -lcrypto |
| 459 | USE_TLS := yes |
| 460 | |
| 461 | USE_OPENSSL_DTLS := $(shell [ -f $(SYSROOT)/include/openssl/dtls1.h ] || \ |
| 462 | [ -f $(SYSROOT)/local/include/openssl/dtls1.h ] || \ |
| 463 | [ -f $(SYSROOT_ALT)/include/openssl/dtls1.h ] && echo "yes") |
| 464 | |
| 465 | USE_OPENSSL_SRTP := $(shell [ -f $(SYSROOT)/include/openssl/srtp.h ] || \ |
| 466 | [ -f $(SYSROOT)/local/include/openssl/srtp.h ] || \ |
| 467 | [ -f $(SYSROOT_ALT)/include/openssl/srtp.h ] && echo "yes") |
| 468 | |
| 469 | ifneq ($(USE_OPENSSL_DTLS),) |
| 470 | CFLAGS += -DUSE_OPENSSL_DTLS -DUSE_DTLS |
| 471 | USE_DTLS := yes |
| 472 | endif |
| 473 | |
| 474 | ifneq ($(USE_OPENSSL_SRTP),) |
| 475 | CFLAGS += -DUSE_OPENSSL_SRTP -DUSE_DTLS_SRTP |
| 476 | USE_DTLS_SRTP := yes |
| 477 | endif |
| 478 | |
| 479 | USE_OPENSSL_AES := yes |
| 480 | USE_OPENSSL_HMAC := yes |
| 481 | |
| 482 | endif |
| 483 | |
| 484 | |
| 485 | USE_ZLIB := $(shell [ -f $(SYSROOT)/include/zlib.h ] || \ |
| 486 | [ -f $(SYSROOT)/local/include/zlib.h ] || \ |
| 487 | [ -f $(SYSROOT_ALT)/include/zlib.h ] && echo "yes") |
| 488 | |
| 489 | ifneq ($(USE_ZLIB),) |
| 490 | CFLAGS += -DUSE_ZLIB |
| 491 | LIBS += -lz |
| 492 | endif |
| 493 | |
| 494 | |
| 495 | ifneq ($(OS),win32) |
| 496 | |
| 497 | HAVE_PTHREAD := $(shell [ -f $(SYSROOT)/include/pthread.h ] && echo "1") |
| 498 | ifneq ($(HAVE_PTHREAD),) |
| 499 | HAVE_PTHREAD_RWLOCK := 1 |
| 500 | CFLAGS += -DHAVE_PTHREAD |
| 501 | HAVE_LIBPTHREAD := 1 |
| 502 | ifneq ($(HAVE_LIBPTHREAD),) |
| 503 | LIBS += -lpthread |
| 504 | endif |
| 505 | endif |
| 506 | |
| 507 | ifneq ($(ARCH),mipsel) |
| 508 | HAVE_GETIFADDRS := $(shell [ -f $(SYSROOT)/include/ifaddrs.h ] && echo "1") |
| 509 | ifneq ($(HAVE_GETIFADDRS),) |
| 510 | CFLAGS += -DHAVE_GETIFADDRS |
| 511 | endif |
| 512 | endif |
| 513 | |
| 514 | HAVE_STRERROR_R := 1 |
| 515 | ifneq ($(HAVE_STRERROR_R),) |
| 516 | CFLAGS += -DHAVE_STRERROR_R |
| 517 | endif |
| 518 | |
| 519 | endif |
| 520 | |
| 521 | HAVE_GETOPT := $(shell [ -f $(SYSROOT)/include/getopt.h ] && echo "1") |
| 522 | ifneq ($(HAVE_GETOPT),) |
| 523 | CFLAGS += -DHAVE_GETOPT |
| 524 | endif |
| 525 | HAVE_INTTYPES_H := $(shell [ -f $(SYSROOT)/include/inttypes.h ] && echo "1") |
| 526 | ifneq ($(HAVE_INTTYPES_H),) |
| 527 | CFLAGS += -DHAVE_INTTYPES_H |
| 528 | endif |
| 529 | HAVE_NET_ROUTE_H := $(shell [ -f $(SYSROOT)/include/net/route.h ] && echo "1") |
| 530 | ifneq ($(HAVE_NET_ROUTE_H),) |
| 531 | CFLAGS += -DHAVE_NET_ROUTE_H |
| 532 | endif |
| 533 | HAVE_SYS_SYSCTL_H := \ |
| 534 | $(shell [ -f $(SYSROOT)/include/sys/sysctl.h ] || \ |
| 535 | [ -f $(SYSROOT)/include/$(MACHINE)/sys/sysctl.h ] \ |
| 536 | && echo "1") |
| 537 | ifneq ($(HAVE_SYS_SYSCTL_H),) |
| 538 | CFLAGS += -DHAVE_SYS_SYSCTL_H |
| 539 | endif |
| 540 | |
| 541 | CFLAGS += -DHAVE_STDBOOL_H |
| 542 | |
| 543 | HAVE_INET6 := 1 |
| 544 | ifneq ($(HAVE_INET6),) |
| 545 | CFLAGS += -DHAVE_INET6 |
| 546 | endif |
| 547 | |
| 548 | ifeq ($(OS),win32) |
| 549 | CFLAGS += -DHAVE_SELECT |
| 550 | CFLAGS += -DHAVE_IO_H |
| 551 | else |
| 552 | HAVE_SYSLOG := $(shell [ -f $(SYSROOT)/include/syslog.h ] && echo "1") |
| 553 | HAVE_DLFCN_H := $(shell [ -f $(SYSROOT)/include/dlfcn.h ] && echo "1") |
| 554 | ifneq ($(OS),darwin) |
| 555 | HAVE_EPOLL := $(shell [ -f $(SYSROOT)/include/sys/epoll.h ] || \ |
| 556 | [ -f $(SYSROOT)/include/$(MACHINE)/sys/epoll.h ] \ |
| 557 | && echo "1") |
| 558 | endif |
| 559 | |
| 560 | HAVE_RESOLV := $(shell [ -f $(SYSROOT)/include/resolv.h ] && echo "1") |
| 561 | |
| 562 | ifneq ($(HAVE_RESOLV),) |
| 563 | CFLAGS += -DHAVE_RESOLV |
| 564 | endif |
| 565 | ifneq ($(HAVE_SYSLOG),) |
| 566 | CFLAGS += -DHAVE_SYSLOG |
| 567 | endif |
| 568 | |
| 569 | HAVE_INET_NTOP := 1 |
| 570 | |
| 571 | CFLAGS += -DHAVE_FORK |
| 572 | |
| 573 | ifneq ($(HAVE_INET_NTOP),) |
| 574 | CFLAGS += -DHAVE_INET_NTOP |
| 575 | endif |
| 576 | CFLAGS += -DHAVE_PWD_H |
| 577 | ifneq ($(OS),darwin) |
| 578 | CFLAGS += -DHAVE_POLL # Darwin: poll() does not support devices |
| 579 | HAVE_INET_PTON := 1 |
| 580 | endif |
| 581 | ifneq ($(HAVE_INET_PTON),) |
| 582 | CFLAGS += -DHAVE_INET_PTON |
| 583 | endif |
| 584 | CFLAGS += -DHAVE_SELECT -DHAVE_SELECT_H |
| 585 | CFLAGS += -DHAVE_SETRLIMIT |
| 586 | CFLAGS += -DHAVE_SIGNAL |
| 587 | CFLAGS += -DHAVE_SYS_TIME_H |
| 588 | ifneq ($(HAVE_EPOLL),) |
| 589 | CFLAGS += -DHAVE_EPOLL |
| 590 | endif |
| 591 | ifneq ($(HAVE_KQUEUE),) |
| 592 | CFLAGS += -DHAVE_KQUEUE |
| 593 | endif |
| 594 | CFLAGS += -DHAVE_UNAME |
| 595 | CFLAGS += -DHAVE_UNISTD_H |
| 596 | CFLAGS += -DHAVE_STRINGS_H |
| 597 | endif |
| 598 | |
| 599 | ifneq ($(HAVE_ARC4RANDOM),) |
| 600 | CFLAGS += -DHAVE_ARC4RANDOM |
| 601 | endif |
| 602 | |
| 603 | |
| 604 | ############################################################################## |
| 605 | # |
| 606 | # Misc tools section |
| 607 | # |
| 608 | CCACHE := $(shell [ -e /usr/bin/ccache ] 2>/dev/null \ |
| 609 | || [ -e /opt/local/bin/ccache ] \ |
| 610 | && echo "ccache") |
| 611 | CFLAGS += -DVERSION=\"$(VERSION)\" |
| 612 | CFLAGS += \ |
| 613 | -DVER_MAJOR=$(VER_MAJOR) \ |
| 614 | -DVER_MINOR=$(VER_MINOR) \ |
| 615 | -DVER_PATCH=$(VER_PATCH) |
| 616 | |
| 617 | |
| 618 | # Enable gcov Coverage testing |
| 619 | # |
| 620 | # - generated during build: .gcno files |
| 621 | # - generated during exec: .gcda files |
| 622 | # |
| 623 | ifneq ($(GCOV),) |
| 624 | CFLAGS += -fprofile-arcs -ftest-coverage |
| 625 | LFLAGS += -fprofile-arcs -ftest-coverage |
| 626 | # Disable ccache |
| 627 | CCACHE := |
| 628 | endif |
| 629 | |
| 630 | # gprof - GNU Profiling |
| 631 | # |
| 632 | # - generated during exec: gmon.out |
| 633 | # |
| 634 | ifneq ($(GPROF),) |
| 635 | CFLAGS += -pg |
| 636 | LFLAGS += -pg |
| 637 | # Disable ccache |
| 638 | CCACHE := |
| 639 | endif |
| 640 | |
| 641 | CC := $(CCACHE) $(CC) |
| 642 | CFLAGS += $(EXTRA_CFLAGS) |
| 643 | LFLAGS += $(EXTRA_LFLAGS) |
| 644 | |
| 645 | BUILD := build-$(ARCH) |
| 646 | |
| 647 | |
| 648 | default: all |
| 649 | |
| 650 | .PHONY: distclean |
| 651 | distclean: |
| 652 | @rm -rf build* *core* |
| 653 | @rm -f *stamp $(BIN) |
| 654 | @rm -f `find . -name "*.[oda]"` `find . -name "*.so"` |
| 655 | @rm -f `find . -name "*~"` `find . -name "\.\#*"` |
| 656 | @rm -f `find . -name "*.orig"` `find . -name "*.rej"` |
| 657 | @rm -f `find . -name "*.previous"` `find . -name "*.gcov"` |
| 658 | @rm -f `find . -name "*.exe"` `find . -name "*.dll"` |
| 659 | @rm -f `find . -name "*.dylib"` |
| 660 | |
| 661 | .PHONY: info |
| 662 | info: |
| 663 | @echo "info - $(PROJECT) version $(VERSION)" |
| 664 | @echo " MODULES: $(MODULES)" |
| 665 | # @echo " SRCS: $(SRCS)" |
| 666 | @echo " MACHINE: $(MACHINE)" |
| 667 | @echo " ARCH: $(ARCH)" |
| 668 | @echo " OS: $(OS)" |
| 669 | @echo " BUILD: $(BUILD)" |
| 670 | @echo " CCACHE: $(CCACHE)" |
| 671 | @echo " CC: $(CC_NAME) $(CC_SHORTVER)" |
| 672 | @echo " CFLAGS: $(CFLAGS)" |
| 673 | @echo " DFLAGS: $(DFLAGS)" |
| 674 | @echo " LFLAGS: $(LFLAGS)" |
| 675 | @echo " SH_LFLAGS: $(SH_LFLAGS)" |
| 676 | @echo " MOD_LFLAGS: $(MOD_LFLAGS)" |
| 677 | @echo " APP_LFLAGS: $(APP_LFLAGS)" |
| 678 | @echo " LIBS: $(LIBS)" |
| 679 | @echo " LIBRE_MK: $(LIBRE_MK)" |
| 680 | @echo " LIBRE_INC: $(LIBRE_INC)" |
| 681 | @echo " LIBRE_SO: $(LIBRE_SO)" |
| 682 | @echo " USE_OPENSSL: $(USE_OPENSSL)" |
| 683 | @echo " USE_OPENSSL_AES: $(USE_OPENSSL_AES)" |
| 684 | @echo " USE_OPENSSL_HMAC: $(USE_OPENSSL_HMAC)" |
| 685 | @echo " USE_TLS: $(USE_TLS)" |
| 686 | @echo " USE_DTLS: $(USE_DTLS)" |
| 687 | @echo " USE_DTLS_SRTP: $(USE_DTLS_SRTP)" |
| 688 | @echo " USE_ZLIB: $(USE_ZLIB)" |
| 689 | @echo " GCOV: $(GCOV)" |
| 690 | @echo " GPROF: $(GPROF)" |
| 691 | @echo " CROSS_COMPILE: $(CROSS_COMPILE)" |
| 692 | @echo " SYSROOT: $(SYSROOT)" |
| 693 | @echo " SYSROOT_ALT: $(SYSROOT_ALT)" |
| 694 | @echo " LIB_SUFFIX: $(LIB_SUFFIX)" |
| 695 | @echo " MOD_SUFFIX: $(MOD_SUFFIX)" |
| 696 | @echo " BIN_SUFFIX: $(BIN_SUFFIX)" |
| 697 | |
| 698 | |
| 699 | ############################################################################## |
| 700 | # |
| 701 | # Packaging section |
| 702 | # |
| 703 | TAR_SRC := $(PROJECT)-$(VERSION) |
| 704 | |
| 705 | release: |
| 706 | @rm -rf ../$(TAR_SRC) |
| 707 | @svn export . ../$(TAR_SRC) |
| 708 | @if [ -f ../$(TAR_SRC)/mk/exclude ]; then \ |
| 709 | cat ../$(TAR_SRC)/mk/exclude \ |
| 710 | | sed 's|^|../$(TAR_SRC)/|' | xargs -t rm -rf ; \ |
| 711 | rm -f ../$(TAR_SRC)/mk/exclude ; \ |
| 712 | fi |
| 713 | @cd .. && rm -f $(TAR_SRC).tar.gz \ |
| 714 | && tar -zcf $(TAR_SRC).tar.gz $(TAR_SRC) \ |
| 715 | && echo "created release tarball `pwd`/$(TAR_SRC).tar.gz" |
| 716 | |
| 717 | tar: |
| 718 | @rm -rf ../$(TAR_SRC) |
| 719 | @svn export . ../$(TAR_SRC) |
| 720 | @cd .. && rm -f $(TAR_SRC).tar.gz \ |
| 721 | && tar -zcf $(TAR_SRC).tar.gz $(TAR_SRC) \ |
| 722 | && echo "created source tarball `pwd`/$(TAR_SRC).tar.gz" |
| 723 | |
| 724 | |
| 725 | git_release: |
| 726 | git archive --format=tar --prefix=$(PROJECT)-$(VERSION)/ v$(VERSION) \ |
| 727 | | gzip > ../$(PROJECT)-$(VERSION).tar.gz |
| 728 | |
| 729 | |
| 730 | git_snapshot: |
| 731 | git archive --format=tar --prefix=$(PROJECT)-$(VERSION)/ HEAD \ |
| 732 | | gzip > ../$(PROJECT)-$(VERSION).tar.gz |
| 733 | |
| 734 | |
| 735 | # Debian |
| 736 | .PHONY: deb |
| 737 | deb: |
| 738 | dpkg-buildpackage -rfakeroot |
| 739 | |
| 740 | .PHONY: debclean |
| 741 | debclean: |
| 742 | @rm -rf build-stamp configure-stamp debian/files debian/$(PROJECT) \ |
| 743 | debian/lib$(PROJECT) debian/lib$(PROJECT)-dev debian/tmp \ |
| 744 | debian/.debhelper debian/*.debhelper debian/*.debhelper.log \ |
| 745 | debian/*.substvars |
| 746 | |
| 747 | # RPM |
| 748 | RPM := $(shell [ -d /usr/src/rpm ] 2>/dev/null && echo "rpm") |
| 749 | ifeq ($(RPM),) |
| 750 | RPM := $(shell [ -d /usr/src/redhat ] 2>/dev/null && echo "redhat") |
| 751 | endif |
| 752 | .PHONY: rpm |
| 753 | rpm: tar |
| 754 | sudo cp ../$(PROJECT)-$(VERSION).tar.gz /usr/src/$(RPM)/SOURCES |
| 755 | sudo rpmbuild -ba rpm/$(PROJECT).spec |
| 756 | |
| 757 | |
| 758 | ############################################################################## |
| 759 | # |
| 760 | # Library and header files location section - in prioritised order |
| 761 | # |
| 762 | # - relative path |
| 763 | # - local installation |
| 764 | # - system installation |
| 765 | # |
| 766 | |
| 767 | LIBRE_PATH := ../re |
| 768 | |
| 769 | # Include path |
| 770 | LIBRE_INC := $(shell [ -f $(LIBRE_PATH)/include/re.h ] && \ |
| 771 | echo "$(LIBRE_PATH)/include") |
| 772 | ifeq ($(LIBRE_INC),) |
| 773 | LIBRE_INC := $(shell [ -f /usr/local/include/re/re.h ] && \ |
| 774 | echo "/usr/local/include/re") |
| 775 | endif |
| 776 | ifeq ($(LIBRE_INC),) |
| 777 | LIBRE_INC := $(shell [ -f /usr/include/re/re.h ] && echo "/usr/include/re") |
| 778 | endif |
| 779 | |
| 780 | # Library path |
| 781 | LIBRE_SO := $(shell [ -f $(LIBRE_PATH)/libre$(LIB_SUFFIX) ] \ |
| 782 | && echo "$(LIBRE_PATH)") |
| 783 | ifeq ($(LIBRE_SO),) |
| 784 | LIBRE_SO := $(shell [ -f /usr/local/lib/libre$(LIB_SUFFIX) ] \ |
| 785 | && echo "/usr/local/lib") |
| 786 | endif |
| 787 | ifeq ($(LIBRE_SO),) |
| 788 | LIBRE_SO := $(shell [ -f /usr/lib/libre$(LIB_SUFFIX) ] && echo "/usr/lib") |
| 789 | endif |
| 790 | ifeq ($(LIBRE_SO),) |
| 791 | LIBRE_SO := $(shell [ -f /usr/lib64/libre$(LIB_SUFFIX) ] && echo "/usr/lib64") |
| 792 | endif |
| 793 | |
| 794 | |
| 795 | ############################################################################### |
| 796 | # |
| 797 | # Clang section |
| 798 | # |
| 799 | |
| 800 | CLANG_OPTIONS := -Iinclude -I$(LIBRE_INC) $(CFLAGS) |
| 801 | CLANG_IGNORE := |
| 802 | CLANG_SRCS += $(filter-out $(CLANG_IGNORE), $(patsubst %,src/%,$(SRCS))) |
| 803 | |
| 804 | clang: |
| 805 | @clang --analyze $(CLANG_OPTIONS) $(CLANG_SRCS) |
| 806 | @rm -f *.plist |
| 807 | |
| 808 | |
| 809 | ############################################################################### |
| 810 | # |
| 811 | # Documentation section |
| 812 | # |
| 813 | DOX_DIR=../$(PROJECT)-dox |
| 814 | DOX_TAR=$(PROJECT)-dox-$(VERSION) |
| 815 | |
| 816 | $(DOX_DIR): |
| 817 | @mkdir $@ |
| 818 | |
| 819 | $(DOX_DIR)/Doxyfile: mk/Doxyfile Makefile |
| 820 | @cp $< $@ |
| 821 | @perl -pi -e 's/PROJECT_NUMBER\s*=.*/PROJECT_NUMBER = $(VERSION)/' \ |
| 822 | $(DOX_DIR)/Doxyfile |
| 823 | |
| 824 | .PHONY: |
| 825 | dox: $(DOX_DIR) $(DOX_DIR)/Doxyfile |
| 826 | @doxygen $(DOX_DIR)/Doxyfile 2>&1 | grep -v DEBUG_ ; true |
| 827 | @cd .. && rm -f $(DOX_TAR).tar.gz && \ |
| 828 | tar -zcf $(DOX_TAR).tar.gz $(PROJECT)-dox > /dev/null && \ |
| 829 | echo "Doxygen docs in `pwd`/$(DOX_TAR).tar.gz" |