forked from emmt/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (88 loc) · 2.65 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
115
116
117
118
119
120
.PHONY: clean test-orig test-f2c
#---- Customizations begin here -----------------------------------------------
# Compilers (only the C compiler is needed to build the library):
CC = gcc
FC = gfortran
# Compiler and linker flags:
#STRICT = -ansi -Wpedantic
CFLAGS = ${STRICT} -Wall -O2 -I. -DNDEBUG
FFLAGS = ${CFLAGS}
LDFLAGS =
# Command and flags to build a static library:
AR = ar
ARFLAGS = rv
# Set the following to true/false depending whether your terminal does support
# ANSI colors.
COLOR = true
#---- Customizations end here -------------------------------------------------
srcdir=.
TMPDIR = /tmp
NAME = bobyqa
LIBNAME = lib${NAME}.a
OBJS = ${NAME}.o
SINGLE = -DSINGLE_PRECISION
DOUBLE = -USINGLE_PRECISION
default: library
library: ${LIBNAME}
test: test-code
clean:
rm -f *~ *.o ${LIBNAME} *.diff
rm -f ${NAME}-f2c.c
rm -f ${NAME}-orig ${NAME}-f2c ${NAME}-test
very-clean: clean
rm -f *.out
${LIBNAME}: ${OBJS}
${AR} ${ARFLAGS} $@ $^
${NAME}.o: ${srcdir}/${NAME}.c ${srcdir}/${NAME}.h
${CC} ${CFLAGS} ${DOUBLE} -UTESTING -c $< -o $@
# Rule to produce output of tests (the exponential notation uses a 'D' in
# FORTRAN, an 'E' in C, so we have to filter this).
%.out: %
./$< | sed 's/\([0-9]\)D\([-+]\?[0-9]\)/\1E\2/g' > $@
# ### Original FORTRAN code.
${NAME}-orig: ${srcdir}/${NAME}.f
${FC} ${FFLAGS} $< -o $@ -lm
### Conversion with F2C.
${NAME}-f2c.c: ${srcdir}/${NAME}.f
rm -f ${TMPDIR}/${NAME}.c
f2c -Aas -d${TMPDIR} $<
mv ${TMPDIR}/${NAME}.c $@
${NAME}-f2c: ${srcdir}/${NAME}-f2c.c
${CC} ${CFLAGS} $< -o $@ -lf2c -lm
test-f2c: ${NAME}-f2c.out ${NAME}-orig.out
@if diff $^ >${NAME}-f2c.diff; then \
msg="test of F2C version successful"; \
if ${COLOR}; then \
/bin/echo -e "\e[1;32m$${msg}\e[0;39;49m"; \
else \
echo "$${msg}"; \
fi; \
else \
msg="test of F2C version failed (see file ${NAME}-f2c.diff)"; \
if ${COLOR}; then \
/bin/echo -e "\e[1;31m$${msg}\e[0;39;49m"; \
else \
echo "$${msg}"; \
fi; \
fi
### Conversion and optimizations by hand.
${NAME}-test.o: ${srcdir}/${NAME}.c ${srcdir}/${NAME}.h
${CC} ${CFLAGS} ${DOUBLE} -DTESTING -c $< -o $@
${NAME}-test: ${NAME}-test.o
${CC} ${LDFLAGS} $< -o $@ -lm
test-code: ${NAME}-test.out ${NAME}-orig.out
@if diff $^ >${NAME}-f2c.diff; then \
msg="test of C version successful"; \
if ${COLOR}; then \
/bin/echo -e "\e[1;32m$${msg}\e[0;39;49m"; \
else \
echo "$${msg}"; \
fi; \
else \
msg="test of C version failed (see file ${NAME}-f2c.diff)"; \
if ${COLOR}; then \
/bin/echo -e "\e[1;31m$${msg}\e[0;39;49m"; \
else \
echo "$${msg}"; \
fi; \
fi