• 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) $($(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)
57
58%.o: %.c
59	$(COMPILE_C)
60
61%.o: %.cpp
62	$(COMPILE_CXX)
63
64%.o: %.m
65	$(COMPILE_M)
66
67%.s: %.c
68	$(CC) $(CCFLAGS) -S -o $@ $<
69
70%.o: %.S
71	$(COMPILE_S)
72
73%_host.o: %.c
74	$(COMPILE_HOSTC)
75
76%$(DEFAULT_X86ASMD).asm: %.asm
77	$(DEPX86ASM) $(X86ASMFLAGS) -M -o $@ $< > $(@:.asm=.d)
78	$(X86ASM) $(X86ASMFLAGS) -e $< | sed '/^%/d;/^$$/d;' > $@
79
80%.o: %.asm
81	$(COMPILE_X86ASM)
82	-$(if $(ASMSTRIPFLAGS), $(STRIP) $(ASMSTRIPFLAGS) $@)
83
84%.o: %.rc
85	$(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
86
87%.i: %.c
88	$(CC) $(CCFLAGS) $(CC_E) $<
89
90%.h.c:
91	$(Q)echo '#include "$*.h"' >$@
92
93%.ptx: %.cu $(SRC_PATH)/compat/cuda/cuda_runtime.h
94	$(COMPILE_NVCC)
95
96%.ptx.c: %.ptx
97	$(Q)sh $(SRC_PATH)/compat/cuda/ptx2c.sh $@ $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<)
98
99%.c %.h %.pc %.ver %.version: TAG = GEN
100
101# Dummy rule to stop make trying to rebuild removed or renamed headers
102%.h:
103	@:
104
105# Disable suffix rules.  Most of the builtin rules are suffix rules,
106# so this saves some time on slow systems.
107.SUFFIXES:
108
109# Do not delete intermediate files from chains of implicit rules
110$(OBJS):
111endif
112
113include $(SRC_PATH)/ffbuild/arch.mak
114
115OBJS      += $(OBJS-yes)
116SLIBOBJS  += $(SLIBOBJS-yes)
117FFLIBS    := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
118TESTPROGS += $(TESTPROGS-yes)
119
120LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
121FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS)
122
123OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
124SLIBOBJS  := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
125TESTOBJS  := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o)
126TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF))
127HOSTOBJS  := $(HOSTPROGS:%=$(SUBDIR)%.o)
128HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
129TOOLS     += $(TOOLS-yes)
130TOOLOBJS  := $(TOOLS:%=tools/%.o)
131TOOLS     := $(TOOLS:%=tools/%$(EXESUF))
132HEADERS   += $(HEADERS-yes)
133
134PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(2)LIBNAME))
135DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib),$(CONFIG_SHARED:yes=S)))
136STATIC_DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
137
138SRC_DIR    := $(SRC_PATH)/lib$(NAME)
139ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
140SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
141SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
142HOBJS        = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
143PTXOBJS      = $(filter %.ptx.o,$(OBJS))
144$(HOBJS):     CCFLAGS += $(CFLAGS_HEADERS)
145checkheaders: $(HOBJS)
146.SECONDARY:   $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=)
147
148alltools: $(TOOLS)
149
150$(HOSTOBJS): %.o: %.c
151	$(COMPILE_HOSTC)
152
153$(HOSTPROGS): %$(HOSTEXESUF): %.o
154	$(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTEXTRALIBS)
155
156$(OBJS):     | $(sort $(dir $(OBJS)))
157$(HOBJS):    | $(sort $(dir $(HOBJS)))
158$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
159$(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
160$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
161$(TOOLOBJS): | tools
162
163OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
164
165CLEANSUFFIXES     = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
166LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
167
168define RULES
169clean::
170	$(RM) $(HOSTPROGS) $(TESTPROGS) $(TOOLS)
171endef
172
173$(eval $(RULES))
174
175-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d)
176