diff --git a/.gitignore b/.gitignore index c56a2624..632aa69f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ *.log .kdev4 src/kvazaar +src/libkvazaar.so.* diff --git a/src/Makefile b/src/Makefile index 3b81a6db..3b4fe462 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,14 +1,38 @@ # Simple Makefile for Kvazaar HEVC encoder -#Disable default rules -.SUFFIXES: +# Installation locations +DESTDIR = +PREFIX = /usr/local +BINDIR = $(PREFIX)/bin +INCDIR = $(PREFIX)/include +LIBDIR = $(PREFIX)/lib + +PROG = ./kvazaar +DEBUG = ./kvazaar_debug +TESTS = ./kvazaar_tests +LIB = ./libkvazaar.so.0.0.0 +SONAME = libkvazaar.so.0 +INC = ./kvazaar.h \ + ./kvazaar_version.h + +# Compilers and other tools +AS = yasm +LD = gcc +INSTALL = install + +# Do not use variable length arrays because they don't work in Visual Studio 2013. +WARNINGS = -Wall -Wtype-limits -Wvla +INCLUDEDIRS = -I. -I./strategies -I./extras -I.. + +ASFLAGS += $(INCLUDEDIRS) +CFLAGS += -O2 -g -Werror -ftree-vectorize -fpic -std=gnu99 +CFLAGS += $(INCLUDEDIRS) $(WARNINGS) +LDFLAGS += -lm -pthread ifeq (, $(ARCH)) ARCH = $(shell uname -m) endif SYSTEM = $(shell uname -s) -ASMFLAGS = -CFLAGS += -O2 -g -Werror -ftree-vectorize # ARCH related flags ifeq ($(ARCH), x86_64) @@ -29,54 +53,65 @@ LDFLAGS += -m$(TARGET_CPU_BITS) # Windows (cygwin/mingw) specific flags ifneq ( ,$(findstring Windows, $(OS))) ifeq ($(ARCH), x86_64) - ASMFLAGS += -f win64 - ASMFLAGS += -DHAVE_ALIGNED_STACK=1 + ASFLAGS += -f win64 + ASFLAGS += -DHAVE_ALIGNED_STACK=1 else - ASMFLAGS += -f win32 - ASMFLAGS += -DPREFIX - ASMFLAGS += -DHAVE_ALIGNED_STACK=0 + ASFLAGS += -f win32 + ASFLAGS += -DPREFIX + ASFLAGS += -DHAVE_ALIGNED_STACK=0 endif CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 # OS X specific flags else ifeq ($(SYSTEM),Darwin) ifeq ($(ARCH), x86_64) - ASMFLAGS += -f macho64 + ASFLAGS += -f macho64 else - ASMFLAGS += -f macho32 + ASFLAGS += -f macho32 endif - ASMFLAGS += -DPREFIX + ASFLAGS += -DPREFIX # Default to Linux/elf specific flags else LDFLAGS += -lrt ifeq ($(ARCH), x86_64) - ASMFLAGS += -f elf64 + ASFLAGS += -f elf64 else - ASMFLAGS += -f elf32 + ASFLAGS += -f elf32 endif endif # Flags shared across systems ifeq ($(ARCH), x86_64) - ASMFLAGS += -DARCH_X86_64=1 + ASFLAGS += -DARCH_X86_64=1 else - ASMFLAGS += -DARCH_X86_64=0 + ASFLAGS += -DARCH_X86_64=0 endif -# Do not use variable length arrays because they don't work in Visual Studio 2013. -WARNINGS = -Wall -Wtype-limits -Wvla - -INCLUDEDIRS = -I. -I./strategies -I./extras -I.. - -STRATEGIES = generic sse2 sse41 avx2 x86_asm altivec - #Detect if cc is gcc for the link time optimization flag GCCVERSION = $(shell $(CC) --version | grep GCC) ifneq (, $(GCCVERSION)) CFLAGS += -flto LDFLAGS += -flto -O3 endif -CFLAGS += -std=gnu99 $(INCLUDEDIRS) $(WARNINGS) -LDFLAGS += -lm -pthread -LD = gcc + +# Compile asm files by default if yasm is present. +ifndef KVZ_DISABLE_ASM + has_as := $(shell type $(AS) 2>/dev/null) + ifeq ($(has_as),) + KVZ_DISABLE_ASM := 1 + endif +endif + +# Compile files in strategy directories with appropriate flags. +ifeq ($(ARCH), ppc64) + strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto +else + strategies/sse2/%.o: EXTRA_FLAGS += -msse2 -fno-lto + strategies/sse41/%.o: EXTRA_FLAGS += -msse4.1 -fno-lto + # Needs to be defined on Travis + ifndef KVZ_DISABLE_AVX2 + strategies/avx2/%.o: EXTRA_FLAGS += -mavx2 -fno-lto + endif +endif + OBJS = \ bitstream.o \ cabac.o \ @@ -124,7 +159,13 @@ OBJS = \ strategies/generic/ipol-generic.o \ strategies/avx2/ipol-avx2.o -MAIN_OBJS := encmain.o interface_main.o +ifndef KVZ_DISABLE_ASM + strategies/x86_asm/%.o: EXTRA_FLAGS += -DKVZ_COMPILE_ASM + + OBJS += \ + strategies/x86_asm/picture-x86-asm-sad.o \ + strategies/x86_asm/picture-x86-asm-satd.o +endif TESTDIR := ../tests TEST_OBJS := \ @@ -136,57 +177,17 @@ TEST_OBJS := \ $(TESTDIR)/tests_main.o \ $(TESTDIR)/test_strategies.o - -ASMFLAGS += $(INCLUDEDIRS) -ASMOBJS = +MAIN_OBJS := encmain.o interface_main.o -AS = yasm - -# Compile asm files by default if yasm is present. -ifndef KVZ_DISABLE_ASM - has_as := $(shell type $(AS) 2>/dev/null) - ifeq ($(has_as),) - KVZ_DISABLE_ASM := 1 - endif -endif - - -PROG = ./kvazaar -DEBUG = ./kvazaar_debug -TESTS = ./kvazaar_tests +RELEASE_OBJS = $(MAIN_OBJS) $(OBJS) +DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o) +TESTS_OBJS = $(TEST_OBJS) $(OBJS) PROGS = $(PROG) $(DEBUG) $(TESTS) -RELEASE_OBJS = $(MAIN_OBJS) $(OBJS) $(ASMOBJS) -DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o) -TESTS_OBJS = $(TEST_OBJS) $(OBJS) $(ASMOBJS) - - DEPS = $(RELEASE_OBJS:.o=.d) $(DEBUG_OBJS:.o=.d) $(TESTS_OBJS:.o=.d) -GREATEST = ../greatest/greatest.h - -all: $(PROG) -.PHONY: all clean build_tests tests debug - - -# Compile files in strategy directories with appropriate flags. -ifeq ($(ARCH), ppc64) - strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto -else - strategies/sse2/%.o: EXTRA_FLAGS += -msse2 -fno-lto - strategies/sse41/%.o: EXTRA_FLAGS += -msse4.1 -fno-lto - #Needs to be defined on Travis - ifndef KVZ_DISABLE_AVX2 - strategies/avx2/%.o: EXTRA_FLAGS += -mavx2 -fno-lto - endif -endif - -ifndef KVZ_DISABLE_ASM - ASMOBJS += strategies/x86_asm/picture-x86-asm-sad.o - ASMOBJS += strategies/x86_asm/picture-x86-asm-satd.o - strategies/x86_asm/%.o: EXTRA_FLAGS += -DKVZ_COMPILE_ASM -endif +all: $(PROG) $(LIB) debug: LDFLAGS := $(filter-out -O3 -O2 -flto, $(LDFLAGS)) debug: CFLAGS := $(filter-out -O3 -O2 -flto, $(CFLAGS)) @@ -198,20 +199,21 @@ tests: build_tests build_tests: CFLAGS := $(filter-out -Werror, $(CFLAGS)) build_tests: init_submodules $(TESTS) -REMOVE_FILES = $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(PROGS) - $(PROG): $(RELEASE_OBJS) $(LD) $^ $(LDFLAGS) -o $@ - + +$(LIB): $(RELEASE_OBJS) + $(LD) $^ $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@ + $(DEBUG): $(DEBUG_OBJS) $(LD) $^ $(LDFLAGS) -o $@ - + $(TESTS): $(TESTS_OBJS) $(LD) $^ $(LDFLAGS) -o $@ %.o %_debug.o: %.asm Makefile - $(AS) $(ASMFLAGS) -o $@ $< - + $(AS) $(ASFLAGS) -o $@ $< + %.o %_debug.o: %.c Makefile $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ @@ -219,9 +221,27 @@ init_submodules: git submodule init git submodule update +install: install-prog install-lib + +install-prog: $(PROG) + $(INSTALL) -d $(DESTDIR)$(BINDIR) + $(INSTALL) -m755 $(PROG) -t $(DESTDIR)$(BINDIR) + +install-lib: $(LIB) + $(INSTALL) -d $(DESTDIR)$(INCDIR) + $(INSTALL) -d $(DESTDIR)$(LIBDIR) + $(INSTALL) -m644 $(INC) -t $(DESTDIR)$(INCDIR) + $(INSTALL) -m644 $(LIB) -t $(DESTDIR)$(LIBDIR) + clean: - rm -f $(REMOVE_FILES) + $(RM) $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(PROGS) $(LIB) ifneq ($(MAKECMDGOALS),clean) -include $(DEPS) endif + +# Disable default rules +.SUFFIXES: + +.PHONY: all clean build_tests tests debug init_submodules +.PHONY: install install-prog install-lib diff --git a/src/encmain.c b/src/encmain.c index 2f9d7396..c907ee22 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -23,8 +23,6 @@ * */ -#include "kvazaar_internal.h" - #ifdef _WIN32 /* The following two defines must be located before the inclusion of any system header files. */ #define WINVER 0x0500 @@ -33,6 +31,8 @@ #include /* _O_BINARY */ #endif +#include "kvazaar_internal.h" + #include #include #include