-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (122 loc) · 5.51 KB
/
Makefile
File metadata and controls
142 lines (122 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Configurable variables
TENSORFLOW_REPO = https://github.com/tensorflow/tensorflow.git
TENSORFLOW_VERSION = v2.19.0
KISSFFT_VERSION = febd4caeed32e33ad8b2e0bb5ea77542c40f18ec
KISSFFT_REPO = https://github.com/mborgerding/kissfft.git
INSTALL_PREFIX = /usr/local
BUILD_DIR = build
EXTRAS_DIR = extras
# Tools
WGET = wget
GIT = git
MKDIR = mkdir -p
CP = cp -r
RM = rm -rf
BAZEL = bazel
# Output files to check if build is already done
TF_LITE_LIB = $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so
MICROFRONTEND_LIB = $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/experimental/microfrontend/lib/libmicrofrontend.so
# TensorFlow headers
TF_HEADERS_DIR = $(BUILD_DIR)/tensorflow/tensorflow
MICROFRONTEND_HEADERS_DIR = $(BUILD_DIR)/tensorflow/tensorflow/lite/experimental/microfrontend
.PHONY: all clean install install_shared install_headers download build check_build
all: download build
# Download dependencies
download: download_tensorflow download_kissfft
download_tensorflow:
@echo "Checking for TensorFlow..."
@if [ ! -d "$(BUILD_DIR)/tensorflow" ]; then \
echo "Cloning TensorFlow $(TENSORFLOW_VERSION)..."; \
$(MKDIR) $(BUILD_DIR); \
cd $(BUILD_DIR) && \
$(GIT) clone --depth 1 -b $(TENSORFLOW_VERSION) $(TENSORFLOW_REPO) tensorflow; \
else \
echo "TensorFlow already downloaded, skipping..."; \
fi
download_kissfft:
@echo "Checking for KissFFT..."
@if [ ! -d "$(BUILD_DIR)/kissfft" ]; then \
echo "Downloading KissFFT..."; \
cd $(BUILD_DIR) && \
$(GIT) clone $(KISSFFT_REPO) kissfft && \
cd kissfft && \
$(GIT) checkout $(KISSFFT_VERSION); \
else \
echo "KissFFT already downloaded, skipping..."; \
fi
# Check if build is already done
check_build:
@echo "Checking if build is already done..."
@if [ -f "$(TF_LITE_LIB)" ] && [ -f "$(MICROFRONTEND_LIB)" ]; then \
echo "Build already completed, skipping build step."; \
touch $(TF_LITE_LIB) $(MICROFRONTEND_LIB); \
exit 0; \
fi
# Build the library using the existing BUILD file
build: download check_build
@if [ ! -f "$(TF_LITE_LIB)" ] || [ ! -f "$(MICROFRONTEND_LIB)" ]; then \
echo "Building library..."; \
# Copy the BUILD file to TensorFlow's microfrontend library directory \
$(MKDIR) $(BUILD_DIR)/tensorflow/tensorflow/lite/experimental/microfrontend/lib; \
$(CP) $(EXTRAS_DIR)/BUILD $(BUILD_DIR)/tensorflow/tensorflow/lite/experimental/microfrontend/lib/; \
# Build the library using TensorFlow's Bazel \
cd $(BUILD_DIR)/tensorflow && \
$(BAZEL) build //tensorflow/lite/experimental/microfrontend/lib:microfrontend && \
$(BAZEL) build //tensorflow/lite/c:tensorflowlite_c; \
fi
install: build
@echo "Installing shared library..."
$(MKDIR) $(INSTALL_PREFIX)/lib
$(CP) $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so $(INSTALL_PREFIX)/lib/
$(CP) $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/experimental/microfrontend/lib/libmicrofrontend.so $(INSTALL_PREFIX)/lib/
@echo "Shared library installation complete to $(INSTALL_PREFIX)/lib"
install_shared: build
@echo "Installing shared library..."
$(MKDIR) $(INSTALL_PREFIX)/lib
$(CP) $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so $(INSTALL_PREFIX)/lib/
$(CP) $(BUILD_DIR)/tensorflow/bazel-bin/tensorflow/lite/experimental/microfrontend/lib/libmicrofrontend.so $(INSTALL_PREFIX)/lib/
@echo "Shared library installation complete to $(INSTALL_PREFIX)/lib"
# Install header files
install_headers: build
@echo "Installing header files..."
# Create include directories
$(MKDIR) $(INSTALL_PREFIX)/include/tensorflow/compiler/mlir/lite/core/c
$(MKDIR) $(INSTALL_PREFIX)/include/tensorflow/lite/c
$(MKDIR) $(INSTALL_PREFIX)/include/tensorflow/lite/core/c
$(MKDIR) $(INSTALL_PREFIX)/include/tensorflow/lite/core/async/c
$(MKDIR) $(INSTALL_PREFIX)/include/tensorflow/lite/experimental/microfrontend
# Install TensorFlow Lite C API headers
$(CP) -R $(TF_HEADERS_DIR)/compiler/mlir/lite/core/c/*.h $(INSTALL_PREFIX)/include/tensorflow/compiler/mlir/lite/core/c
$(CP) -R $(TF_HEADERS_DIR)/lite/core/c/*.h $(INSTALL_PREFIX)/include/tensorflow/lite/core/c
$(CP) -R $(TF_HEADERS_DIR)/lite/core/async/c/*.h $(INSTALL_PREFIX)/include/tensorflow/lite/core/async/c
$(CP) -R $(TF_HEADERS_DIR)/lite/c/*.h $(INSTALL_PREFIX)/include/tensorflow/lite/c
# Install Microfrontend headers (recursively for all subdirectories)
$(CP) $(MICROFRONTEND_HEADERS_DIR) $(INSTALL_PREFIX)/include/tensorflow/lite/experimental/
# Install KissFFT headers if they're needed
$(MKDIR) $(INSTALL_PREFIX)/include/kissfft
$(CP) $(BUILD_DIR)/kissfft/*.h $(INSTALL_PREFIX)/include/kissfft/
@echo "Header files installation complete to $(INSTALL_PREFIX)/include"
# Clean up
clean:
$(RM) $(BUILD_DIR)
@echo "Clean complete"
# Show help
help:
@echo "Makefile for building audio feature vectors library"
@echo ""
@echo "Targets:"
@echo " all - Download dependencies, build and install the library (default)"
@echo " download - Download TensorFlow and KissFFT"
@echo " build - Build the library (skips if already built)"
@echo " install - Install the library to $(INSTALL_PREFIX)"
@echo " clean - Remove build directory"
@echo ""
@echo "Configuration:"
@echo " TENSORFLOW_REPO = $(TENSORFLOW_REPO)"
@echo " KISSFFT_VERSION = $(KISSFFT_VERSION)"
@echo " INSTALL_PREFIX = $(INSTALL_PREFIX)"
@echo ""
@echo "Example usage:"
@echo " make # Build and install with default settings"
@echo " make INSTALL_PREFIX=/opt # Install to /opt instead of /usr/local"
@echo " sudo make install # Install the shared (.so) library"