This repository has been archived by the owner on Mar 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
115 lines (95 loc) · 2.78 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# is not easy to make makefiles :(
# it is so ugly...
# always needed reminder:
# rules/targets are of the form
# target: dependency1 dependency2 ... dependencyN
# command_to_execute
# @other_command_to_execute
# if a command starts with @, it doesn't print the command, it just executes it
# $@ is the target's name
# $< is the first dependency
# $^ are all dependencies
# $? are all dependencies that are newer than target
# DEFINITIONS
CSIPDIR = $(realpath .)
CSIPSRCDIR = $(CSIPDIR)/src
CSIPINC = $(CSIPDIR)/include
CSIPLIBDIR = $(CSIPDIR)/lib
CFLAGS = -std=c99 -Wall -pedantic
SCIPSRC = $(CSIPLIBDIR)/include
SCIPLIB = -lscip
FLAGS = -I$(SCIPSRC) -I$(CSIPINC)
LFLAGS = -L$(CSIPLIBDIR)
LINKFLAGS = -Wl,-rpath,$(CSIPLIBDIR)
TESTDIR = $(CSIPDIR)/test
TESTFLAGS = -I$(CSIPINC) -g
TESTLIBS = -lm -lcsip -lscip
LINKTESTFLAGS = $(LINKFLAGS)
LINKTESTFLAGS += -Wl,-rpath,$(CSIPLIBDIR)
LTESTFLAGS = -L$(CSIPLIBDIR)
TESTSRC = $(TESTDIR)/test.c
TESTBIN = $(TESTDIR)/test # don't know where to put the test executable
CSIPHEADER = $(CSIPINC)/csip.h
CSIPSRC = $(CSIPSRCDIR)/csip.c
CSIPOBJ = $(CSIPSRCDIR)/csip.o
CSIPLIB = $(CSIPLIBDIR)/libcsip.so
# RULES
.PHONY: all
all: $(CSIPLIBDIR) $(CSIPLIB)
.PHONY: clean
clean:
@echo "removing $(CSIPOBJ), $(CSIPLIB), $(TESTBIN)"
@rm -f $(CSIPOBJ)
@rm -f $(CSIPLIB)
@rm -f $(TESTBIN)
.PHONY: clean-links
clean-links:
@echo "removing symlinks"
@rm -rf $(CSIPLIBDIR)
.PHONY: test
test:
@make $(TESTBIN)
$(TESTBIN)
.PHONY: links
links:
@echo "Creating symbolic links to headers and library within SCIPOPTDIR ($(SCIPOPTDIR))."
@bash -c 'cd lib; \
if [ -e $(SCIPOPTDIR)/include/scip/scip.h ] ; \
then \
ln -s $(SCIPOPTDIR)/include; \
else \
echo "ERROR: no SCIP headers found in SCIPOPTDIR!" ; \
cd ..; \
rmdir lib; \
exit 1; \
fi ; \
cd ..;\
'
@bash -c 'cd lib; \
if [ -e $(SCIPOPTDIR)/lib/libscip.so ] ; \
then \
ln -s $(SCIPOPTDIR)/lib/libscip* .; \
else \
echo "ERROR: no SCIP library found in SCIPOPTDIR!" ; \
cd ..; \
rmdir lib; \
exit 1; \
fi ; \
cd ..;\
'
$(CSIPLIBDIR):
mkdir -p $@
make links
$(CSIPLIB): $(CSIPSRC)
gcc $(CFLAGS) $(FLAGS) -c $< $(LFLAGS) $(LINKFLAGS) $(SCIPLIB) -fPIC -o $(CSIPOBJ)
gcc $(CFLAGS) $(CSIPOBJ) $(LFLAGS) $(LINKFLAGS) $(SCIPLIB) -fPIC -shared -o $@
$(TESTBIN): $(TESTSRC) $(CSIPLIB)
@echo "compiling test"
gcc $(CFLAGS) $(TESTFLAGS) $< $(LINKTESTFLAGS) $(TESTLIBS) $(LTESTFLAGS) -o $@
ASTYLEOPTS = --style=allman --indent=spaces=4 --indent-cases --pad-oper --pad-header --unpad-paren --align-pointer=name --add-brackets --max-code-length=80
.PHONY: style
style:
@astyle -q $(ASTYLEOPTS) $(CSIPHEADER) $(CSIPSRC) $(TESTSRC)
.PHONY: valgrind
valgrind:
@valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all $(TESTBIN)