Makefile.rules 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. .PHONY: dist-clean
  18. # If 'make' decides to create intermediate files to satisfy a build requirement
  19. # (like producing a .i from a .c), we want to keep them, so tell make to keep
  20. # all intermediate files
  21. .SECONDARY:
  22. # extra cflags to build dependencies. Recursively expanded.
  23. MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
  24. ifeq ($(NOISY_BUILD),)
  25. ECHO_PREFIX=@
  26. CMD_PREFIX=@
  27. else
  28. ECHO_PREFIX=@\#
  29. CMD_PREFIX=
  30. endif
  31. OPTIMIZE?=-O3
  32. ifneq ($(findstring darwin,$(OSARCH)),)
  33. ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
  34. # Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
  35. OPTIMIZE+=-fno-inline-functions
  36. endif
  37. endif
  38. ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
  39. _ASTCFLAGS+=$(OPTIMIZE)
  40. else
  41. _ASTCFLAGS+=-O0
  42. endif
  43. ifeq ($(AST_CODE_COVERAGE),yes)
  44. _ASTCFLAGS+=-ftest-coverage -fprofile-arcs
  45. _ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
  46. endif
  47. ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
  48. _ASTCFLAGS+=$(CONFIG_CFLAGS)
  49. endif
  50. # shortcuts for common combinations of flags; these must be recursively expanded so that
  51. # per-target settings will be applied
  52. CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
  53. CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
  54. ifeq ($(GNU_LD),1)
  55. SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
  56. ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
  57. SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
  58. endif
  59. endif
  60. CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
  61. CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
  62. CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
  63. CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
  64. # determine whether to double-compile so that the optimizer can report code path problems
  65. # this is only done when developer mode and DONT_OPTIMIZE are both enabled
  66. # in that case, we run the preprocessor to produce a .i or .ii file from the source
  67. # code, then compile once with optimizer enabled (and the output to /dev/null),
  68. # and if that doesn't fail then compile again with optimizer disabled
  69. ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),DONT_OPTIMIZEyes)
  70. COMPILE_DOUBLE=yes
  71. else
  72. _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
  73. endif
  74. ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
  75. _ASTCFLAGS+=-march=native
  76. endif
  77. %.o: %.s
  78. $(ECHO_PREFIX) echo " [AS] $< -> $@"
  79. ifeq ($(COMPILE_DOUBLE),yes)
  80. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
  81. endif
  82. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
  83. %.o: %.i
  84. $(ECHO_PREFIX) echo " [CCi] $< -> $@"
  85. ifeq ($(COMPILE_DOUBLE),yes)
  86. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
  87. endif
  88. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
  89. ifneq ($(COMPILE_DOUBLE),yes)
  90. %.o: %.c
  91. $(ECHO_PREFIX) echo " [CC] $< -> $@"
  92. $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS)
  93. endif
  94. %.i: %.c
  95. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  96. $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS)
  97. %.oo: %.ii
  98. $(ECHO_PREFIX) echo " [CXXi] $< -> $@"
  99. ifeq ($(COMPILE_DOUBLE),yes)
  100. $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
  101. endif
  102. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS)
  103. ifneq ($(COMPILE_DOUBLE),yes)
  104. %.oo: %.cc
  105. $(ECHO_PREFIX) echo " [CXX] $< -> $@"
  106. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS)
  107. endif
  108. %.ii: %.cc
  109. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  110. $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS)
  111. %.so: %.o
  112. ifeq ($(GNU_LD),1)
  113. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  114. endif
  115. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  116. $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
  117. %.so: %.oo
  118. ifeq ($(GNU_LD),1)
  119. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  120. endif
  121. $(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
  122. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
  123. %.eo: %.o
  124. $(ECHO_PREFIX) echo " [EMBED] $< -> $@"
  125. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_eo_script $* > .$@.ld
  126. $(CMD_PREFIX) $(LD) -r -T .$@.ld -o $@ $<
  127. $(CMD_PREFIX) rm -f .$@.ld
  128. %.eo: %.oo
  129. $(ECHO_PREFIX) echo " [EMBED] $< -> $@"
  130. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_eo_script $* > .$@.ld
  131. $(CMD_PREFIX) $(LD) -r -T .$@.ld -o $@ $<
  132. $(CMD_PREFIX) rm -f .$@.ld
  133. %: %.o
  134. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  135. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
  136. dist-clean:: clean