Set up Makefile for building libkvazaar.so.

Adds targets "libkvazaar.so.0.0.0", "install", "install-prog" and
"install-lib" to the Makefile.
This commit is contained in:
Arttu Ylä-Outinen 2015-07-01 08:17:21 +03:00
parent 4ab9aa3e2f
commit af2b417809
3 changed files with 102 additions and 81 deletions

1
.gitignore vendored
View file

@ -19,3 +19,4 @@
*.log *.log
.kdev4 .kdev4
src/kvazaar src/kvazaar
src/libkvazaar.so.*

View file

@ -1,14 +1,38 @@
# Simple Makefile for Kvazaar HEVC encoder # Simple Makefile for Kvazaar HEVC encoder
#Disable default rules # Installation locations
.SUFFIXES: 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)) ifeq (, $(ARCH))
ARCH = $(shell uname -m) ARCH = $(shell uname -m)
endif endif
SYSTEM = $(shell uname -s) SYSTEM = $(shell uname -s)
ASMFLAGS =
CFLAGS += -O2 -g -Werror -ftree-vectorize
# ARCH related flags # ARCH related flags
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
@ -29,54 +53,65 @@ LDFLAGS += -m$(TARGET_CPU_BITS)
# Windows (cygwin/mingw) specific flags # Windows (cygwin/mingw) specific flags
ifneq ( ,$(findstring Windows, $(OS))) ifneq ( ,$(findstring Windows, $(OS)))
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
ASMFLAGS += -f win64 ASFLAGS += -f win64
ASMFLAGS += -DHAVE_ALIGNED_STACK=1 ASFLAGS += -DHAVE_ALIGNED_STACK=1
else else
ASMFLAGS += -f win32 ASFLAGS += -f win32
ASMFLAGS += -DPREFIX ASFLAGS += -DPREFIX
ASMFLAGS += -DHAVE_ALIGNED_STACK=0 ASFLAGS += -DHAVE_ALIGNED_STACK=0
endif endif
CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
# OS X specific flags # OS X specific flags
else ifeq ($(SYSTEM),Darwin) else ifeq ($(SYSTEM),Darwin)
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
ASMFLAGS += -f macho64 ASFLAGS += -f macho64
else else
ASMFLAGS += -f macho32 ASFLAGS += -f macho32
endif endif
ASMFLAGS += -DPREFIX ASFLAGS += -DPREFIX
# Default to Linux/elf specific flags # Default to Linux/elf specific flags
else else
LDFLAGS += -lrt LDFLAGS += -lrt
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
ASMFLAGS += -f elf64 ASFLAGS += -f elf64
else else
ASMFLAGS += -f elf32 ASFLAGS += -f elf32
endif endif
endif endif
# Flags shared across systems # Flags shared across systems
ifeq ($(ARCH), x86_64) ifeq ($(ARCH), x86_64)
ASMFLAGS += -DARCH_X86_64=1 ASFLAGS += -DARCH_X86_64=1
else else
ASMFLAGS += -DARCH_X86_64=0 ASFLAGS += -DARCH_X86_64=0
endif 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 #Detect if cc is gcc for the link time optimization flag
GCCVERSION = $(shell $(CC) --version | grep GCC) GCCVERSION = $(shell $(CC) --version | grep GCC)
ifneq (, $(GCCVERSION)) ifneq (, $(GCCVERSION))
CFLAGS += -flto CFLAGS += -flto
LDFLAGS += -flto -O3 LDFLAGS += -flto -O3
endif endif
CFLAGS += -std=gnu99 $(INCLUDEDIRS) $(WARNINGS)
LDFLAGS += -lm -pthread # Compile asm files by default if yasm is present.
LD = gcc 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 = \ OBJS = \
bitstream.o \ bitstream.o \
cabac.o \ cabac.o \
@ -124,7 +159,13 @@ OBJS = \
strategies/generic/ipol-generic.o \ strategies/generic/ipol-generic.o \
strategies/avx2/ipol-avx2.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 TESTDIR := ../tests
TEST_OBJS := \ TEST_OBJS := \
@ -136,57 +177,17 @@ TEST_OBJS := \
$(TESTDIR)/tests_main.o \ $(TESTDIR)/tests_main.o \
$(TESTDIR)/test_strategies.o $(TESTDIR)/test_strategies.o
MAIN_OBJS := encmain.o interface_main.o
ASMFLAGS += $(INCLUDEDIRS)
ASMOBJS =
AS = yasm RELEASE_OBJS = $(MAIN_OBJS) $(OBJS)
DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o)
# Compile asm files by default if yasm is present. TESTS_OBJS = $(TEST_OBJS) $(OBJS)
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
PROGS = $(PROG) $(DEBUG) $(TESTS) 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) DEPS = $(RELEASE_OBJS:.o=.d) $(DEBUG_OBJS:.o=.d) $(TESTS_OBJS:.o=.d)
GREATEST = ../greatest/greatest.h all: $(PROG) $(LIB)
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
debug: LDFLAGS := $(filter-out -O3 -O2 -flto, $(LDFLAGS)) debug: LDFLAGS := $(filter-out -O3 -O2 -flto, $(LDFLAGS))
debug: CFLAGS := $(filter-out -O3 -O2 -flto, $(CFLAGS)) debug: CFLAGS := $(filter-out -O3 -O2 -flto, $(CFLAGS))
@ -198,20 +199,21 @@ tests: build_tests
build_tests: CFLAGS := $(filter-out -Werror, $(CFLAGS)) build_tests: CFLAGS := $(filter-out -Werror, $(CFLAGS))
build_tests: init_submodules $(TESTS) build_tests: init_submodules $(TESTS)
REMOVE_FILES = $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(PROGS)
$(PROG): $(RELEASE_OBJS) $(PROG): $(RELEASE_OBJS)
$(LD) $^ $(LDFLAGS) -o $@ $(LD) $^ $(LDFLAGS) -o $@
$(LIB): $(RELEASE_OBJS)
$(LD) $^ $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@
$(DEBUG): $(DEBUG_OBJS) $(DEBUG): $(DEBUG_OBJS)
$(LD) $^ $(LDFLAGS) -o $@ $(LD) $^ $(LDFLAGS) -o $@
$(TESTS): $(TESTS_OBJS) $(TESTS): $(TESTS_OBJS)
$(LD) $^ $(LDFLAGS) -o $@ $(LD) $^ $(LDFLAGS) -o $@
%.o %_debug.o: %.asm Makefile %.o %_debug.o: %.asm Makefile
$(AS) $(ASMFLAGS) -o $@ $< $(AS) $(ASFLAGS) -o $@ $<
%.o %_debug.o: %.c Makefile %.o %_debug.o: %.c Makefile
$(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@
@ -219,9 +221,27 @@ init_submodules:
git submodule init git submodule init
git submodule update 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: clean:
rm -f $(REMOVE_FILES) $(RM) $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(PROGS) $(LIB)
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS) -include $(DEPS)
endif endif
# Disable default rules
.SUFFIXES:
.PHONY: all clean build_tests tests debug init_submodules
.PHONY: install install-prog install-lib

View file

@ -23,8 +23,6 @@
* *
*/ */
#include "kvazaar_internal.h"
#ifdef _WIN32 #ifdef _WIN32
/* The following two defines must be located before the inclusion of any system header files. */ /* The following two defines must be located before the inclusion of any system header files. */
#define WINVER 0x0500 #define WINVER 0x0500
@ -33,6 +31,8 @@
#include <fcntl.h> /* _O_BINARY */ #include <fcntl.h> /* _O_BINARY */
#endif #endif
#include "kvazaar_internal.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>