-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·217 lines (209 loc) · 6.13 KB
/
build.sh
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env bash
# This file is part of DSQLite.
#
# Foobar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
function fail(){
local position=$1
echo "Build fail during: ${position}"
exit 1
}
function usage(){
cat << EOF
usage: $0 options
This script install LDC, phobos2 library and druntime library over a machine.
OPTIONS:
-h Show this message
-v Verbose could be use twice time as -v -v for increase verbosity
-q No verbosity
-f Add flag to DFLAGS
-s Build static lib instead shared lib
-c Set compiler default ldc2
-l Set lib dir default lib
-p Set prefix default /usr/local
EOF
}
PROJECTNAME="DSQLite"
DC=ldc2
COMPILER="ldc2"
VERBOSE=0
SHARED_LIB=1
PREFIX="/usr/local"
LIBDIR="lib"
DESTDIR="../install"
LIBDIR_PATH=""
DFLAGS="-w -g -op -c -od../build"
while getopts “hvqscf:l:p:” OPTION
do
case $OPTION in
c)
DC=$OPTARG
;;
h)
usage
exit 1
;;
f)
DFLAGS="${DFLAGS} $OPTARG"
;;
l)
LIBDIR=$OPTARG
;;
p)
PREFIX=$OPTARG
;;
q)
VERBOSE=0
;;
s)
SHARED_LIB=0
;;
v)
let VERBOSE++
;;
?)
usage
exit 1
;;
esac
done
LIBDIR_PATH="${DESTDIR}/${PREFIX}/${LIBDIR}"
DOCDIR_PATH="${DESTDIR}/${PREFIX}/share/doc/DSQLite"
INCLUDEDIR="${DESTDIR}/${PREFIX}/include/d/DSQLite"
DFLAGS="${DFLAGS} -Dd${DOCDIR_PATH} -Hd${INCLUDEDIR}"
if [[ $VERBOSE -ge 1 ]]; then
echo -e "\033[31mEntering is source directory\033[0;0m"
fi
cd src
#############################################################
if [[ $VERBOSE -ge 1 ]]; then
echo -e "\033[31mSet DFLAGS\033[0;0m"
fi
case ${DC} in
ldc | ldc2)
COMPILER="ldc"
DFLAGS="${DFLAGS} --output-o"
if [[ $SHARED_LIB -eq 1 ]]; then
DFLAGS="${DFLAGS} --output-bc -relocation-model=pic"
fi
;;
gdmd | gdc)
COMPILER="gdc"
DC="gdmd"
;;
dmd)
COMPILER="dmd"
if [[ $SHARED_LIB -eq 1 ]]; then
#DFLAGS="${DFLAGS} -fPIC"
echo "Currently dmd do not support shared lib!"
echo "Only ldc support it. So use ldc or use flag -s"
usage
exit 1
fi
;;
?)
echo "Unknow compiler: ${DC}"
echo "Supported compiler ldc, ldc2, gdc, dmd"
;;
esac
#############################################################
if [[ $VERBOSE -ge 1 ]]; then
echo -e "\033[31mCompile ...\033[0;0m"
fi
if [[ $VERBOSE -ge 2 ]]; then
echo -e "\033[33m${DC} ${DFLAGS} *.d\033[0;0m"
fi
${DC} ${DFLAGS} $(find . -name "*.d")
if [[ $? -ge 1 ]]; then
fail "Build"
fi
#############################################################
if [[ $VERBOSE -ge 1 ]]; then
echo -e "\033[31mEntering is build directory\033[0;0m"
fi
cd ../build
#############################################################
if [[ $VERBOSE -ge 1 ]]; then
echo -e "\033[31mLinking ...\033[0;0m"
fi
if [ ! -e "${LIBDIR_PATH}" ]; then
mkdir -p ${LIBDIR_PATH}
fi
if [[ $? -ge 1 ]]; then
fail "mkdir ${LIBDIR_PATH}"
fi
case ${DC} in
ldc | ldc2)
if [[ $SHARED_LIB -eq 1 ]]; then
if [[ $VERBOSE -ge 2 ]]; then
echo -e "\033[33mllvm-ld -link-as-library -o libDSQLite.bc -lm -ldl -lrt -soname=DSQLite *.bc\033[0;0m"
fi
llvm-ld -link-as-library -o libDSQLite.bc -lm -ldl -lrt -soname=DSQLite $(find . -name "*.bc")
if [[ $? -ge 1 ]]; then
fail "llvm-ld"
fi
if [[ $VERBOSE -ge 2 ]]; then
echo -e "\033[33mllc -relocation-model=pic libDSQLite.bc\033[0;0m"
fi
llc -relocation-model=pic libDSQLite.bc
if [[ $? -ge 1 ]]; then
fail "llc"
fi
if [[ $VERBOSE -ge 2 ]]; then
echo -e "\033[33mgcc -shared libDSQLite.s -o ${LIBDIR_PATH}/libDSQLite-${COMPILER}.so\033[0;0m"
fi
gcc -shared -Wl,-soname,libDSQLite-${COMPILER}.so libDSQLite.s -o ${LIBDIR_PATH}/libDSQLite-${COMPILER}.so
if [[ $? -ge 1 ]]; then
fail "gcc"
fi
if [ -e libDSQLite.bc ]; then
rm *.bc
fi
if [[ $? -ge 1 ]]; then
fail "rm *.bc"
fi
else
if [[ $VERBOSE -ge 2 ]]; then
echo -e "ar rcs ${LIBDIR_PATH}/libDSQLite-${COMPILER}.a *.o"
fi
ar rcs ${LIBDIR_PATH}/libDSQLite-${COMPILER}.a $(find . -name "*.o")
if [[ $? -ge 1 ]]; then
fail "ar"
fi
if [[ $VERBOSE -ge 2 ]]; then
echo -e "{LIBDIR_PATH}/libDSQLite-${COMPILER}.a"
fi
ranlib ${LIBDIR_PATH}/libDSQLite-${COMPILER}.a
if [[ $? -ge 1 ]]; then
fail "ranlib"
fi
fi
;;
gdmd | dmd)
if [[ $SHARED_LIB -eq 1 ]]; then
echo "not supported"
else
if [[ $VERBOSE -ge 2 ]]; then
echo -e "${DC} -link *.o -of ${LIBDIR_PATH}/libDSQLite-${COMPILER}.a"
fi
${DC} -link $(find . -name "*.o") -of ${LIBDIR_PATH}/libDSQLite-${COMPILER}.a
if [[ $? -ge 1 ]]; then
fail "${DC} -link"
fi
fi
;;
?)
echo "Unknow compiler: ${DC}"
echo "Supported compiler ldc, ldc2, gdc, dmd"
;;
esac