forked from PierreSenellart/matrix_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (47 loc) · 1.37 KB
/
Makefile
File metadata and controls
61 lines (47 loc) · 1.37 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
# All main files to compile
TARGET=main_matrix main_matrix_static test_matrix
# Main target: compile everything in $(TARGET)
all: $(TARGET)
# Compiler used
CC=clang
# Compiler and linker flags
CFLAGS=-Wall -Wextra -pedantic -std=c11 -fPIC $(DEPFLAGS)
LDFLAGS=-L.
LDLIBS=-lmatrix
# Adapt CFLAGS depending on DEBUG Make variable
ifndef DEBUG
CFLAGS += -O2
else
CFLAGS += -Og -g
endif
# Dynamic library production
libmatrix.so: matrix.o
$(CC) -shared -fPIC -o $@ $^
# Static library production
libmatrix.a: matrix.o
ar r $@ $^
# Rule to produce main_matrix_static (as a static executable)
main_matrix_static: main_matrix.o libmatrix.a
$(CC) $(LDFLAGS) -static -o $@ $< $(LDLIBS)
# Rule to produce test_matrix (as a static executable)
test_matrix: test_matrix.o libmatrix.a
$(CC) $(LDFLAGS) -static -o $@ $< $(LDLIBS)
# main_matrix depends on libmatrix.so, the built-in Make rule will do the
# rest
main_matrix: libmatrix.so
# Remove all generated files except targets
clean:
-rm -f *.o *.gch *.d *.a *.so
# Remove targets as well as other generated files
fclean: clean
-rm $(TARGET)
# Run unit tests
test: test_matrix
./test_matrix
# clean, fclean and test have rules but do not produce real files
.PHONY: clean fclean test
# Automatic generation of dependencies .d files
DEPFLAGS=-MMD -MP -MF $*.d
SRCS:=$(wildcard *.c)
DEPFILES:=$(SRCS:%.c=%.d)
include $(wildcard $(DEPFILES))