-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·136 lines (114 loc) · 2.59 KB
/
make.sh
File metadata and controls
executable file
·136 lines (114 loc) · 2.59 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
ROOT=$(realpath "$(dirname "$0")")
WORKER=8
error() {
echo "$@" 1>&2
}
fail() {
error "$@"
exit 1
}
find_clang() {
if [ -f "/usr/local/opt/llvm/bin/clang" ]; then
echo "/usr/local/opt/llvm/bin/clang"
elif hash which 2>/dev/null; then
which clang
else
fail "clang not found"
fi
}
find_libtool() {
if hash which 2>/dev/null; then
if hash libtool 2>/dev/null; then
which libtool
else
fail "libtool not found"
fi
fi
}
compile_c++() {
OBJFOLDER="$ROOT/.tmp/obj/$(dirname "$1")"
FILENAME=$(basename "$1")
if [ ! -f "$OBJFOLDER" ]; then
mkdir -p "$OBJFOLDER"
fi
includes=("${!2}")
includeArg=""
if [ ${#includes} -ne 0 ]; then
for i in "${includes[@]}"; do
includeArg+="-I $i "
done
fi
if [ -f "$ROOT/$1" ]; then
if ! eval "$CXX -x c++ $CXXFLAGS -c $ROOT/$1 $includeArg -o $OBJFOLDER/${FILENAME%%.*}.o"; then
fail "$ROOT/$1 compilation error"
fi
else
fail "$ROOT/$1 doesn't exist"
fi
}
libtool_c++() {
srcs=("${!1}")
objects=""
for f in "${srcs[@]}"; do
filename_obj="$ROOT/.tmp/obj/${f%%.*}.o"
if [ ! -f "$filename_obj" ]; then
fail "$filename_obj doesn't exist"
else
objects+="$filename_obj "
fi
done
eval "$LIBTOOL -static -o $ROOT/$2.a $objects"
}
if [ -z "${CXX+x}" ]; then
CXX=$(find_clang)
fi
if [ -z "${LIBTOOL+x}" ]; then
LIBTOOL=$(find_libtool)
fi
if [ -z "${CXXFLAGS+x}" ]; then
#CXXFLAGS="-O0 -g -fno-omit-frame-pointer -std=c++1z -march=native "
CXXFLAGS="-Ofast -std=c++1z -march=native "
CXXFLAGS+="-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++11-compat -Wno-c++11-compat-pedantic -Wno-c++14-compat -Wno-c++14-compat-pedantic -Wno-padded"
fi
build_future() {
FILES=(
"future/debug.cpp"
"future/future.cpp"
"future/memory.cpp"
"future/system_error.cpp"
"future/thread.cpp"
)
N=$WORKER
for f in "${FILES[@]}"; do
((i=i%N)); ((i++==0)) && wait
compile_c++ "$f" &
done
wait
libtool_c++ FILES[@] "libfuture"
}
build() {
build_future
}
clean_future() {
if [ -f "$ROOT/libfuture.a" ]; then
rm -f "$ROOT/libfuture.a"
fi
}
clean() {
if [ -d "$ROOT/.tmp/obj" ]; then
rm -rf "$ROOT/.tmp/obj"
fi
clean_future
}
case "$1" in
build)
build
;;
clean)
clean
;;
*)
echo $"Usage: $0 {build|clean}"
exit 1;
esac