-
Notifications
You must be signed in to change notification settings - Fork 9
/
makefile
68 lines (51 loc) · 1.87 KB
/
makefile
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
# Set emcc as the compiler to use.
CC = emcc
# Set any necessary compiler flags, like optimization flags or features to be enabled.
CFLAGS = -O3
# CFLAGS += -s DISABLE_EXCEPTION_CATCHING=1
CFLAGS += -fwasm-exceptions
CFLAGS += -s ALLOW_MEMORY_GROWTH=1
CFLAGS += -s ALLOW_TABLE_GROWTH=1
CFLAGS += -s WASM=1
CFLAGS += -s MODULARIZE=1
CFLAGS += -s EXPORT_NAME='hnswlib'
CFLAGS += -s ASSERTIONS=1
CFLAGS += -s DEMANGLE_SUPPORT=1
CFLAGS += -s SINGLE_FILE
CFLAGS += --bind
CFLAGS += -s ENVIRONMENT=web
CFLAGS += -gsource-map
CFLAGS += -lidbfs.js
# CFLAGS += --source-map-base=http://localhost:8080/
# Define the source directory, the target directory
SRC_DIR := ./src
LIB_DIR := ./lib
MY_COMMENT := /***************** GENERATED FILE ********************/
# Define the name of the output JavaScript file within the 'lib' directory.
OUTPUT = $(LIB_DIR)/hnswlib
# Define the list of source files that need to be compiled.
SOURCES = ./$(SRC_DIR)/wrapper.cpp
# Set the path to the HNSWLIB header.
HNSWLIB_INCLUDE = ./$(SRC_DIR)/hnswlib
# Add the include path to the compiler flags.
CFLAGS += -I$(HNSWLIB_INCLUDE)
# Create a target called `all` that builds the output file.
all: $(OUTPUT) copy_and_comment
# Define the rule for building the output file, which depends on the source files.
# First, create the output directory if it doesn't exist, then compile and link the source files.
$(OUTPUT): $(SOURCES)
mkdir -p lib
$(CC) $(CFLAGS) $(LDFLAGS) $(SOURCES) -o $(OUTPUT).mjs
# Add a `clean` target to remove generated files from the 'lib' directory.
clean:
rm -f $(OUTPUT).mjs $(OUTPUT).wasm $(OUTPUT).cjs $(OUTPUT).js
.PHONY: all clean
rebuild: clean all
.PHONY: rebuild
copy_and_comment: $(wildcard $(SRC_DIR)/*.ts)
@cp $^ $(LIB_DIR)
@for f in $(LIB_DIR)/*.ts; do \
echo "$(MY_COMMENT)" | cat - $$f > tmpfile && mv tmpfile $$f; \
echo " " >> $$f; \
echo "$(MY_COMMENT)" >> $$f; \
done