Skip to content

Commit

Permalink
Merge pull request #2951 from mozilla/hack-mac-sox-static
Browse files Browse the repository at this point in the history
Ugly, very ugly, incredibly ugly static linking of libsox on macOS
  • Loading branch information
reuben authored Apr 29, 2020
2 parents d120c40 + ea7475d commit 09b756a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions native_client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ default: $(DEEPSPEECH_BIN)
clean:
rm -f deepspeech

$(DEEPSPEECH_BIN): client.cc
$(DEEPSPEECH_BIN): client.cc Makefile
$(CXX) $(CFLAGS) $(CFLAGS_DEEPSPEECH) $(SOX_CFLAGS) client.cc $(LDFLAGS) $(SOX_LDFLAGS)
ifeq ($(OS),Darwin)
install_name_tool -change $$TASKCLUSTER_TASK_DIR/homebrew-builds/opt/sox/lib/libsox.3.dylib @rpath/libsox.3.dylib deepspeech
install_name_tool -change bazel-out/local-opt/bin/native_client/libdeepspeech.so @rpath/libdeepspeech.so deepspeech
endif

Expand Down
12 changes: 9 additions & 3 deletions native_client/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ TOOL_LD := ld
TOOL_LDD := ldd
TOOL_LIBEXE :=

OS := $(shell uname -s)

ifeq ($(findstring _NT,$(OS)),_NT)
PLATFORM_EXE_SUFFIX := .exe
endif
Expand All @@ -30,7 +32,13 @@ SOX_CFLAGS := `pkg-config --cflags sox`
ifeq ($(OS),Linux)
SOX_CFLAGS += -fopenmp
SOX_LDFLAGS := -Wl,-Bstatic `pkg-config --static --libs sox` -lgsm `pkg-config --static --libs libpng | cut -d' ' -f1` -lz -lmagic -lltdl -Wl,-Bdynamic -ldl
else # OS == Linux
else ifeq ($(OS),Darwin)
LIBSOX_PATH := $(shell echo `pkg-config --libs-only-L sox | sed -e 's/^-L//'`/lib`pkg-config --libs-only-l sox | sed -e 's/^-l//'`.dylib)
LIBOPUSFILE_PATH := $(shell echo `pkg-config --libs-only-L opusfile | sed -e 's/^-L//'`/lib`pkg-config --libs-only-l opusfile | sed -e 's/^-l//'`.dylib)
LIBSOX_STATIC_DEPS := $(shell echo `otool -L $(LIBSOX_PATH) | tail -n +2 | cut -d' ' -f1 | grep /opt/ | sed -E "s/\.[[:digit:]]+\.dylib/\.a/" | tr '\n' ' '`)
LIBOPUSFILE_STATIC_DEPS := $(shell echo `otool -L $(LIBOPUSFILE_PATH) | tail -n +2 | cut -d' ' -f1 | grep /opt/ | sed -E "s/\.[[:digit:]]+\.dylib/\.a/" | tr '\n' ' '`)
SOX_LDFLAGS := $(LIBSOX_STATIC_DEPS) $(LIBOPUSFILE_STATIC_DEPS) -framework CoreAudio -lz
else
SOX_LDFLAGS := `pkg-config --libs sox`
endif # OS others
PYTHON_PACKAGES := numpy${NUMPY_BUILD_VERSION}
Expand Down Expand Up @@ -93,8 +101,6 @@ NODE_PLATFORM_TARGET := --target_arch=arm64 --target_platform=linux
TOOLCHAIN_LDD_OPTS := --root $(RASPBIAN)/
endif # ($(TARGET),rpi3-armv8)

OS := $(shell uname -s)

# -Wl,--no-as-needed is required to force linker not to evict libs it thinks we
# dont need ; will fail the build on OSX because that option does not exists
ifeq ($(OS),Linux)
Expand Down

0 comments on commit 09b756a

Please sign in to comment.