Makefile.rules 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #
  2. # Asterisk -- An open source telephony toolkit.
  3. #
  4. # Makefile rules
  5. #
  6. # Copyright (C) 2006-2010, Digium, Inc.
  7. #
  8. # Kevin P. Fleming <kpfleming@digium.com>
  9. #
  10. # This program is free software, distributed under the terms of
  11. # the GNU General Public License
  12. #
  13. # Each command is preceded by a short comment on what to do.
  14. # Prefixing one or the other with @\# or @ or nothing makes the desired
  15. # behaviour. ECHO_PREFIX prefixes the comment, CMD_PREFIX prefixes the command.
  16. -include $(ASTTOPDIR)/makeopts
  17. # Helpful functions
  18. # call with $(call function,...)
  19. tolower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
  20. .PHONY: dist-clean
  21. # If 'make' decides to create intermediate files to satisfy a build requirement
  22. # (like producing a .i from a .c), we want to keep them, so tell make to keep
  23. # all intermediate files
  24. .SECONDARY:
  25. # extra cflags to build dependencies. Recursively expanded.
  26. MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
  27. ifeq ($(findstring ADDRESS_SANITIZER,$(MENUSELECT_CFLAGS)),ADDRESS_SANITIZER)
  28. _ASTLDFLAGS+=-fsanitize=address
  29. _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=address
  30. endif
  31. ifeq ($(findstring THREAD_SANITIZER,$(MENUSELECT_CFLAGS)),THREAD_SANITIZER)
  32. _ASTLDFLAGS+=-fsanitize=thread -pie -fPIE
  33. _ASTCFLAGS+=-fno-omit-frame-pointer -pie -fPIE -fsanitize=thread
  34. endif
  35. ifeq ($(findstring LEAK_SANITIZER,$(MENUSELECT_CFLAGS)),LEAK_SANITIZER)
  36. _ASTLDFLAGS+=-fsanitize=leak
  37. _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=leak
  38. endif
  39. ifeq ($(findstring UNDEFINED_SANITIZER,$(MENUSELECT_CFLAGS)),UNDEFINED_SANITIZER)
  40. _ASTLDFLAGS+=-fsanitize=undefined
  41. _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=undefined
  42. endif
  43. ifeq ($(NOISY_BUILD),)
  44. ECHO_PREFIX=@
  45. CMD_PREFIX=@
  46. else
  47. ECHO_PREFIX=@\#
  48. CMD_PREFIX=
  49. endif
  50. OPTIMIZE?=-O3
  51. ifneq ($(findstring darwin,$(OSARCH)),)
  52. ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
  53. # Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
  54. OPTIMIZE+=-fno-inline-functions
  55. endif
  56. endif
  57. ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
  58. _ASTCFLAGS+=$(OPTIMIZE)
  59. else
  60. _ASTCFLAGS+=-O0
  61. endif
  62. ifeq ($(AST_CODE_COVERAGE),yes)
  63. _ASTCFLAGS_COVERAGE=-ftest-coverage -fprofile-arcs
  64. _ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
  65. else
  66. _ASTCFLAGS_COVERAGE=
  67. endif
  68. ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
  69. _ASTCFLAGS+=$(CONFIG_CFLAGS)
  70. endif
  71. # shortcuts for common combinations of flags; these must be recursively expanded so that
  72. # per-target settings will be applied
  73. CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
  74. CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
  75. # Clang -Werror warning suppressions
  76. ifeq ($(C_COMPILER_FAMILY),clang)
  77. CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
  78. endif
  79. ifeq ($(GNU_LD),1)
  80. SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
  81. ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
  82. SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
  83. endif
  84. endif
  85. CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
  86. CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
  87. CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
  88. CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
  89. # determine whether to double-compile so that the optimizer can report code path problems
  90. # In this case, we run the preprocessor to produce a .i or .ii file from the source
  91. # code, then compile once with optimizer enabled (and the output to /dev/null),
  92. # and if that doesn't fail then compile again with optimizer disabled
  93. ifeq ($(findstring COMPILE_DOUBLE,$(MENUSELECT_CFLAGS)),COMPILE_DOUBLE)
  94. COMPILE_DOUBLE=yes
  95. endif
  96. ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),)
  97. _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
  98. endif
  99. ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
  100. _ASTCFLAGS+=-march=native
  101. endif
  102. %.o: %.s
  103. $(ECHO_PREFIX) echo " [AS] $< -> $@"
  104. ifeq ($(COMPILE_DOUBLE),yes)
  105. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
  106. endif
  107. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  108. %.o: %.i
  109. $(ECHO_PREFIX) echo " [CCi] $< -> $@"
  110. ifneq ($(AST_CLANG_BLOCKS),)
  111. ifeq ($(COMPILE_DOUBLE),yes)
  112. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE) -Wno-unused-command-line-argument
  113. endif
  114. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE) -Wno-unused-command-line-argument
  115. else
  116. ifeq ($(COMPILE_DOUBLE),yes)
  117. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
  118. endif
  119. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  120. endif
  121. ifneq ($(COMPILE_DOUBLE),yes)
  122. %.o: %.c
  123. $(ECHO_PREFIX) echo " [CC] $< -> $@"
  124. $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  125. endif
  126. %.i: %.c
  127. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  128. $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  129. %.oo: %.ii
  130. $(ECHO_PREFIX) echo " [CXXi] $< -> $@"
  131. ifeq ($(COMPILE_DOUBLE),yes)
  132. $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
  133. endif
  134. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  135. ifneq ($(COMPILE_DOUBLE),yes)
  136. %.oo: %.cc
  137. $(ECHO_PREFIX) echo " [CXX] $< -> $@"
  138. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  139. endif
  140. %.ii: %.cc
  141. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  142. $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
  143. %.so: %.o
  144. ifeq ($(GNU_LD),1)
  145. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  146. endif
  147. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  148. $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
  149. %.so: %.oo
  150. ifeq ($(GNU_LD),1)
  151. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  152. endif
  153. $(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
  154. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
  155. %: %.o
  156. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  157. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
  158. dist-clean:: clean