-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·328 lines (279 loc) · 8.36 KB
/
install.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
#########################################
# PascalAdt library installation script #
#########################################
# VERSION is the number of the library version with nothing prepended
# or appended
VERSION="1.0.3"
# VERSION_SUFFIX must have a dash ("-") prepended and nothing should be
# appended to the version number
VERSION_SUFFIX="-$VERSION"
DYNAMIC_LIB_STEM=libpascaladt
STATIC_LIB_STEM=libppascaladt
FILE_OVERWRITE=0
DEBUG_FILE_OVERWRITE=0
INSTALL_OPTS=
UNINST_SCRIPT_FILE="uninstall-pascaladt${VERSION_SUFFIX}.sh"
# a .ppu file present in every version; used to check for other versions
CRITICAL_INCLUDE_FILE=adtcont.ppu
CRITICAL_SMART_LIB_FILE=libpadtcont.a
function checked_eval()
{
echo $*
if ! eval $* ; then
echo "install.sh: Error - exiting"
exit 3
fi
}
function check_persent()
{
eval "$1 --version >/dev/null 2>&1"
if [ "$?" != 127 ]; then
return 0;
else
return 1;
fi;
}
function check_dir()
{
if [ ! -d "$1" ]; then
read -n 1 -p "Directory $1 does not exist. Create? (y/n) "
echo
if [ "$REPLY" = n ]; then
echo "Not confirmed - exiting."
exit 1
else
checked_eval mkdir $1
fi
fi
}
function should_overwrite_ppu()
{
eval '[ $'$1'FILE_OVERWRITE == 1 -o \( ! -f ${'$1'INCLUDE_DIR}${CRITICAL_INCLUDE_FILE} \) ]'
}
# processes a directory name in $REPLY; appends a slash if not already present
function process_dirname()
{
REPLY=`eval 'echo -n '$REPLY` # to have path/tidle expansion work
if [ ! "${REPLY:${#REPLY}-1:1}" == '/' ]; then
REPLY=$REPLY/
fi
}
# install_release() installs one of the release versions of the
# library $1 - make target; $2 - the name of the library file(s); $2
# is evaluated only after all the files are created (so that you may
# use wildcards); $3 - any additional options to install (including
# file permissions); $4 - additional options to the compiler;
# $5 - additional options to mcp;
function install_release()
{
checked_eval make fastclean
checked_eval make $1 RELEASE=true OPTS="$4" VER="$VERSION_SUFFIX" MCP_OPTS="$5"
LIB_FILES=`eval "echo -n $2"`
checked_eval install $3 $INSTALL_OPTS $LIB_FILES $LIB_DIR
if [ $MAKE_UNINST_SCRIPT == 1 ]; then
echo "cd ${LIB_DIR}" >> $UNINST_SCRIPT_FILE
echo "rm ${LIB_FILES}" >> $UNINST_SCRIPT_FILE
fi
} # end install_release
echo
echo "PascalAdt $VERSION installation script."
echo
echo "You may pass additional options to the compiler by invoking this"
echo "script like this: install.sh <additional compiler options>"
echo "See the INSTALL file."
echo
if check_persent srcdoc; then
SRCDOC_PRESENT=1
else
SRCDOC_PRESENT=0
fi
read -e -p "Enter the library directory (default /usr/local/lib/): "
if [ $REPLY ]; then
process_dirname
LIB_DIR=$REPLY
else
LIB_DIR="/usr/local/lib/"
fi
read -e -p "Enter the include directory (default /usr/local/include/): "
if [ $REPLY ]; then
process_dirname
INCLUDE_DIR=$REPLY
else
INCLUDE_DIR="/usr/local/include/"
fi
#read -n 1 -p "Make a dynamic library? (y/n) "
#echo
#if [ "$REPLY" != n ]; then
MAKE_DYNAMIC=1
XD="-XD"
#else
# MAKE_DYNAMIC=0
# XD=""
#fi
#read -n 1 -p "Make a smartlinked static library? (n/y) "
#echo
#if [ "$REPLY" == "y" ]; then
# MAKE_SMART=1
#else
MAKE_SMART=0
#fi
#read -n 1 -p "Make a non-smartlinked static library? (n/y) "
#echo
#if [ "$REPLY" == "y" ]; then
# MAKE_STATIC=1
#else
# MAKE_STATIC=0
#fi
read -n 1 -p "Install debug version also? (n/y) "
echo
if [ "$REPLY" == y ]; then
INSTALL_DEBUG=1
else
INSTALL_DEBUG=0
fi
if [ $INSTALL_DEBUG == 1 ]; then
read -e -p "Enter the library directory for the debug version (default ${LIB_DIR}debug/): "
if [ $REPLY ]; then
process_dirname
DEBUG_LIB_DIR=$REPLY
else
DEBUG_LIB_DIR="${LIB_DIR}debug/"
fi
read -e -p "Enter the include directory for the debug version (default ${INCLUDE_DIR}debug/): "
if [ $REPLY ]; then
process_dirname
DEBUG_INCLUDE_DIR=$REPLY
else
DEBUG_INCLUDE_DIR="${INCLUDE_DIR}debug/"
fi
fi
MCPOPTS=
read -n 1 -p "Generate template instantiations for Integer? (y/n) "
echo
if [ "$REPLY" == "n" ]; then
MCPOPTS="-dMCP_NO_INTEGER $MCPOPTS"
fi
read -n 1 -p "Generate template instantiations for Pointer? (n/y) "
echo
if [ "$REPLY" == "y" ]; then
MCPOPTS="-dMCP_POINTER $MCPOPTS"
fi
#read -n 1 -p "Generate template instantiations for Cardinal? (n/y) "
#echo
#if [ "$REPLY" == "y" ]; then
# MCPOPTS="-dMCP_CARDINAL $MCPOPTS"
#fi
read -n 1 -p "Generate template instantiations for Real? (n/y) "
echo
if [ "$REPLY" == "y" ]; then
MCPOPTS="-dMCP_REAL $MCPOPTS"
fi
if [ $SRCDOC_PRESENT == 1 ]; then
read -n 1 -p "Make documentation? (y/n) "
echo
if [ "$REPLY" == n ]; then
MAKE_DOCUMENTATION=0
else
MAKE_DOCUMENTATION=1
fi
else
MAKE_DOCUMENTATION=0
fi
read -n 1 -p "Generate uninstallation script? (y/n) "
echo
if [ "$REPLY" == n ]; then
MAKE_UNINST_SCRIPT=0
else
MAKE_UNINST_SCRIPT=1
rm $UNINST_SCRIPT_FILE > /dev/null 2>&1
echo -e "#!/bin/bash\n" > $UNINST_SCRIPT_FILE
fi
echo
# create directories if not already exist
check_dir ${LIB_DIR}
check_dir ${INCLUDE_DIR}
if [ $INSTALL_DEBUG == 1 ]; then
check_dir ${DEBUG_LIB_DIR}
check_dir ${DEBUG_INCLUDE_DIR}
fi
# check for older versions
if [ -f ${INCLUDE_DIR}${CRITICAL_INCLUDE_FILE} ]; then
echo "Another version of PascalAdt found. The binary library files"
echo "will be preserved, but if the .ppu files are overwritten linking "
echo "with the old debug version may no longer be possible."
read -n 1 -p "Overwrite files? (n/y) "
echo
echo
if [ "$REPLY" == "y" ]; then
FILE_OVERWRITE=1
fi
fi
if [ $INSTALL_DEBUG == 1 ]; then
if [ -f ${DEBUG_INCLUDE_DIR}${CRITICAL_INCLUDE_FILE} ]; then
echo "Another debug version of PascalAdt found. The binary library files"
echo "will be preserved, but if the .ppu files are overwritten linking "
echo "with the old debug version may no longer be possible."
read -n 1 -p "Overwrite files? (n/y) "
echo
echo
if [ "$REPLY" == "y" ]; then
DEBUG_FILE_OVERWRITE=1
fi
fi
fi
# compile and install the release version(s)
if [ $MAKE_DYNAMIC == 1 ]; then
install_release dynamic ${DYNAMIC_LIB_STEM}${VERSION_SUFFIX}.so " " "$*" "\"$MCPOPTS\"";
fi
if [ $MAKE_SMART == 1 ]; then
install_release smart ${STATIC_LIB_STEM}${VERSION_SUFFIX}.a "-m 644" "$*" "\"$MCPOPTS\"";
fi
if [ $MAKE_STATIC == 1 ]; then
install_release static ${STATIC_LIB_STEM}${VERSION_SUFFIX}.a "-m 644" "$*" "\"$MCPOPTS\"";
fi
if should_overwrite_ppu "" ; then
checked_eval install -m 644 $INSTALL_OPTS *.ppu $INCLUDE_DIR
fi
if [ $MAKE_UNINST_SCRIPT == 1 ] && should_overwrite_ppu "" ; then
echo "cd ${INCLUDE_DIR}" >> $UNINST_SCRIPT_FILE
echo rm *.ppu >> $UNINST_SCRIPT_FILE
fi
# compile and install the debug version
if [ $INSTALL_DEBUG == 1 ]; then
DEBUG_LINK_PATH=${DEBUG_LIB_DIR}${DYNAMIC_LIB_STEM}.so
DEBUG_LIB_PATH=${DEBUG_LIB_DIR}${DYNAMIC_LIB_STEM}${VERSION_SUFFIX}.so
checked_eval make fastclean
checked_eval make dynamic DEBUG=true OPTS="$*" VER="$VERSION_SUFFIX" MCP_OPTS="\"$MCPOPTS\""
checked_eval install -m 644 $INSTALL_OPTS ${DYNAMIC_LIB_STEM}${VERSION_SUFFIX}.so ${DEBUG_LIB_DIR}
if should_overwrite_ppu DEBUG_ ; then
checked_eval install -m 664 $INSTALL_OPTS *.ppu ${DEBUG_INCLUDE_DIR}
fi
if [ $MAKE_UNINST_SCRIPT == 1 ]; then
echo "rm ${DEBUG_LIB_PATH}" >> $UNINST_SCRIPT_FILE
if should_overwrite_ppu DEBUG_ ; then
echo "cd ${DEBUG_INCLUDE_DIR}" >> $UNINST_SCRIPT_FILE
echo rm *.ppu >> $UNINST_SCRIPT_FILE
fi
fi
fi
checked_eval make fastclean
# make the documentation
if [ $MAKE_DOCUMENTATION == 1 ]; then
checked_eval "make cleandocs"
checked_eval "make docs VER=${VERSION}"
fi
echo
echo "Installation finished."
if [ $MAKE_UNINST_SCRIPT == 1 ]; then
chmod a+x $UNINST_SCRIPT_FILE
echo
echo "Uninstallation script written to $UNINST_SCRIPT_FILE"
fi
echo
echo "To use the library in your programs invoke fpc with the following"
echo "command line options."
echo
echo "fpc $XD -Fu$INCLUDE_DIR -Fl$INCLUDE_DIR ..."
echo
echo "Documentation is available at https://pascaladt.github.io"