shared library support (.so)
authorJohn Koleszar <jkoleszar@google.com>
Thu, 3 Jun 2010 14:29:04 +0000 (10:29 -0400)
committerJohn Koleszar <john.koleszar@on2.com>
Sat, 5 Jun 2010 20:47:23 +0000 (16:47 -0400)
This patch adds support for building shared libraries when configured
with the --enable-shared switch.

Building DLLs would require more invasive changes to the sample
utilities than I want to make in this patch, since on Windows you can't
use the address of an imported symbol in a static initializer. The best
way to work around this is proably to build the codec interface mapping
table with an init() function, but dll support is of questionable value
anyway, since most windows users will probably use a media framework
lib like webmdshow, which links this library in staticly.

Change-Id: Iafb48900549b0c6b67f4a05d3b790b2643d026f4

build/make/Makefile
configure
libs.mk
vp8/exports_dec [new file with mode: 0644]
vp8/exports_enc [new file with mode: 0644]
vp8/vp8cx.mk
vp8/vp8dx.mk
vpx/exports [deleted file]
vpx/exports_com [new file with mode: 0644]
vpx/exports_dec [new file with mode: 0644]
vpx/exports_enc [new file with mode: 0644]

index 6dd1279..ba2578e 100755 (executable)
@@ -220,6 +220,20 @@ $(1):
        $(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
 endef
 
+define so_template
+# Not using a pattern rule here because we don't want to generate empty
+# archives when they are listed as a dependency in files not responsible
+# for creating them.
+#
+# This needs further abstraction for dealing with non-GNU linkers.
+$(1):
+       $(if $(quiet),@echo "    [LD] $$@")
+       $(qexec)$$(LD) -shared $$(LDFLAGS) \
+            -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
+            -Wl,--version-script,$$(SO_VERSION_SCRIPT) -o $$@ \
+            $$(filter %.o,$$?)
+endef
+
 define lipo_lib_template
 $(1): $(addsuffix /$(1),$(FAT_ARCHS))
        $(if $(quiet),@echo "    [LIPO] $$@")
@@ -283,6 +297,7 @@ LIBS=$(call enabled,LIBS)
 .libs: $(LIBS)
        @touch $@
 $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
+$(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
 
 INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
 ifeq ($(MAKECMDGOALS),dist)
index d7d041c..f2b42be 100755 (executable)
--- a/configure
+++ b/configure
@@ -39,6 +39,7 @@ Advanced options:
   ${toggle_spatial_resampling}    spatial sampling (scaling) support
   ${toggle_realtime_only}         enable this option while building for real-time encoding
   ${toggle_runtime_cpu_detect}    runtime cpu detection
+  ${toggle_shared}                shared library support
 
 Codecs:
   Codecs can be selectively enabled or disabled individually, or by family:
@@ -242,6 +243,7 @@ CONFIG_LIST="
     static_msvcrt
     spatial_resampling
     realtime_only
+    shared
 "
 CMDLINE_SELECT="
     extra_warnings
@@ -280,6 +282,7 @@ CMDLINE_SELECT="
     mem_tracker
     spatial_resampling
     realtime_only
+    shared
 "
 
 process_cmdline() {
@@ -369,6 +372,12 @@ process_targets() {
     if [ -f "${source_path}/build/make/version.sh" ]; then
         local ver=`"$source_path/build/make/version.sh" --bare $source_path`
         DIST_DIR="${DIST_DIR}-${ver}"
+        ver=${ver%%-*}
+        VERSION_PATCH=${ver##*.}
+        ver=${ver%.*}
+        VERSION_MINOR=${ver##*.}
+        ver=${ver#v}
+        VERSION_MAJOR=${ver%.*}
     fi
     enabled child || cat <<EOF >> config.mk
 ifeq (\$(MAKECMDGOALS),dist)
@@ -377,6 +386,11 @@ else
 DIST_DIR?=\$(DESTDIR)${prefix}
 endif
 LIBSUBDIR=${libdir##${prefix}/}
+
+VERSION_MAJOR=${VERSION_MAJOR}
+VERSION_MINOR=${VERSION_MINOR}
+VERSION_PATCH=${VERSION_PATCH}
+
 EOF
     enabled child || echo "CONFIGURE_ARGS?=${CONFIGURE_ARGS}" >> config.mk
 
@@ -396,6 +410,12 @@ EOF
 }
 
 process_detect() {
+    if enabled shared; then
+        # Can only build shared libs on a subset of platforms. Doing this check
+        # here rather than at option parse time because the target auto-detect
+        # magic happens after the command line has been parsed.
+       enabled linux || die "--enable-shared only supported on ELF for now"
+    fi
     if [ -z "$CC" ]; then
         echo "Bypassing toolchain for environment detection."
         enable external_build
diff --git a/libs.mk b/libs.mk
index be237a1..c6b08d2 100644 (file)
--- a/libs.mk
+++ b/libs.mk
@@ -92,7 +92,9 @@ CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/x86.h
 CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/x86_abi_support.asm
 endif
 CODEC_SRCS-$(ARCH_ARM) += $(BUILD_PFX)vpx_config.asm
-CODEC_EXPORTS-$(BUILD_LIBVPX) += vpx/exports
+CODEC_EXPORTS-$(BUILD_LIBVPX) += vpx/exports_com
+CODEC_EXPORTS-$(CONFIG_ENCODERS) += vpx/exports_enc
+CODEC_EXPORTS-$(CONFIG_DECODERS) += vpx/exports_dec
 
 INSTALL-LIBS-yes += include/vpx/vpx_codec.h
 INSTALL-LIBS-yes += include/vpx/vpx_image.h
@@ -175,6 +177,31 @@ LIBVPX_OBJS=$(call objs,$(CODEC_SRCS))
 OBJS-$(BUILD_LIBVPX) += $(LIBVPX_OBJS)
 LIBS-$(BUILD_LIBVPX) += $(BUILD_PFX)libvpx.a $(BUILD_PFX)libvpx_g.a
 $(BUILD_PFX)libvpx_g.a: $(LIBVPX_OBJS)
+
+BUILD_LIBVPX_SO         := $(if $(BUILD_LIBVPX),$(CONFIG_SHARED))
+LIBVPX_SO               := libvpx.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
+LIBS-$(BUILD_LIBVPX_SO) += $(BUILD_PFX)$(LIBVPX_SO)
+$(BUILD_PFX)$(LIBVPX_SO): $(LIBVPX_OBJS) libvpx.ver
+$(BUILD_PFX)$(LIBVPX_SO): LDFLAGS += -lm -pthread
+$(BUILD_PFX)$(LIBVPX_SO): SONAME = libvpx.so.$(VERSION_MAJOR)
+$(BUILD_PFX)$(LIBVPX_SO): SO_VERSION_SCRIPT = libvpx.ver
+LIBVPX_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
+                             libvpx.so libvpx.so.$(VERSION_MAJOR) \
+                             libvpx.so.$(VERSION_MAJOR).$(VERSION_MINOR))
+
+libvpx.ver: $(call enabled,CODEC_EXPORTS)
+       @echo "    [CREATE] $@"
+       $(qexec)echo "{ global:" > $@
+       $(qexec)for f in $?; do awk '{print $$2";"}' < $$f >>$@; done
+       $(qexec)echo "local: *; };" >> $@
+CLEAN-OBJS += libvpx.ver
+
+$(addprefix $(DIST_DIR)/,$(LIBVPX_SO_SYMLINKS)):
+       @echo "    [LN]      $@"
+       $(qexec)ln -sf $(LIBVPX_SO) $@
+
+INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBVPX_SO_SYMLINKS)
+INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBSUBDIR)/$(LIBVPX_SO)
 endif
 
 LIBS-$(LIPO_LIBVPX) += libvpx.a
diff --git a/vp8/exports_dec b/vp8/exports_dec
new file mode 100644 (file)
index 0000000..f9b985c
--- /dev/null
@@ -0,0 +1 @@
+data vpx_codec_vp8_dx_algo
diff --git a/vp8/exports_enc b/vp8/exports_enc
new file mode 100644 (file)
index 0000000..9967011
--- /dev/null
@@ -0,0 +1 @@
+data vpx_codec_vp8_cx_algo
index a512ff9..544a3b3 100644 (file)
@@ -10,6 +10,9 @@
 
 
 include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk
+
+VP8_CX_EXPORTS += exports_enc
+
 VP8_CX_SRCS-yes += $(VP8_COMMON_SRCS-yes)
 VP8_CX_SRCS-no  += $(VP8_COMMON_SRCS-no)
 VP8_CX_SRCS_REMOVE-yes += $(VP8_COMMON_SRCS_REMOVE-yes)
index 44b4b49..24f18b7 100644 (file)
@@ -10,6 +10,9 @@
 
 
 include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk
+
+VP8_DX_EXPORTS += exports_dec
+
 VP8_DX_SRCS-yes += $(VP8_COMMON_SRCS-yes)
 VP8_DX_SRCS-no  += $(VP8_COMMON_SRCS-no)
 VP8_DX_SRCS_REMOVE-yes += $(VP8_COMMON_SRCS_REMOVE-yes)
diff --git a/vpx/exports b/vpx/exports
deleted file mode 100644 (file)
index f5e7473..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-text vpx_dec_control
-text vpx_dec_decode
-text vpx_dec_destroy
-text vpx_dec_err_to_string
-text vpx_dec_error
-text vpx_dec_error_detail
-text vpx_dec_get_caps
-text vpx_dec_get_frame
-text vpx_dec_get_mem_map
-text vpx_dec_get_stream_info
-text vpx_dec_iface_name
-text vpx_dec_init_ver
-text vpx_dec_peek_stream_info
-text vpx_dec_register_put_frame_cb
-text vpx_dec_register_put_slice_cb
-text vpx_dec_set_mem_map
-text vpx_dec_xma_init_ver
diff --git a/vpx/exports_com b/vpx/exports_com
new file mode 100644 (file)
index 0000000..2ab0509
--- /dev/null
@@ -0,0 +1,16 @@
+text vpx_codec_build_config
+text vpx_codec_control_
+text vpx_codec_destroy
+text vpx_codec_err_to_string
+text vpx_codec_error
+text vpx_codec_error_detail
+text vpx_codec_get_caps
+text vpx_codec_iface_name
+text vpx_codec_version
+text vpx_codec_version_extra_str
+text vpx_codec_version_str
+text vpx_img_alloc
+text vpx_img_flip
+text vpx_img_free
+text vpx_img_set_rect
+text vpx_img_wrap
diff --git a/vpx/exports_dec b/vpx/exports_dec
new file mode 100644 (file)
index 0000000..ed121f7
--- /dev/null
@@ -0,0 +1,9 @@
+text vpx_codec_dec_init_ver
+text vpx_codec_decode
+text vpx_codec_get_frame
+text vpx_codec_get_mem_map
+text vpx_codec_get_stream_info
+text vpx_codec_peek_stream_info
+text vpx_codec_register_put_frame_cb
+text vpx_codec_register_put_slice_cb
+text vpx_codec_set_mem_map
diff --git a/vpx/exports_enc b/vpx/exports_enc
new file mode 100644 (file)
index 0000000..3d56749
--- /dev/null
@@ -0,0 +1,8 @@
+text vpx_codec_enc_config_default
+text vpx_codec_enc_config_set
+text vpx_codec_enc_init_ver
+text vpx_codec_encode
+text vpx_codec_get_cx_data
+text vpx_codec_get_global_headers
+text vpx_codec_get_preview_frame
+text vpx_codec_set_cx_data_buf