Makefile.rules 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #
  2. # Asterisk -- A telephony toolkit for Linux.
  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?=-O6
  32. ifneq ($(findstring darwin,$(OSARCH)),)
  33. ifeq ($(shell /usr/bin/sw_vers -productVersion | cut -c1-4),10.6)
  34. # Snow Leopard 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. endif
  72. %.o: %.s
  73. $(ECHO_PREFIX) echo " [AS] $< -> $@"
  74. ifeq ($(COMPILE_DOUBLE),yes)
  75. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(OPTIMIZE) $(CC_CFLAGS)
  76. endif
  77. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
  78. %.o: %.i
  79. $(ECHO_PREFIX) echo " [CCi] $< -> $@"
  80. ifeq ($(COMPILE_DOUBLE),yes)
  81. $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(OPTIMIZE) $(CC_CFLAGS)
  82. endif
  83. $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
  84. ifneq ($(COMPILE_DOUBLE),yes)
  85. %.o: %.c
  86. $(ECHO_PREFIX) echo " [CC] $< -> $@"
  87. $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS)
  88. endif
  89. %.i: %.c
  90. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  91. $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS)
  92. %.oo: %.ii
  93. $(ECHO_PREFIX) echo " [CXXi] $< -> $@"
  94. ifeq ($(COMPILE_DOUBLE),yes)
  95. $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(OPTIMIZE) $(CXX_CFLAGS)
  96. endif
  97. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS)
  98. ifneq ($(COMPILE_DOUBLE),yes)
  99. %.oo: %.cc
  100. $(ECHO_PREFIX) echo " [CXX] $< -> $@"
  101. $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS)
  102. endif
  103. %.ii: %.cc
  104. $(ECHO_PREFIX) echo " [CPP] $< -> $@"
  105. $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS)
  106. %.so: %.o
  107. ifeq ($(GNU_LD),1)
  108. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  109. endif
  110. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  111. $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
  112. %.so: %.oo
  113. ifeq ($(GNU_LD),1)
  114. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
  115. endif
  116. $(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
  117. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
  118. %.eo: %.o
  119. $(ECHO_PREFIX) echo " [EMBED] $< -> $@"
  120. $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_eo_script $* > .$@.ld
  121. $(CMD_PREFIX) $(LD) -r -T .$@.ld -o $@ $<
  122. $(CMD_PREFIX) rm -f .$@.ld
  123. %.eo: %.oo
  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. %: %.o
  129. $(ECHO_PREFIX) echo " [LD] $^ -> $@"
  130. $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
  131. dist-clean:: clean