Skip to content

Commit

Permalink
fix: enhance Makefile for improved cross-platform library handling
Browse files Browse the repository at this point in the history
- Updated the TFLITE_LIB_DIR logic to prioritize Homebrew installation on macOS, falling back to the HOME directory if not found.
- Added conditional CGO_LDFLAGS for Darwin to ensure proper linking of TensorFlow Lite libraries.
- Improved the download-tflite target with clearer echo statements for file movements, enhancing user feedback during the build process.

These changes ensure better compatibility and user experience when building on macOS and Linux.
  • Loading branch information
tphakala committed Jan 19, 2025
1 parent 0bb4c3e commit 8889db9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ define get_cgo_flags
$(strip \
CGO_ENABLED=1 \
CGO_CFLAGS="-I$(HOME)/src/tensorflow" \
$(if $(filter darwin%,$1), \
CGO_LDFLAGS="-L$(TFLITE_LIB_DIR)" \
) \
$(if $(filter linux_arm64,$1), \
$(if $(filter x86_64,$(UNAME_M)), \
CC=aarch64-linux-gnu-gcc \
Expand All @@ -69,7 +72,12 @@ ifeq ($(UNAME_S),Linux)
TFLITE_LIB_EXT := .so
else ifeq ($(UNAME_S),Darwin)
NATIVE_TARGET := darwin_$(if $(filter x86_64,$(UNAME_M)),amd64,arm64)
TFLITE_LIB_DIR := /usr/local/lib
# Try Homebrew location first, fall back to HOME directory
ifeq ($(wildcard /opt/homebrew/lib),)
TFLITE_LIB_DIR := $(HOME)/lib
else
TFLITE_LIB_DIR := /opt/homebrew/lib
endif
TFLITE_LIB_EXT := .dylib
else
$(error Build is supported only on Linux and macOS)
Expand Down Expand Up @@ -136,16 +144,19 @@ download-tflite:
sudo mv ./tensorflowlite_c-$(patsubst v%,%,$(TFLITE_VERSION)).dll $(TFLITE_LIB_DIR)/; \
rm -f tensorflowlite_c-$(patsubst v%,%,$(TFLITE_VERSION)).dll; \
else \
echo "Extracting $(TFLITE_C_FILE)..."; \
tar -xzf $(TFLITE_C_FILE) -C .; \
if [ "$(UNAME_S)" = "Darwin" ]; then \
if [ -f "$(TFLITE_LIB_DIR)/libtensorflowlite_c.dylib" ]; then \
sudo mv "$(TFLITE_LIB_DIR)/libtensorflowlite_c.dylib" "$(TFLITE_LIB_DIR)/libtensorflowlite_c.dylib.old"; \
fi; \
echo "Moving libtensorflowlite_c.dylib to $(TFLITE_LIB_DIR)"; \
sudo mv libtensorflowlite_c.dylib $(TFLITE_LIB_DIR)/; \
else \
if [ -f "$(TFLITE_LIB_DIR)/libtensorflowlite_c.so" ]; then \
sudo mv "$(TFLITE_LIB_DIR)/libtensorflowlite_c.so" "$(TFLITE_LIB_DIR)/libtensorflowlite_c.so.old"; \
fi; \
echo "Moving libtensorflowlite_c.so to $(TFLITE_LIB_DIR)"; \
sudo mv libtensorflowlite_c.so.$(patsubst v%,%,$(TFLITE_VERSION)) $(TFLITE_LIB_DIR)/; \
fi; \
fi; \
Expand Down

0 comments on commit 8889db9

Please sign in to comment.