-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakefile
More file actions
71 lines (59 loc) · 1.84 KB
/
makefile
File metadata and controls
71 lines (59 loc) · 1.84 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
# =============================
# Makefile for C² Compiler
# Supports normal and test builds
# =============================
include config.mk
.PHONY: all clean rebuild info directories
# -----------------------------
# Build targets
# -----------------------------
all: directories $(TARGET)
rebuild: clean all
# Normal build
$(TARGET): $(OBJS)
@echo "Linking $(TARGET)"
$(CC) $(CFLAGS) $(OBJS) -o $(BINDIR)/$(TARGET) $(LDFLAGS)
# test build with tests
TEST_TARGET := csq-x86-test
TEST_OBJS := $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%_test.o,$(SRCS))
$(TEST_TARGET): directories $(TEST_OBJS)
@echo "Linking test binary $(BINDIR)/$(TEST_TARGET)"
$(CC) $(CFLAGS) $(TEST_OBJS) -o $(BINDIR)/$(TEST_TARGET) $(LDFLAGS)
# -----------------------------
# Compile source files
# -----------------------------
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
@echo "Compiling $<"
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%_test.o: $(SRCDIR)/%.c
@echo "Compiling test $<"
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -DCSQ_RUN_TESTS -c $< -o $@
# -----------------------------
# Token/Directory management
# -----------------------------
directories:
@mkdir -p $(BUILDDIR) $(BINDIR) $(shell find $(SRCDIR) -type d | sed 's|$(SRCDIR)|$(BUILDDIR)|')
# -----------------------------
# Cleaning
# -----------------------------
clean:
@echo "Cleaning build artifacts"
@rm -rf $(BUILDDIR) $(BINDIR)
# -----------------------------
# test info
# -----------------------------
info:
@echo "C² Build Configuration:"
@echo " Compiler: $(CC)"
@echo " CFLAGS: $(CFLAGS)"
@echo " LDFLAGS: $(LDFLAGS)"
@echo " Source dir: $(SRCDIR)"
@echo " Build dir: $(BUILDDIR)"
@echo " Binary dir: $(BINDIR)"
@echo " Target: $(TARGET)"
@echo " test Target: $(TEST_TARGET)"
@echo " Sources: $(SRCS)"
@echo " Objects: $(OBJS)"
@echo " test Objects: $(TEST_OBJS)"