-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (32 loc) · 901 Bytes
/
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
TCC=tcc
CC=gcc
DEBUGGER=gdb
CFLAGS=-lcurl
CCOV=-fprofile-arcs -ftest-coverage
SRC=src
BUILD=build
TEST=tests
BIN=$(BUILD)/openai
OBJS=$(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(SRCS))
SRCS=$(wildcard $(SRC)/*.c)
TESTS=$(wildcard $(TEST)/*.c)
LIBRCS=$(filter-out $(SRC)/main.c, $(SRCS))
INITBUILD=mkdir -p $(BUILD)
COMPILE=$(INITBUILD) && $(TCC) $(CFLAGS)
all: $(BIN) $(BUILD)/libopenai-c.a $(BUILD)/libopenai-c.so
$(BIN): $(OBJS)
$(CC) $^ -o $@ -lcurl
$(OBJS): $(BUILD)/%.o : $(SRC)/%.c
$(INITBUILD) && $(CC) -c $< -o $@ $(CFLAGS) -fPIC
$(BUILD)/libopenai-c.a: $(OBJS)
ar rcs $@ $^
$(BUILD)/libopenai-c.so: $(SRCS)
$(CC) -fPIC -shared $(SRCS) -o $@ $(CFLAGS)
run:
$(COMPILE) $(SRCS) -g -o $(BIN) && ./$(BIN)
test:
$(COMPILE) $(LIBRCS) $(TESTS) -DDEBUG -g -o $(BIN)_test && ./$(BIN)_test
debug:
$(COMPILE) $(SRCS) -g -o $(BIN) && $(DEBUGGER) -q -ex run $(BIN)
clean:
rm -r $(BUILD)