common.mak 5.0 KB

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