2
0

common.mak 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. NVCCFLAGS += -ptx
  35. HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
  36. LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
  37. define COMPILE
  38. $(call $(1)DEP,$(1))
  39. $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<)
  40. endef
  41. COMPILE_C = $(call COMPILE,CC)
  42. COMPILE_CXX = $(call COMPILE,CXX)
  43. COMPILE_S = $(call COMPILE,AS)
  44. COMPILE_M = $(call COMPILE,OBJCC)
  45. COMPILE_X86ASM = $(call COMPILE,X86ASM)
  46. COMPILE_HOSTC = $(call COMPILE,HOSTCC)
  47. COMPILE_NVCC = $(call COMPILE,NVCC)
  48. %.o: %.c
  49. $(COMPILE_C)
  50. %.o: %.cpp
  51. $(COMPILE_CXX)
  52. %.o: %.m
  53. $(COMPILE_M)
  54. %.s: %.c
  55. $(CC) $(CCFLAGS) -S -o $@ $<
  56. %.o: %.S
  57. $(COMPILE_S)
  58. %_host.o: %.c
  59. $(COMPILE_HOSTC)
  60. %$(DEFAULT_X86ASMD).asm: %.asm
  61. $(DEPX86ASM) $(X86ASMFLAGS) -M -o $@ $< > $(@:.asm=.d)
  62. $(X86ASM) $(X86ASMFLAGS) -e $< | sed '/^%/d;/^$$/d;' > $@
  63. %.o: %.asm
  64. $(COMPILE_X86ASM)
  65. -$(if $(ASMSTRIPFLAGS), $(STRIP) $(ASMSTRIPFLAGS) $@)
  66. %.o: %.rc
  67. $(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
  68. %.i: %.c
  69. $(CC) $(CCFLAGS) $(CC_E) $<
  70. %.h.c:
  71. $(Q)echo '#include "$*.h"' >$@
  72. %.ptx: %.cu
  73. $(COMPILE_NVCC)
  74. %.ptx.c: %.ptx
  75. $(Q)sh $(SRC_PATH)/compat/cuda/ptx2c.sh $@ $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<)
  76. %.c %.h %.pc %.ver %.version: TAG = GEN
  77. # Dummy rule to stop make trying to rebuild removed or renamed headers
  78. %.h:
  79. @:
  80. # Disable suffix rules. Most of the builtin rules are suffix rules,
  81. # so this saves some time on slow systems.
  82. .SUFFIXES:
  83. # Do not delete intermediate files from chains of implicit rules
  84. $(OBJS):
  85. endif
  86. include $(SRC_PATH)/ffbuild/arch.mak
  87. OBJS += $(OBJS-yes)
  88. SLIBOBJS += $(SLIBOBJS-yes)
  89. FFLIBS := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
  90. TESTPROGS += $(TESTPROGS-yes)
  91. LDLIBS = $(FFLIBS:%=%$(BUILDSUF))
  92. FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS)
  93. OBJS := $(sort $(OBJS:%=$(SUBDIR)%))
  94. SLIBOBJS := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
  95. TESTOBJS := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o)
  96. TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF))
  97. HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o)
  98. HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
  99. TOOLS += $(TOOLS-yes)
  100. TOOLOBJS := $(TOOLS:%=tools/%.o)
  101. TOOLS := $(TOOLS:%=tools/%$(EXESUF))
  102. HEADERS += $(HEADERS-yes)
  103. PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(2)LIBNAME))
  104. DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib),$(CONFIG_SHARED:yes=S)))
  105. STATIC_DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
  106. SRC_DIR := $(SRC_PATH)/lib$(NAME)
  107. ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
  108. SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
  109. SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
  110. HOBJS = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
  111. PTXOBJS = $(filter %.ptx.o,$(OBJS))
  112. $(HOBJS): CCFLAGS += $(CFLAGS_HEADERS)
  113. checkheaders: $(HOBJS)
  114. .SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=)
  115. alltools: $(TOOLS)
  116. $(HOSTOBJS): %.o: %.c
  117. $(COMPILE_HOSTC)
  118. $(HOSTPROGS): %$(HOSTEXESUF): %.o
  119. $(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTEXTRALIBS)
  120. $(OBJS): | $(sort $(dir $(OBJS)))
  121. $(HOBJS): | $(sort $(dir $(HOBJS)))
  122. $(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
  123. $(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
  124. $(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
  125. $(TOOLOBJS): | tools
  126. OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
  127. CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~
  128. LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
  129. define RULES
  130. clean::
  131. $(RM) $(HOSTPROGS) $(TESTPROGS) $(TOOLS)
  132. endef
  133. $(eval $(RULES))
  134. -include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d)