-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (43 loc) · 1.74 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
CC := g++ -std=c++17
CFLAGS := -g -Wall -O2
LDFLAGS := -Lbuild -lnablagrad
BUILD_DIR := build
INSTALL_DIR := /usr/include
INSTALL_LIB_DIR := /usr/lib
NABLA_DIR := nablagrad
SRCS := $(NABLA_DIR)/tensor.cpp
# SRCS := $(NABLA_DIR)/dual.cpp $(NABLA_DIR)/tensor.cpp $(NABLA_DIR)/core.cpp $(NABLA_DIR)/forward_ad.cpp $(NABLA_DIR)/gradient_tape.cpp $(NABLA_DIR)/tensor_ops.cpp
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
EXAMPLES_DIR := examples
EXAMPLES := $(EXAMPLES_DIR)/reverse_mode_gradient $(EXAMPLES_DIR)/forward_mode_partial_diff
TESTS_DIR := test
LIBRARY := libnablagrad.a
.PHONY: all build examples install uninstall clean
all: main_test
build: $(BUILD_DIR)/$(LIBRARY)
$(BUILD_DIR)/$(LIBRARY): $(OBJS)
@if [ ! -d "build" ]; then mkdir "build"; fi
ar rcs $@ $^
$(NABLA_DIR)/%.o: $(SRCS)
$(CC) $(CFLAGS) -c $(NABLA_DIR)/$*.cpp -o $(NABLA_DIR)/$*.o
examples: $(EXAMPLES)
$(EXAMPLES_DIR)/%.o: $(EXAMPLES_DIR)/$*.cpp
$(CC) $(CFLAGS) -c $(EXAMPLES_DIR)/$*.cpp -o $(EXAMPLES_DIR)/$*.o
$(EXAMPLES_DIR)/reverse_mode_gradient: $(EXAMPLES_DIR)/reverse_mode_gradient.o
$(CC) -o $@ $^ $(LDFLAGS)
$(EXAMPLES_DIR)/forward_mode_partial_diff: $(EXAMPLES_DIR)/forward_mode_partial_diff.o
$(CC) -o $@ $^ $(LDFLAGS)
main_test: $(NABLA_DIR)/main.o $(OBJS)
$(CC) -o $@ $(NABLA_DIR)/main.o $(OBJS)
test_tensor: $(TESTS_DIR)/test_tensor.o $(OBJS)
$(CC) -o $@ $(TESTS_DIR)/test_tensor.o $(OBJS)
install: build
@cp $(BUILD_DIR)/$(LIBRARY) $(INSTALL_LIB_DIR)/$(LIBRARY)
@cp -r $(NABLA_DIR) $(INSTALL_DIR)
@echo "nablagrad installed to "$(INSTALL_DIR)" and "$(INSTALL_LIB_DIR)""
uninstall:
@rm $(INSTALL_LIB_DIR)/$(LIBRARY)
@rm -r $(INSTALL_DIR)/$(NABLA_DIR)
@echo "nablagrad uninstalled"
clean:
rm -f $(NABLA_DIR)/*.o $(EXAMPLES_DIR)/*.o $(BUILD_DIR)/$(LIBRARY) $(EXAMPLES) main_test