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