Add static library target to Makefile.

Adds targets libkvazaar.a and install-static to the Makefile.
This commit is contained in:
Arttu Ylä-Outinen 2015-08-20 14:45:38 +03:00
parent 23159e45b7
commit cb49586d36
3 changed files with 42 additions and 15 deletions

1
.gitignore vendored
View file

@ -20,6 +20,7 @@
*.log *.log
.kdev4 .kdev4
src/kvazaar src/kvazaar
src/libkvazaar.a
src/libkvazaar.so.* src/libkvazaar.so.*
src/kvazaar.dll src/kvazaar.dll
src/libkvazaar.dll.a src/libkvazaar.dll.a

View file

@ -21,6 +21,7 @@ DEBUG = kvazaar_debug
TESTS = kvazaar_tests TESTS = kvazaar_tests
NAME = libkvazaar NAME = libkvazaar
STATIC = $(NAME).a
SO = $(NAME).so SO = $(NAME).so
LIB = $(SO).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) LIB = $(SO).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE)
DYLIB = $(NAME).$(VER_MAJOR).dylib DYLIB = $(NAME).$(VER_MAJOR).dylib
@ -34,6 +35,7 @@ AS = yasm
LD = $(CC) LD = $(CC)
INSTALL = install INSTALL = install
LN_S = ln -s LN_S = ln -s
RANLIB = ranlib
# Do not use variable length arrays because they don't work in Visual Studio 2013. # Do not use variable length arrays because they don't work in Visual Studio 2013.
WARNINGS = -Werror -Wall -Wtype-limits -Wvla WARNINGS = -Werror -Wall -Wtype-limits -Wvla
@ -138,12 +140,16 @@ endif
# Compile files in strategy directories with appropriate flags. # Compile files in strategy directories with appropriate flags.
ifeq ($(ARCH), ppc64) ifeq ($(ARCH), ppc64)
strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto
strategies/altivec/%.lo: EXTRA_FLAGS += -maltivec -fno-lto
else else
strategies/sse2/%.o: EXTRA_FLAGS += -msse2 -fno-lto strategies/sse2/%.o: EXTRA_FLAGS += -msse2 -fno-lto
strategies/sse41/%.o: EXTRA_FLAGS += -msse4.1 -fno-lto strategies/sse41/%.o: EXTRA_FLAGS += -msse4.1 -fno-lto
strategies/sse2/%.lo: EXTRA_FLAGS += -msse2 -fno-lto
strategies/sse41/%.lo: EXTRA_FLAGS += -msse4.1 -fno-lto
# Needs to be defined on Travis # Needs to be defined on Travis
ifndef KVZ_DISABLE_AVX2 ifndef KVZ_DISABLE_AVX2
strategies/avx2/%.o: EXTRA_FLAGS += -mavx2 -fno-lto strategies/avx2/%.o: EXTRA_FLAGS += -mavx2 -fno-lto
strategies/avx2/%.lo: EXTRA_FLAGS += -mavx2 -fno-lto
endif endif
endif endif
@ -218,12 +224,8 @@ MAIN_OBJS := \
yuv_io.o yuv_io.o
RELEASE_OBJS = $(MAIN_OBJS) $(OBJS) RELEASE_OBJS = $(MAIN_OBJS) $(OBJS)
# Compile separate PIC objects for Linux/OSX. # Compile separate PIC objects for shared libraries
ifeq ($(SYSTEM), Windows)
SHARED_OBJS = $(OBJS)
else
SHARED_OBJS = $(OBJS:.o=.lo) SHARED_OBJS = $(OBJS:.o=.lo)
endif
DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o) DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o)
TESTS_OBJS = $(TEST_OBJS) $(OBJS) TESTS_OBJS = $(TEST_OBJS) $(OBJS)
@ -232,7 +234,7 @@ DEPS = $(RELEASE_OBJS:.o=.d) $(DEBUG_OBJS:.o=.d) $(TESTS_OBJS:.o=.d)
.PHONY: cli lib-shared lib-static debug tests build_tests .PHONY: cli lib-shared lib-static debug tests build_tests
cli: $(PROG) cli: $(PROG)
lib-shared: $(LIBKVAZAAR_SHARED) lib-shared: $(LIBKVAZAAR_SHARED)
lib-static: # TODO lib-static: $(STATIC)
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))
@ -254,6 +256,11 @@ $(DYLIB): LDFLAGS += -dynamiclib \
$(PROG): $(RELEASE_OBJS) $(PROG): $(RELEASE_OBJS)
$(LD) $^ $(LDFLAGS) $(LIBS) -o $@ $(LD) $^ $(LDFLAGS) $(LIBS) -o $@
$(STATIC): $(OBJS)
$(RM) $@
$(AR) rcD $@ $^
$(RANLIB) $@
$(LIB) $(DLL) $(DYLIB): $(SHARED_OBJS) $(LIB) $(DLL) $(DYLIB): $(SHARED_OBJS)
$(LD) $^ $(LDFLAGS) $(LIBS) -o $@ $(LD) $^ $(LDFLAGS) $(LIBS) -o $@
@ -275,15 +282,22 @@ $(TESTS): $(TESTS_OBJS)
%_debug.lo: %.asm Makefile %_debug.lo: %.asm Makefile
$(AS) $(ASFLAGS) -o $@ $< $(AS) $(ASFLAGS) -o $@ $<
# Object files not meant for shared libs need KVZ_STATIC_LIB defined so
# that the names of the API functions don't get mangled on Windows.
%.o: CFLAGS += -DKVZ_STATIC_LIB
%.o: %.c Makefile %.o: %.c Makefile
$(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@
%_debug.o: %.c Makefile %_debug.o: %.c Makefile
$(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@
ifneq ($(SYSTEM), Windows)
# Only use -fpic when not on Windows
%.lo: CFLAGS += -fpic
endif
%.lo: %.c Makefile %.lo: %.c Makefile
$(CC) -fpic $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@
%_debug.lo: %.c Makefile %_debug.lo: %.c Makefile
$(CC) -fpic $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@
.PHONY: kvazaar.pc init_submodules install install-pc install-prog install-lib .PHONY: kvazaar.pc init_submodules install install-pc install-prog install-lib
@ -307,6 +321,12 @@ install-prog: $(PROG)
$(INSTALL) -d $(DESTDIR)$(BINDIR) $(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m755 $(PROG) $(DESTDIR)$(BINDIR) $(INSTALL) -m755 $(PROG) $(DESTDIR)$(BINDIR)
install-static: $(STATIC)
$(INSTALL) -d $(DESTDIR)$(INCDIR)
$(INSTALL) -d $(DESTDIR)$(LIBDIR)
$(INSTALL) -m644 $(INC) $(DESTDIR)$(INCDIR)
$(INSTALL) -m644 $(STATIC) $(DESTDIR)$(LIBDIR)
install-lib: $(LIB) install-lib: $(LIB)
$(INSTALL) -d $(DESTDIR)$(INCDIR) $(INSTALL) -d $(DESTDIR)$(INCDIR)
$(INSTALL) -d $(DESTDIR)$(LIBDIR) $(INSTALL) -d $(DESTDIR)$(LIBDIR)
@ -332,7 +352,7 @@ install-dll: $(DLL)
clean: clean:
$(RM) $(RELEASE_OBJS) $(SHARED_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(RM) $(RELEASE_OBJS) $(SHARED_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS)
$(RM) $(PROG) $(DEBUG) $(TESTS) $(LIB) $(DLL) $(IMPLIB) $(DYLIB) $(RM) $(PROG) $(DEBUG) $(TESTS) $(STATIC) $(LIB) $(DLL) $(IMPLIB) $(DYLIB)
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS) -include $(DEPS)

View file

@ -34,13 +34,19 @@
extern "C" { extern "C" {
#endif #endif
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(KVZ_STATIC_LIB)
// Using or building kvazaar as a static library.
#define KVZ_PUBLIC
#elif defined(_WIN32) || defined(__CYGWIN__)
#ifdef KVZ_DLL_EXPORTS #ifdef KVZ_DLL_EXPORTS
// Building kvazaar on windows.
#define KVZ_PUBLIC __declspec(dllexport) #define KVZ_PUBLIC __declspec(dllexport)
#else #else
// Using kvazaar as a DLL on windows.
#define KVZ_PUBLIC __declspec(dllimport) #define KVZ_PUBLIC __declspec(dllimport)
#endif #endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
// Using GCC and not on windows.
#define KVZ_PUBLIC __attribute__ ((visibility ("default"))) #define KVZ_PUBLIC __attribute__ ((visibility ("default")))
#else #else
#define KVZ_PUBLIC #define KVZ_PUBLIC