forked from rkowalewski/nasty-MPI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
93 lines (74 loc) · 2.32 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
include Makefile.DEF
CFLAGS=-std=c11 $(OPTFLAGS) -Isrc -Wextra -Wall
LIBS=$(OPTLIBS)
PREFIX?=/usr/local
SOURCES=$(wildcard src/**/*.c src/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
TEST_SRC=$(wildcard tests/**/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))
SAMPLES_SRC=$(wildcard samples/**/*.c)
SAMPLES=$(patsubst samples/%.c,bin/%,$(SAMPLES_SRC))
LIB_VERSION=$(MAJOR).$(MINOR)
TARGET=build/lib$(LIB_NAME).a
SO_TARGET=build/lib$(LIB_NAME).so.$(LIB_VERSION)
# The Target Build
release: CFLAGS += -DNDEBUG -O3
release: $(TARGET) $(SO_TARGET)
cd lib; \
ln -fs ../$(SO_TARGET) lib$(LIB_NAME).so.$(MAJOR); \
ln -fs lib$(LIB_NAME).so.$(MAJOR) lib$(LIB_NAME).so \
debug: CFLAGS += -ggdb -pedantic
debug: $(TARGET) $(SO_TARGET)
cd lib; \
ln -fs ../$(SO_TARGET) lib$(LIB_NAME).so.$(MAJOR); \
ln -fs lib$(LIB_NAME).so.$(MAJOR) lib$(LIB_NAME).so \
lib/lib$(LIB_NAME).so: $(SO_TARGET)
cd lib; \
ln -fs ../$(SO_TARGET) lib$(LIB_NAME).so.$(MAJOR); \
ln -fs lib$(LIB_NAME).so.$(MAJOR) lib$(LIB_NAME).so \
$(SO_TARGET): BUILD_DYNAMIC=1
$(SO_TARGET): $(TARGET) $(OBJECTS)
$(CC) -shared -Wl,-soname,lib$(LIB_NAME).so.$(MAJOR) $(OBJECTS) -o $@ -lc
$(TARGET): CFLAGS += -fPIC
$(TARGET): build $(OBJECTS)
ar rcs $@ $(OBJECTS)
ranlib $@
build:
@mkdir -p build
@mkdir -p bin
@mkdir -p lib
# The Unit Tests
.PHONY: tests
tests: LDLIBS = -l$(LIB_NAME)
tests: LDFLAGS = -Wl,-rpath,./lib/ -L./lib/
tests: CFLAGS += -g -Wall -Wextra -Werror
tests: lib $(TESTS)
sh ./tests/basic_tests.sh
samples: CFLAGS+=-ggdb
samples: $(SAMPLES)
$(SAMPLES): bin/% : samples/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ samples/testbench.c $<
# The Cleaner
clean:
rm -rf build $(OBJECTS) $(TESTS)
rm -f tests/tests.log
find . -name "*.gc*" -exec rm {} \;
rm -rf `find . -name "*.dSYM" -print`
rm -rf $(SAMPLES)
rm -f samples/tests.log
rm -rf bin/*
# The Install
install: lib
install -d $(DESTDIR)/$(PREFIX)/lib/
install $(TARGET) $(DESTDIR)/$(PREFIX)/lib/
install $(SO_TARGET) $(DESTDIR)/$(PREFIX)/lib/
ldconfig -n $(DESTDIR)/$(PREFIX)/lib/
cd $(DESTDIR)/$(PREFIX)/lib/; \
ln -fs lib$(LIB_NAME).so.$(MAJOR) lib$(LIB_NAME).so
# The Install
uninstall:
$(RM) $(DESTDIR)/$(PREFIX)/lib/$(notdir $(TARGET))
$(RM) $(DESTDIR)/$(PREFIX)/lib/$(notdir $(SO_TARGET))
$(RM) $(DESTDIR)/$(PREFIX)/lib/lib$(LIB_NAME).so.$(MAJOR)
$(RM) $(DESTDIR)/$(PREFIX)/lib/lib$(LIB_NAME).so