1# Makefile
2
3include config.mak
4
5vpath %.c $(SRCPATH)
6vpath %.h $(SRCPATH)
7vpath %.S $(SRCPATH)
8vpath %.asm $(SRCPATH)
9vpath %.rc $(SRCPATH)
10vpath %.manifest $(SRCPATH)
11
12CFLAGS += $(CFLAGSPROF)
13LDFLAGS += $(LDFLAGSPROF)
14
15GENERATED =
16
17all: default
18default:
19
20SRCS = common/osdep.c common/base.c common/cpu.c common/tables.c \
21       encoder/api.c
22
23SRCS_X = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
24         common/frame.c common/dct.c common/cabac.c \
25         common/common.c common/rectangle.c \
26         common/set.c common/quant.c common/deblock.c common/vlc.c \
27         common/mvpred.c common/bitstream.c \
28         encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
29         encoder/set.c encoder/macroblock.c encoder/cabac.c \
30         encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
31
32SRCS_8 =
33
34SRCCLI = x264.c autocomplete.c input/input.c input/timecode.c input/raw.c \
35         input/y4m.c output/raw.c output/matroska.c output/matroska_ebml.c \
36         output/flv.c output/flv_bytestream.c filters/filters.c \
37         filters/video/video.c filters/video/source.c filters/video/internal.c \
38         filters/video/resize.c filters/video/fix_vfr_pts.c \
39         filters/video/select_every.c filters/video/crop.c
40
41SRCCLI_X = filters/video/cache.c filters/video/depth.c
42
43SRCSO =
44
45SRCCHK_X = tools/checkasm.c
46
47SRCEXAMPLE = example.c
48
49OBJS =
50OBJASM =
51OBJSO =
52OBJCLI =
53OBJCHK =
54OBJCHK_8 =
55OBJCHK_10 =
56OBJEXAMPLE =
57
58CONFIG := $(shell cat config.h)
59
60# Optional module sources
61ifneq ($(findstring HAVE_AVS 1, $(CONFIG)),)
62SRCCLI += input/avs.c
63endif
64
65ifneq ($(findstring HAVE_THREAD 1, $(CONFIG)),)
66SRCS_X   += common/threadpool.c
67SRCCLI_X += input/thread.c
68endif
69
70ifneq ($(findstring HAVE_WIN32THREAD 1, $(CONFIG)),)
71SRCS += common/win32thread.c
72endif
73
74ifneq ($(findstring HAVE_LAVF 1, $(CONFIG)),)
75SRCCLI += input/lavf.c
76endif
77
78ifneq ($(findstring HAVE_FFMS 1, $(CONFIG)),)
79SRCCLI += input/ffms.c
80endif
81
82ifneq ($(findstring HAVE_GPAC 1, $(CONFIG)),)
83SRCCLI += output/mp4.c
84endif
85
86ifneq ($(findstring HAVE_LSMASH 1, $(CONFIG)),)
87SRCCLI += output/mp4_lsmash.c
88endif
89
90ifneq ($(AS),)
91
92# MMX/SSE optims
93SRCASM_X =
94ifeq ($(SYS_ARCH),X86)
95ARCH_X86 = yes
96SRCASM_X += common/x86/dct-32.asm \
97            common/x86/pixel-32.asm
98endif
99ifeq ($(SYS_ARCH),X86_64)
100ARCH_X86 = yes
101SRCASM_X += common/x86/dct-64.asm \
102            common/x86/trellis-64.asm
103endif
104
105ifdef ARCH_X86
106SRCASM_X += common/x86/bitstream-a.asm \
107            common/x86/const-a.asm \
108            common/x86/cabac-a.asm \
109            common/x86/dct-a.asm \
110            common/x86/deblock-a.asm \
111            common/x86/mc-a.asm \
112            common/x86/mc-a2.asm \
113            common/x86/pixel-a.asm \
114            common/x86/predict-a.asm \
115            common/x86/quant-a.asm
116SRCS_X   += common/x86/mc-c.c \
117            common/x86/predict-c.c
118
119OBJASM += common/x86/cpu-a.o
120ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
121OBJASM += $(SRCASM_X:%.asm=%-8.o) common/x86/sad-a-8.o
122endif
123ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
124OBJASM += $(SRCASM_X:%.asm=%-10.o) common/x86/sad16-a-10.o
125endif
126
127OBJCHK += tools/checkasm-a.o
128endif
129
130# AltiVec optims
131ifeq ($(SYS_ARCH),PPC)
132SRCS_X += common/ppc/dct.c \
133          common/ppc/deblock.c \
134          common/ppc/mc.c \
135          common/ppc/pixel.c \
136          common/ppc/predict.c \
137          common/ppc/quant.c
138endif
139
140# NEON optims
141ifeq ($(SYS_ARCH),ARM)
142SRCASM_X  = common/arm/bitstream-a.S \
143            common/arm/dct-a.S \
144            common/arm/deblock-a.S \
145            common/arm/mc-a.S \
146            common/arm/pixel-a.S \
147            common/arm/predict-a.S \
148            common/arm/quant-a.S
149SRCS_X   += common/arm/mc-c.c \
150            common/arm/predict-c.c
151
152OBJASM += common/arm/cpu-a.o
153ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
154OBJASM += $(SRCASM_X:%.S=%-8.o)
155endif
156ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
157OBJASM += $(SRCASM_X:%.S=%-10.o)
158endif
159
160OBJCHK += tools/checkasm-arm.o
161endif
162
163# AArch64 NEON optims
164ifeq ($(SYS_ARCH),AARCH64)
165SRCASM_X  = common/aarch64/bitstream-a.S \
166            common/aarch64/cabac-a.S \
167            common/aarch64/dct-a.S \
168            common/aarch64/deblock-a.S \
169            common/aarch64/mc-a.S \
170            common/aarch64/pixel-a.S \
171            common/aarch64/predict-a.S \
172            common/aarch64/quant-a.S
173SRCS_X   += common/aarch64/asm-offsets.c \
174            common/aarch64/mc-c.c \
175            common/aarch64/predict-c.c
176
177OBJASM +=
178ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
179OBJASM += $(SRCASM_X:%.S=%-8.o)
180endif
181ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
182OBJASM += $(SRCASM_X:%.S=%-10.o)
183endif
184
185OBJCHK += tools/checkasm-aarch64.o
186endif
187
188# MSA optims
189ifeq ($(SYS_ARCH),MIPS)
190ifneq ($(findstring HAVE_MSA 1, $(CONFIG)),)
191SRCS_X += common/mips/dct-c.c \
192          common/mips/deblock-c.c \
193          common/mips/mc-c.c \
194          common/mips/pixel-c.c \
195          common/mips/predict-c.c \
196          common/mips/quant-c.c
197endif
198endif
199
200endif
201
202ifneq ($(HAVE_GETOPT_LONG),1)
203SRCCLI += extras/getopt.c
204endif
205
206ifeq ($(SYS),WINDOWS)
207OBJCLI += $(if $(RC), x264res.o)
208ifneq ($(SONAME),)
209SRCSO  += x264dll.c
210OBJSO  += $(if $(RC), x264res.dll.o)
211endif
212endif
213
214ifeq ($(HAVE_OPENCL),yes)
215common/oclobj.h: common/opencl/x264-cl.h $(wildcard $(SRCPATH)/common/opencl/*.cl)
216	cat $^ | $(SRCPATH)/tools/cltostr.sh $@
217GENERATED += common/oclobj.h
218SRCS_8 += common/opencl.c encoder/slicetype-cl.c
219endif
220
221OBJS   += $(SRCS:%.c=%.o)
222OBJCLI += $(SRCCLI:%.c=%.o)
223OBJSO  += $(SRCSO:%.c=%.o)
224OBJEXAMPLE += $(SRCEXAMPLE:%.c=%.o)
225
226ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
227OBJS      += $(SRCS_X:%.c=%-8.o) $(SRCS_8:%.c=%-8.o)
228OBJCLI    += $(SRCCLI_X:%.c=%-8.o)
229OBJCHK_8  += $(SRCCHK_X:%.c=%-8.o)
230checkasm: checkasm8$(EXE)
231endif
232ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
233OBJS      += $(SRCS_X:%.c=%-10.o)
234OBJCLI    += $(SRCCLI_X:%.c=%-10.o)
235OBJCHK_10 += $(SRCCHK_X:%.c=%-10.o)
236checkasm: checkasm10$(EXE)
237endif
238
239.PHONY: all default fprofiled clean distclean install install-* uninstall cli lib-* checkasm etags
240
241cli: x264$(EXE)
242lib-static: $(LIBX264)
243lib-shared: $(SONAME)
244
245$(LIBX264): $(GENERATED) .depend $(OBJS) $(OBJASM)
246	rm -f $(LIBX264)
247	$(AR)$@ $(OBJS) $(OBJASM)
248	$(if $(RANLIB), $(RANLIB) $@)
249
250$(SONAME): $(GENERATED) .depend $(OBJS) $(OBJASM) $(OBJSO)
251	$(LD)$@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS)
252
253$(IMPLIBNAME): $(SONAME)
254
255ifneq ($(EXE),)
256.PHONY: x264 checkasm8 checkasm10 example
257x264: x264$(EXE)
258checkasm8: checkasm8$(EXE)
259checkasm10: checkasm10$(EXE)
260example: example$(EXE)
261endif
262
263x264$(EXE): $(GENERATED) .depend $(OBJCLI) $(CLI_LIBX264)
264	$(LD)$@ $(OBJCLI) $(CLI_LIBX264) $(LDFLAGSCLI) $(LDFLAGS)
265
266checkasm8$(EXE): $(GENERATED) .depend $(OBJCHK) $(OBJCHK_8) $(LIBX264)
267	$(LD)$@ $(OBJCHK) $(OBJCHK_8) $(LIBX264) $(LDFLAGS)
268
269checkasm10$(EXE): $(GENERATED) .depend $(OBJCHK) $(OBJCHK_10) $(LIBX264)
270	$(LD)$@ $(OBJCHK) $(OBJCHK_10) $(LIBX264) $(LDFLAGS)
271
272example$(EXE): $(GENERATED) .depend $(OBJEXAMPLE) $(LIBX264)
273	$(LD)$@ $(OBJEXAMPLE) $(LIBX264) $(LDFLAGS)
274
275$(OBJS) $(OBJSO): CFLAGS += $(CFLAGSSO)
276$(OBJCLI): CFLAGS += $(CFLAGSCLI)
277
278$(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10) $(OBJEXAMPLE): .depend
279
280%.o: %.c
281	$(CC) $(CFLAGS) -c $< $(CC_O)
282
283%-8.o: %.c
284	$(CC) $(CFLAGS) -c $< $(CC_O) -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
285
286%-10.o: %.c
287	$(CC) $(CFLAGS) -c $< $(CC_O) -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
288
289%.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
290	$(AS) $(ASFLAGS) -o $@ $<
291	-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
292
293%-8.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
294	$(AS) $(ASFLAGS) -o $@ $< -DBIT_DEPTH=8 -Dprivate_prefix=x264_8
295	-@ $(if $(STRIP), $(STRIP) -x $@)
296
297%-10.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
298	$(AS) $(ASFLAGS) -o $@ $< -DBIT_DEPTH=10 -Dprivate_prefix=x264_10
299	-@ $(if $(STRIP), $(STRIP) -x $@)
300
301%.o: %.S
302	$(AS) $(ASFLAGS) -o $@ $<
303	-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
304
305%-8.o: %.S
306	$(AS) $(ASFLAGS) -o $@ $< -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
307	-@ $(if $(STRIP), $(STRIP) -x $@)
308
309%-10.o: %.S
310	$(AS) $(ASFLAGS) -o $@ $< -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
311	-@ $(if $(STRIP), $(STRIP) -x $@)
312
313%.dll.o: %.rc x264.h
314	$(RC) $(RCFLAGS)$@ -DDLL $<
315
316%.o: %.rc x264.h x264res.manifest
317	$(RC) $(RCFLAGS)$@ $<
318
319.depend: config.mak
320	@rm -f .depend
321	@echo 'dependency file generation...'
322ifeq ($(COMPILER),CL)
323	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO) $(SRCEXAMPLE)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%.o)" 1>> .depend;)
324ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
325	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCS_8) $(SRCCLI_X) $(SRCCHK_X)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%-8.o)" 1>> .depend;)
326endif
327ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
328	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCCLI_X) $(SRCCHK_X)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%-10.o)" 1>> .depend;)
329endif
330else
331	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO) $(SRCEXAMPLE)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%.o) $(DEPMM) 1>> .depend;)
332ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
333	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCS_8) $(SRCCLI_X) $(SRCCHK_X)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%-8.o) $(DEPMM) 1>> .depend;)
334endif
335ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
336	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCCLI_X) $(SRCCHK_X)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%-10.o) $(DEPMM) 1>> .depend;)
337endif
338endif
339
340config.mak:
341	./configure
342
343depend: .depend
344ifneq ($(wildcard .depend),)
345include .depend
346endif
347
348OBJPROF = $(OBJS) $(OBJSO) $(OBJCLI)
349# These should cover most of the important codepaths
350OPT0 = --crf 30 -b1 -m1 -r1 --me dia --no-cabac --direct temporal --ssim --no-weightb
351OPT1 = --crf 16 -b2 -m3 -r3 --me hex --no-8x8dct --direct spatial --no-dct-decimate -t0  --slice-max-mbs 50
352OPT2 = --crf 26 -b4 -m5 -r2 --me hex --cqm jvt --nr 100 --psnr --no-mixed-refs --b-adapt 2 --slice-max-size 1500
353OPT3 = --crf 18 -b3 -m9 -r5 --me umh -t1 -A all --b-pyramid normal --direct auto --no-fast-pskip --no-mbtree
354OPT4 = --crf 22 -b3 -m7 -r4 --me esa -t2 -A all --psy-rd 1.0:1.0 --slices 4
355OPT5 = --frames 50 --crf 24 -b3 -m10 -r3 --me tesa -t2
356OPT6 = --frames 50 -q0 -m9 -r2 --me hex -Aall
357OPT7 = --frames 50 -q0 -m2 -r1 --me hex --no-cabac
358
359ifeq (,$(VIDS))
360fprofiled:
361	@echo 'usage: make fprofiled VIDS="infile1 infile2 ..."'
362	@echo 'where infiles are anything that x264 understands,'
363	@echo 'i.e. YUV with resolution in the filename, y4m, or avisynth.'
364else
365fprofiled: clean
366	$(MAKE) x264$(EXE) CFLAGSPROF="$(PROF_GEN_CC)" LDFLAGSPROF="$(PROF_GEN_LD)"
367	$(foreach V, $(VIDS), $(foreach I, 0 1 2 3 4 5 6 7, ./x264$(EXE) $(OPT$I) --threads 1 $(V) -o $(DEVNULL) ;))
368ifeq ($(COMPILER),CL)
369# Because Visual Studio timestamps the object files within the PGD, it fails to build if they change - only the executable should be deleted
370	rm -f x264$(EXE)
371else
372	rm -f $(OBJPROF)
373endif
374	$(MAKE) CFLAGSPROF="$(PROF_USE_CC)" LDFLAGSPROF="$(PROF_USE_LD)"
375	rm -f $(OBJPROF:%.o=%.gcda) $(OBJPROF:%.o=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
376endif
377
378clean:
379	rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(GENERATED) .depend TAGS
380	rm -f $(SONAME) *.a *.lib *.exp *.pdb x264$(EXE) x264_lookahead.clbin
381	rm -f checkasm8$(EXE) checkasm10$(EXE) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10)
382	rm -f example$(EXE) $(OBJEXAMPLE)
383	rm -f $(OBJPROF:%.o=%.gcda) $(OBJPROF:%.o=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
384
385distclean: clean
386	rm -f config.mak x264_config.h config.h config.log x264.pc x264.def
387	rm -rf conftest*
388
389install-cli: cli
390	$(INSTALL) -d $(DESTDIR)$(bindir)
391	$(INSTALL) x264$(EXE) $(DESTDIR)$(bindir)
392
393install-lib-dev:
394	$(INSTALL) -d $(DESTDIR)$(includedir) $(DESTDIR)$(libdir)/pkgconfig
395	$(INSTALL) -m 644 $(SRCPATH)/x264.h x264_config.h $(DESTDIR)$(includedir)
396	$(INSTALL) -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
397
398install-lib-static: lib-static install-lib-dev
399	$(INSTALL) -d $(DESTDIR)$(libdir)
400	$(INSTALL) -m 644 $(LIBX264) $(DESTDIR)$(libdir)
401	$(if $(RANLIB), $(RANLIB) $(DESTDIR)$(libdir)/$(LIBX264))
402
403install-lib-shared: lib-shared install-lib-dev
404	$(INSTALL) -d $(DESTDIR)$(libdir)
405ifneq ($(IMPLIBNAME),)
406	$(INSTALL) -d $(DESTDIR)$(bindir)
407	$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(bindir)
408	$(INSTALL) -m 644 $(IMPLIBNAME) $(DESTDIR)$(libdir)
409else ifneq ($(SONAME),)
410	ln -f -s $(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
411	$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir)
412endif
413
414install-bashcompletion:
415ifneq ($(BASHCOMPLETIONSDIR),)
416	$(INSTALL) -d $(DESTDIR)$(BASHCOMPLETIONSDIR)
417	$(INSTALL) -m 644 $(SRCPATH)/tools/bash-autocomplete.sh $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
418endif
419
420uninstall:
421	rm -f $(DESTDIR)$(includedir)/x264.h $(DESTDIR)$(includedir)/x264_config.h $(DESTDIR)$(libdir)/libx264.a
422	rm -f $(DESTDIR)$(bindir)/x264$(EXE) $(DESTDIR)$(libdir)/pkgconfig/x264.pc
423ifneq ($(IMPLIBNAME),)
424	rm -f $(DESTDIR)$(bindir)/$(SONAME) $(DESTDIR)$(libdir)/$(IMPLIBNAME)
425else ifneq ($(SONAME),)
426	rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
427endif
428ifneq ($(BASHCOMPLETIONSDIR),)
429	rm -f $(DESTDIR)$(BASHCOMPLETIONSDIR)/x264
430endif
431
432etags TAGS:
433	etags $(SRCS) $(SRCS_X) $(SRCS_8)
434