-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (57 loc) · 1.64 KB
/
Copy pathMakefile
File metadata and controls
76 lines (57 loc) · 1.64 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
CC := gcc
AR := ar
CFLAGS := -g -fno-omit-frame-pointer -Wall -Wextra -Iinclude -Isrc/arch/x86_64
# Build dir
BUILD := build
OBJ_DIR := $(BUILD)/obj
BIN_DIR := $(BUILD)/bin
TARGET := $(BUILD)/libtachyon.a
# Sources
SRC_C := $(shell find src/ -name "*.c")
SRC_ASM := $(shell find src/arch/x86_64 -name "*.S")
# Mirror the src/ tree under build/obj/
# e.g. src/arch/x86_64/context.S -> build/obj/src/arch/x86_64/context.o
OBJ_C := $(patsubst %,$(OBJ_DIR)/%.o,$(SRC_C))
OBJ_ASM := $(patsubst %,$(OBJ_DIR)/%.o,$(SRC_ASM))
OBJECTS := $(OBJ_C) $(OBJ_ASM)
# Default
.PHONY: all bench clean
all: $(TARGET)
# Static library
$(TARGET): $(OBJECTS) | $(BUILD)
$(AR) rcs $@ $^
# Compile C — create parent dir first
$(OBJ_DIR)/%.c.o: %.c | $(OBJ_DIR)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Compile ASM
$(OBJ_DIR)/%.S.o: %.S | $(OBJ_DIR)
@mkdir -p $(dir $@)
$(CC) -c $< -o $@
# Dir rules
$(BUILD):
@mkdir -p $(BUILD)
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
$(BIN_DIR):
@mkdir -p $(BIN_DIR)
# Benchmark
BENCH_SRC := benchmarks/ctx_switch_bench.c
BENCH_BIN := $(BIN_DIR)/ctx_switch_bench
bench: $(TARGET) | $(BIN_DIR)
$(CC) $(CFLAGS) $(BENCH_SRC) -L$(BUILD) -ltachyon -o $(BENCH_BIN)
taskset -c 0 $(BENCH_BIN)
# Tests
TEST_SRCS := $(shell find test/ -name "*.test.c")
TEST_BINS := $(patsubst test/%.test.c,$(BIN_DIR)/%,$(TEST_SRCS))
test: $(TEST_BINS)
@for t in $(TEST_BINS); do \
echo "running $$t"; \
$$t; \
done
$(BIN_DIR)/%: test/%.test.c $(TARGET) | $(BIN_DIR)
$(CC) $(CFLAGS) $< -L$(BUILD) -ltachyon -o $@
# Clean
# Just nuke build/ — source tree stays untouched
clean:
rm -rf $(BUILD)