common.mak 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #
  2. # common bits used by all libraries
  3. #
  4. # first so "all" becomes default target
  5. all: all-yes
  6. ifndef SUBDIR
  7. ifndef V
  8. Q = @
  9. ECHO = printf "$(1)\t%s\n" $(2)
  10. BRIEF = CC CXX HOSTCC HOSTLD AS YASM AR LD STRIP CP WINDRES
  11. SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM
  12. MSG = $@
  13. M = @$(call ECHO,$(TAG),$@);
  14. $(foreach VAR,$(BRIEF), \
  15. $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
  16. $(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
  17. $(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
  18. endif
  19. ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil postproc swscale swresample
  20. # NASM requires -I path terminated with /
  21. IFLAGS := -I. -I$(SRC_PATH)/
  22. CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
  23. CFLAGS += $(ECFLAGS)
  24. CCFLAGS = $(CPPFLAGS) $(CFLAGS)
  25. ASFLAGS := $(CPPFLAGS) $(ASFLAGS)
  26. CXXFLAGS += $(CPPFLAGS) $(CFLAGS)
  27. YASMFLAGS += $(IFLAGS:%=%/) -Pconfig.asm
  28. HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
  29. LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
  30. define COMPILE
  31. $(call $(1)DEP,$(1))
  32. $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
  33. endef
  34. COMPILE_C = $(call COMPILE,CC)
  35. COMPILE_CXX = $(call COMPILE,CXX)
  36. COMPILE_S = $(call COMPILE,AS)
  37. COMPILE_HOSTC = $(call COMPILE,HOSTCC)
  38. %.o: %.c
  39. $(COMPILE_C)
  40. %.o: %.cpp
  41. $(COMPILE_CXX)
  42. %.o: %.m
  43. $(COMPILE_C)
  44. %.s: %.c
  45. $(CC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $<
  46. %.o: %.S
  47. $(COMPILE_S)
  48. %_host.o: %.c
  49. $(COMPILE_HOSTC)
  50. %.o: %.rc
  51. $(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
  52. %.i: %.c
  53. $(CC) $(CCFLAGS) $(CC_E) $<
  54. %.h.c:
  55. $(Q)echo '#include "$*.h"' >$@
  56. %.ver: %.v
  57. $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
  58. %.c %.h: TAG = GEN
  59. # Dummy rule to stop make trying to rebuild removed or renamed headers
  60. %.h:
  61. @:
  62. # Disable suffix rules. Most of the builtin rules are suffix rules,
  63. # so this saves some time on slow systems.
  64. .SUFFIXES:
  65. # Do not delete intermediate files from chains of implicit rules
  66. $(OBJS):
  67. endif
  68. include $(SRC_PATH)/arch.mak
  69. OBJS += $(OBJS-yes)
  70. SLIBOBJS += $(SLIBOBJS-yes)
  71. FFLIBS := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
  72. TESTPROGS += $(TESTPROGS-yes)
  73. LDLIBS = $(FFLIBS:%=%$(BUILDSUF))
  74. FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
  75. OBJS := $(sort $(OBJS:%=$(SUBDIR)%))
  76. SLIBOBJS := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
  77. TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o)
  78. TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF))
  79. HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o)
  80. HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
  81. TOOLS += $(TOOLS-yes)
  82. TOOLOBJS := $(TOOLS:%=tools/%.o)
  83. TOOLS := $(TOOLS:%=tools/%$(EXESUF))
  84. HEADERS += $(HEADERS-yes)
  85. PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
  86. DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
  87. SRC_DIR := $(SRC_PATH)/lib$(NAME)
  88. ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
  89. SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
  90. SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
  91. HOBJS = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
  92. checkheaders: $(HOBJS)
  93. .SECONDARY: $(HOBJS:.o=.c)
  94. alltools: $(TOOLS)
  95. $(HOSTOBJS): %.o: %.c
  96. $(COMPILE_HOSTC)
  97. $(HOSTPROGS): %$(HOSTEXESUF): %.o
  98. $(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTLIBS)
  99. $(OBJS): | $(sort $(dir $(OBJS)))
  100. $(HOBJS): | $(sort $(dir $(HOBJS)))
  101. $(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
  102. $(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
  103. $(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
  104. $(TOOLOBJS): | tools
  105. OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
  106. CLEANSUFFIXES = *.d *.o *~ *.h.c *.map *.ver *.ho *.gcno *.gcda
  107. DISTCLEANSUFFIXES = *.pc
  108. LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
  109. define RULES
  110. clean::
  111. $(RM) $(OBJS) $(OBJS:.o=.d)
  112. $(RM) $(HOSTPROGS)
  113. $(RM) $(TOOLS)
  114. endef
  115. $(eval $(RULES))
  116. -include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d))