From 7e8c4eeb71643b73053fb8042d5f0b2062dce61c Mon Sep 17 00:00:00 2001 From: Tomi Hakala Date: Sat, 30 Mar 2024 00:03:04 +0200 Subject: [PATCH] build(makefile): update makefile --- Makefile | 55 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 0ca46967..115ef9a7 100644 --- a/Makefile +++ b/Makefile @@ -40,43 +40,40 @@ check-tensorflow: # Download and extract TensorFlow Lite C library download-tflite: - @echo "Downloading TensorFlow Lite C library $(TFLITE_LIB)" - @wget -q https://github.com/tphakala/tflite_c/releases/download/$(TFLITE_VERSION)/$(TFLITE_LIB) -P ./ - @mkdir -p tflite_c - @if [ $(suffix $(TFLITE_LIB)) = .zip ]; then \ - unzip -o $(TFLITE_LIB) -d tflite_c; \ + @if [ ! -f "/usr/lib/libtensorflowlite_c.so" ]; then \ + echo "TensorFlow Lite C library not found. Downloading..."; \ + wget -q https://github.com/tphakala/tflite_c/releases/download/$(TFLITE_VERSION)/$(TFLITE_LIB) -P ./; \ + if [ $$(suffix $(TFLITE_LIB)) = .zip ]; then \ + unzip -o $(TFLITE_LIB) -d .; \ + else \ + tar -xzf $(TFLITE_LIB) -C .; \ + fi; \ + rm -f $(TFLITE_LIB); \ + install-tflite; \ else \ - tar -xzf $(TFLITE_LIB) -C tflite_c; \ + echo "TensorFlow Lite C library already exists."; \ fi # Install TensorFlow Lite C library install-tflite: - @sudo cp tflite_c/libtensorflowlite_c.so $(INSTALL_PATH) + @sudo cp libtensorflowlite_c.so $(INSTALL_PATH) @sudo ldconfig -# Install TensorFlow Lite C library -install-tflite-windows: - @sudo cp tflite_c/libtensorflowlite_c.dll $(INSTALL_PATH) - # labels.zip depends on all files in the labels directory $(LABELS_ZIP): $(LABELS_FILES) @echo "Creating or updating labels.zip from contents of internal/birdnet/labels/*" @cd internal/birdnet/labels && zip -j $(CURDIR)/$(LABELS_ZIP) * # Build for Linux amd64 -linux_amd64: GOOS=linux -linux_amd64: GOARCH=amd64 linux_amd64: INSTALL_PATH=/usr/lib -linux_amd64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_$(GOOS)_$(GOARCH).tar.gz -linux_amd64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite +linux_amd64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_linux_amd64.tar.gz +linux_amd64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite GOOS=linux GOARCH=amd64 $(CGO_FLAGS) go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) # Build for Linux arm64, with cross-compilation setup if on amd64 -linux_arm64: GOOS=linux -linux_arm64: GOARCH=arm64 linux_arm64: INSTALL_PATH=/usr/lib -linux_arm64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_$(GOOS)_$(GOARCH).tar.gz -linux_arm64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite +linux_arm64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_linux_arm64.tar.gz +linux_arm64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite ifeq ($(UNAME_M),x86_64) @# Cross-compilation setup for amd64 to arm64 CC=aarch64-linux-gnu-gcc $(CGO_FLAGS) GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) @@ -86,25 +83,19 @@ else endif # Windows build -windows: GOOS=windows -windows: GOARCH=amd64 -windows: INSTALL_PATH=/usr/lib -windows: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_$(GOOS)_$(GOARCH).zip -windows: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite-windows +windows_amd64: INSTALL_PATH=/usr/lib +windows_amd64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_windows_amd64.zip +windows_amd64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite $(CGO_FLAGS) CC=x86_64-w64-mingw32-gcc go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME).exe # macOS Intel build -macos_intel: GOOS=darwin -macos_intel: GOARCH=amd64 -macos_intel: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_$(GOOS)_$(GOARCH).tar.gz -macos_intel: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite +darwin_amd64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_darwin_amd64.tar.gz +darwin_amd64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite $(CGO_FLAGS) go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) # macOS ARM build -macos_arm: GOOS=darwin -macos_arm: GOARCH=arm64 -macos_arm: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_$(GOOS)_$(GOARCH).tar.gz -macos_arm: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite build +darwin_arm64: TFLITE_LIB=tflite_c_$(TFLITE_VERSION)_darwin_arm64.tar.gz +darwin_arm64: $(LABELS_ZIP) check-tools check-tensorflow download-tflite install-tflite build $(CGO_FLAGS) go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) clean: