minor improvements from Andrew
[goodguy/cinelerra.git] / cinelerra-5.1 / thirdparty / src / dav1d-0.5.1.patch1
1 diff -urN a/Makefile b/Makefile
2 --- a/Makefile  1969-12-31 17:00:00.000000000 -0700
3 +++ b/Makefile  2019-10-14 10:54:47.354841430 -0600
4 @@ -0,0 +1,363 @@
5 +
6 +_ARCH := $(shell uname -m)
7 +ARCH_I32 := $(shell expr "x$(_ARCH)" : 'xi[346]86.*')
8 +ARCH_X64 := $(shell expr "x$(_ARCH)" : 'x..._64*')
9 +
10 +ifneq ($(ARCH_I32),0)
11 +ASM_ARCH := elf32
12 +ARCH_X86_32 := 1
13 +ARCH_X86_64 := 0
14 +endif
15 +ifneq ($(ARCH_X64),0)
16 +ASM_ARCH := elf64
17 +ARCH_X86_32 := 0
18 +ARCH_X86_64 := 1
19 +endif
20 +
21 +BUILD=build
22 +DESTDIR=/
23 +PREFIX=usr/local
24 +LIBDIR=$(PREFIX)/lib
25 +INCDIR=$(PREFIX)/include
26 +# make Q="" for verbose
27 +Q?=@echo == $@; 
28 +OBJDIR?=$(BUILD)/static
29 +NASM_BLD=$(OBJDIR)/nasm
30 +ENTRY_BLD=$(OBJDIR)/entry
31 +SRC_BLD=$(OBJDIR)/src
32 +BIT8_BLD=$(OBJDIR)/bits8
33 +BIT16_BLD=$(OBJDIR)/bits16
34 +TOOLS_BLD=$(BUILD)/tools
35 +TESTS_BLD=$(BUILD)/tests
36 +
37 +STATIC_LIB=$(BUILD)/src/libdav1d.a
38 +SHARED_LIB=$(BUILD)/src/libdav1d.so
39 +DEFS= -DNDEBUG -D_FILE_OFFSET_BITS=64 -D_POSIX_C_SOURCE=200112L
40 +FUZZ= -DDAV1D_MT_FUZZING
41 +
42 +BLD_INCL= $(DEFS) -I. -Isrc -Iinclude/dav1d -Iinclude \
43 +       -I$(BUILD) -I$(BUILD)/include -I$(BUILD)/include/dav1d
44 +TOOLS_INCL= $(DEFS) -Itools -I. -I$(BUILD) -I$(BUILD)/tools \
45 +       -Iinclude -Iinclude/dav1d -I$(BUILD)/include/dav1d \
46 +       -I$(BUILD)/include -I/usr/include/SDL2
47 +
48 +NP?=.NOTPARALLEL:
49 +$(NP)
50 +MAKE_P:=$(MAKE) -j NP=""
51 +
52 +all: meson_data
53 +       $(MAKE_P) $(STATIC_LIB) OBJDIR=$(BUILD)/static
54 +       $(MAKE_P) $(SHARED_LIB) OBJDIR=$(BUILD)/shared
55 +# req SDL
56 +#      $(MAKE_P) $(TOOLS) OBJDIR=$(BUILD)/static
57 +#      $(MAKE_P) $(TESTS) OBJDIR=$(BUILD)/static
58 +
59 +CC_DEFS=\
60 +       -DNDEBUG \
61 +       -D_FILE_OFFSET_BITS=64 \
62 +       -D_POSIX_C_SOURCE=200112L \
63 +
64 +CC_OPTS=\
65 +       -pipe \
66 +       -Wall \
67 +       -Winvalid-pch \
68 +       -Wextra \
69 +       -std=c99 \
70 +       -O3 \
71 +       -fvisibility=hidden \
72 +       -Wundef \
73 +       -Werror=vla \
74 +       -Wno-maybe-uninitialized \
75 +       -Wno-missing-field-initializers \
76 +       -Wno-unused-parameter \
77 +       -Werror=missing-prototypes \
78 +       -fomit-frame-pointer \
79 +       -ffast-math \
80 +       -fPIC \
81 +       -mpreferred-stack-boundary=5 \
82 +       -MD -MQ $@ -MF $@.d \
83 +
84 +SHA_OPTS=\
85 +       -Wl,--no-undefined \
86 +       -Wl,--as-needed \
87 +       -Wl,-O1 \
88 +       -shared \
89 +       -fPIC \
90 +       -Wl,--start-group \
91 +       -Wl,-soname,libdav1d.so.2 \
92 +       -Wl,--end-group \
93 +       -pthread \
94 +
95 +CC_CC=$(Q)cc $(CC_OPTS) $(CFLAGS)
96 +NASM=$(Q)/usr/bin/nasm
97 +any=$(foreach i,$(2),$(1)/$(i))
98 +
99 +# nasm
100 +NASM_OBJS=$(call any,$(NASM_BLD), \
101 +       cdef.obj \
102 +       film_grain.obj \
103 +       ipred.obj \
104 +       itx.obj \
105 +       cdef_sse.obj \
106 +       ipred_ssse3.obj \
107 +       loopfilter.obj \
108 +       looprestoration.obj \
109 +       mc.obj \
110 +       itx_ssse3.obj \
111 +       looprestoration_ssse3.obj \
112 +       loopfilter_ssse3.obj \
113 +       mc_ssse3.obj \
114 +       cpuid.obj \
115 +       msac.obj )
116 +
117 +$(NASM_BLD)/%.obj: src/x86/%.asm
118 +       $(NASM) -f $(ASM_ARCH) \
119 +               -I src/ -I $(BUILD)/ -MQ $@ -MF $@.ndep \
120 +               $< -o $@
121 +
122 +# entry
123 +ENTRY_OBJS=$(call any,$(ENTRY_BLD), \
124 +       lib.c.o \
125 +       thread_task.c.o)
126 +$(ENTRY_BLD)/%.c.o: src/%.c
127 +       $(CC_CC) -Iinclude -Ibuild/include/dav1d -Isrc/entry $(BLD_INCL) \
128 +               -mincoming-stack-boundary=4 -o $@ -c $<
129 +
130 +# src
131 +SRC_OBJS=$(call any,$(SRC_BLD), \
132 +       cdf.o \
133 +       cpu.o \
134 +       data.o \
135 +       decode.o \
136 +       dequant_tables.o \
137 +       getbits.o \
138 +       intra_edge.o \
139 +       lf_mask.o \
140 +       log.o \
141 +       msac.o \
142 +       obu.o \
143 +       picture.o \
144 +       qm.o \
145 +       ref.o \
146 +       ref_mvs.o \
147 +       scan.o \
148 +       tables.o \
149 +       warpmv.o \
150 +       wedge.o \
151 +       x86/cpu.c.o)
152 +$(SRC_BLD)/%.o: src/%.c
153 +       $(CC_CC) $(BLD_INCL) -pthread -o $@ -c $<
154 +$(SRC_BLD)/x86/%.c.o: src/x86/%.c
155 +       $(CC_CC) $(BLD_INCL) -o $@ -c $<
156 +
157 +# bits
158 +BITS_OBJS= \
159 +       cdef_tmpl.o \
160 +       cdef_apply_tmpl.o \
161 +       fg_apply_tmpl.o \
162 +       film_grain_tmpl.o \
163 +       ipred_tmpl.o \
164 +       ipred_prepare_tmpl.o \
165 +       itx_tmpl.o \
166 +       lf_apply_tmpl.o \
167 +       loopfilter_tmpl.o \
168 +       looprestoration_tmpl.o \
169 +       lr_apply_tmpl.o \
170 +       mc_tmpl.o \
171 +       recon_tmpl.o \
172 +       x86/cdef_init_tmpl.c.o \
173 +       x86/film_grain_init_tmpl.c.o \
174 +       x86/ipred_init_tmpl.c.o \
175 +       x86/itx_init_tmpl.c.o \
176 +       x86/loopfilter_init_tmpl.c.o \
177 +       x86/looprestoration_init_tmpl.c.o \
178 +       x86/mc_init_tmpl.c.o \
179 +
180 +BIT8_OBJS=$(call any,$(BIT8_BLD),$(BITS_OBJS))
181 +$(BIT8_BLD)/x86/%.c.o: src/x86/%.c
182 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=8 -o $@ -c $<
183 +$(BIT8_BLD)/%.o: src/%.c
184 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=8 -o $@ -c $<
185 +
186 +BIT16_OBJS=$(call any,$(BIT16_BLD),$(BITS_OBJS))
187 +$(BIT16_BLD)/x86/%.c.o: src/x86/%.c
188 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=16 -o $@ -c $<
189 +$(BIT16_BLD)/%.o: src/%.c
190 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=16 -o $@ -c $<
191 +
192 +$(BUILD)/config.h:
193 +       echo  > $@ "#pragma once"
194 +       echo >> $@ "#define ARCH_AARCH64 0"
195 +       echo >> $@ "#define ARCH_ARM 0"
196 +       echo >> $@ "#define ARCH_PPC64LE 0"
197 +       echo >> $@ "#define ARCH_X86 1"
198 +       echo >> $@ "#define ARCH_X86_32 $(ARCH_X86_32)"
199 +       echo >> $@ "#define ARCH_X86_64 $(ARCH_X86_64)"
200 +       echo >> $@ "#define CONFIG_16BPC 1"
201 +       echo >> $@ "#define CONFIG_8BPC 1"
202 +       echo >> $@ "#define CONFIG_LOG 1"
203 +       echo >> $@ "#define ENDIANNESS_BIG 0"
204 +       echo >> $@ "#define HAVE_ASM 1"
205 +       echo >> $@ "#define HAVE_POSIX_MEMALIGN 1"
206 +       echo >> $@ "#define HAVE_UNISTD_H 1"
207 +       echo >> $@ "#define STACK_ALIGNMENT 32"
208 +
209 +$(BUILD)/config.asm:
210 +       echo  > $@ "%define ARCH_X86_32 $(ARCH_X86_32)"
211 +       echo >> $@ "%define ARCH_X86_64 $(ARCH_X86_64)"
212 +       echo >> $@ "%define PIC 1"
213 +       echo >> $@ "%define STACK_ALIGNMENT 32"
214 +
215 +$(BUILD)/include/vcs_version.h:
216 +       mkdir -p $(BUILD)/include
217 +       echo  > $@ "#define DAV1D_VERSION \"0.5.0\""
218 +
219 +$(BUILD)/include/dav1d/version.h:
220 +       mkdir -p $(BUILD)/include/dav1d
221 +       echo  > $@ "#ifndef DAV1D_VERSION_H"
222 +       echo >> $@ "#define DAV1D_VERSION_H"
223 +       echo >> $@ "#define DAV1D_API_VERSION_MAJOR 2"
224 +       echo >> $@ "#define DAV1D_API_VERSION_MINOR 0"
225 +       echo >> $@ "#define DAV1D_API_VERSION_PATCH 0"
226 +       echo >> $@ "#endif /* DAV1D_VERSION_H */"
227 +
228 +$(TOOLS_BLD)/cli_config.h:
229 +       mkdir -p $(TOOLS_BLD)
230 +       echo  > $@ "#pragma once"
231 +       echo >> $@ "#define HAVE_CLOCK_GETTIME 1"
232 +
233 +.PHONY: meson_data
234 +meson_data:
235 +       make meson_dirs OBJDIR=$(BUILD)/static
236 +       make meson_dirs OBJDIR=$(BUILD)/shared
237 +       ln -sf ./include/compat/gcc/stdatomic.h .
238 +
239 +.PHONY: meson_dirs
240 +meson_dirs: $(OBJDIR) \
241 +       $(BUILD)/config.h $(BUILD)/config.asm \
242 +       $(BUILD)/include/vcs_version.h \
243 +       $(BUILD)/include/dav1d/version.h \
244 +       $(TOOLS_BLD)/cli_config.h \
245 +
246 +LIB_OBJS=$(ENTRY_OBJS) $(NASM_OBJS) $(SRC_OBJS) $(BIT8_OBJS) $(BIT16_OBJS)
247 +
248 +$(STATIC_LIB): DIR?=static
249 +$(STATIC_LIB): $(LIB_OBJS)
250 +       rm -f $@
251 +       gcc-ar csrD $@ $(LIB_OBJS)
252 +
253 +$(SHARED_LIB): DIR?=shared
254 +$(SHARED_LIB): $(LIB_OBJS)
255 +       rm -f $@
256 +       cc -o $@ $(LIB_OBJS) $(SHA_OPTS)
257 +
258 +# tools
259 +DAV1D_OBJS=$(call any,$(TOOLS_BLD),\
260 +       dav1d.o \
261 +       dav1d_cli_parse.o \
262 +       input/annexb.o \
263 +       input/ivf.o \
264 +       input/input.o \
265 +       output/md5.o \
266 +       output/null.o \
267 +       output/output.o \
268 +       output/y4m2.o \
269 +       output/yuv.o)
270 +
271 +DAV1DPLAY_OBJS=$(call any,$(TOOLS_BLD),\
272 +       dav1dplay.o \
273 +       input/annexb.o \
274 +       input/ivf.o \
275 +       input/input.o)
276 +
277 +$(TOOLS_BLD)/%.o: tools/%.c
278 +       $(CC_CC) $(TOOLS_INCL) -o $@ -c $<
279 +
280 +DAV1D=$(TOOLS_BLD)/dav1d
281 +$(DAV1D): $(DAV1D_OBJS)
282 +       $(CC_CC) -pthread -I$(BUILD) -o $@ $(DAV1D_OBJS) $(STATIC_LIB)
283 +
284 +DAV1DPLAY=$(TOOLS_BLD)/dav1dplay
285 +$(DAV1DPLAY): $(DAV1DPLAY_OBJS)
286 +       $(CC_CC) -pthread -o $(TOOLS_BLD)/dav1dplay $(DAV1DPLAY_OBJS) $(STATIC_LIB) -lSDL2
287 +
288 +TOOLS=$(DAV1D) $(DAV1DPLAY)
289 +.PHONY:        tools
290 +tools: $(TOOLS)
291 +
292 +# tests
293 +TESTS_CHKASM=tests/checkasm
294 +TESTS_CHKASM_BLD=$(TESTS_BLD)/checkasm
295 +CHKASM_BIT8=$(TESTS_CHKASM_BLD)/bit8
296 +CHKASM_BIT16=$(TESTS_CHKASM_BLD)/bit16
297 +CHKASM_BITS= \
298 +       cdef.o \
299 +       ipred.o \
300 +       itx.o \
301 +       loopfilter.o \
302 +       looprestoration.o \
303 +       mc.o \
304 +
305 +CHKASM_BIT8_OBJS=$(call any,$(CHKASM_BIT8),$(CHKASM_BITS))
306 +CHKASM_BIT16_OBJS=$(call any,$(CHKASM_BIT16),$(CHKASM_BITS))
307 +
308 +TESTS_CHKASM_OBJS= \
309 +       $(TESTS_CHKASM_BLD)/checkasm.o \
310 +       $(TESTS_CHKASM_BLD)/msac.o \
311 +       $(CHKASM_BIT8_OBJS) $(CHKASM_BIT16_OBJS) \
312 +       $(TESTS_CHKASM_BLD)/x86/checkasm.obj \
313 +
314 +$(TESTS_CHKASM_BLD)/%.o: $(TESTS_CHKASM)/%.c
315 +       $(CC_CC) $(BLD_INCL) -o $@ -c $<
316 +$(CHKASM_BIT8)/%.o: $(TESTS_CHKASM)/%.c
317 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=8 -o $@ -c $<
318 +$(CHKASM_BIT16)/%.o: $(TESTS_CHKASM)/%.c
319 +       $(CC_CC) $(BLD_INCL) -DBITDEPTH=16 -o $@ -c $<
320 +$(TESTS_CHKASM_BLD)/x86/%.obj: $(TESTS_CHKASM)/x86/%.asm
321 +       @$(NASM) -f $(ASM_ARCH) \
322 +               -I src/ -I $(BUILD)/ -MQ $@ -MF $@.ndep \
323 +               $< -o $@
324 +
325 +CHECKASM=$(TESTS_BLD)/checkasm/checkasm
326 +$(CHECKASM): $(TESTS_CHKASM_OBJS) $(STATIC_LIB)
327 +       $(CC_CC) -pthread -o $@ $(TESTS_CHKASM_OBJS) $(STATIC_LIB) -lm
328 +
329 +TESTS_FUZZER=tests/libfuzzer
330 +TESTS_FUZZER_BLD=$(TESTS_BLD)/libfuzzer
331 +TESTS_FUZZER_OBJS= \
332 +       $(TESTS_FUZZER_BLD)/main.o \
333 +       $(TESTS_FUZZER_BLD)/dav1d_fuzzer.o \
334 +
335 +$(TESTS_FUZZER_BLD)/%.o: $(TESTS_FUZZER)/%.c
336 +       $(CC_CC) $(BLD_INCL) -o $@ -c $<
337 +
338 +DAV1D_FUZZER=$(TESTS_BLD)/dav1d_fuzzer
339 +$(DAV1D_FUZZER): $(TESTS_FUZZER_OBJS) $(STATIC_LIB)
340 +       $(CC_CC) -pthread -o $@ $(TESTS_FUZZER_OBJS) $(STATIC_LIB)
341 +
342 +TESTS=$(CHECKASM) $(DAV1D_FUZZER)
343 +.PHONY:        tests
344 +tests: $(TESTS)
345 +
346 +$(OBJDIR):
347 +       mkdir -p $@/include/dav1d \
348 +               $(BUILD)/src $(BUILD)/include \
349 +               $(ENTRY_BLD) $(NASM_BLD) \
350 +               $(SRC_BLD)/x86 $(BIT8_BLD)/x86 $(BIT16_BLD)/x86 \
351 +               $(TOOLS_BLD) $(TOOLS_BLD)/input $(TOOLS_BLD)/output \
352 +               $(TESTS_CHKASM_BLD)/bit8 $(TESTS_CHKASM_BLD)/bit16 \
353 +               $(TESTS_CHKASM_BLD)/x86 $(TESTS_FUZZER_BLD) \
354 +
355 +clean:
356 +       rm -rf $(BUILD)
357 +
358 +install:
359 +       mkdir -p $(DESTDIR)$(LIBDIR)
360 +       cp -a $(STATIC_LIB) $(DESTDIR)$(LIBDIR)
361 +       cp -a $(SHARED_LIB) $(DESTDIR)$(LIBDIR)
362 +       mkdir -p $(DESTDIR)$(INCDIR)
363 +       cp -a include/dav1d $(DESTDIR)$(INCDIR)
364 +       rm -f $(DESTDIR)$(INCDIR)/dav1d/meson.build
365 +       rm -f $(DESTDIR)$(INCDIR)/dav1d/version.h.in
366 +       cp -a $(BUILD)/include/dav1d/version.h $(DESTDIR)$(INCDIR)/version.h
367 +