This repository has been archived by the owner on Sep 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
68 lines (48 loc) · 1.56 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
PROJECT = crap
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_PATCH = 0
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
CFLAGS = -Wall -Wextra -Werror -std=c99 -O2 -Isrc
LDFLAGS =
BUILD_DIR = build
SRC_DIR = src
SOURCES = $(wildcard $(SRC_DIR)/**/*.c $(SRC_DIR)/*.c)
OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SOURCES))
TARGET = $(BUILD_DIR)/lib$(PROJECT).a
TARGET_SO = $(patsubst %.a, %.so, $(TARGET))
TESTS_DIR = tests
TESTS_SRC = $(wildcard $(TESTS_DIR)/*_test.c)
TESTS = $(patsubst %.c, %, $(TESTS_SRC))
# --- Build ---
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | builddir
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
$(TARGET_SO): $(OBJECTS) | builddir
$(CC) $(CFLAGS) -shared -o $@ $(OBJECTS)
@ln -srf $(TARGET_SO) $(TARGET_SO).$(VERSION_MAJOR)
@ln -srf $(TARGET_SO) $(TARGET_SO).$(VERSION_MAJOR).$(VERSION_MINOR)
@ln -srf $(TARGET_SO) $(TARGET_SO).$(VERSION)
# r: replace existing or inset new files into archive
# c: no warning if library had to be created
# s: create an archive index
# v: verbose output
$(TARGET): $(OBJECTS) | builddir
ar rcsv $@ $^
.PHONY: builddir clean tests doc
all: shared
shared: $(TARGET_SO)
static: $(TARGET)
builddir:
@mkdir -pv $(BUILD_DIR)/objects
clean:
@rm -vrf $(BUILD_DIR) $(TESTS) $(patsubst tests/%, tests/valgrind-%.log, $(TESTS)) doc
doc:
@doxygen Doxyfile
# --- Tests ---
test: $(TESTS)
@tests/test_exec.py
test_valgrind: $(TESTS)
@tests/test_exec.py --valgrind
$(TESTS_DIR)/%_test: $(TESTS_DIR)/%_test.c | shared
@echo Working Directory 1: $(PWD)
$(CC) $< -o $@ $(CFLAGS) -Itests -L$(PWD)/build -lcrap