-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·575 lines (477 loc) · 14.1 KB
/
configure
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#!/bin/sh
#
# osh - A shell for Oracle
#
# R. Carbone ([email protected])
# 2Q 2019
#
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
#
#
# This script attempts to configure [osh] on your Linux system.
#
# Based on:
# tcsh - C shell with file name completion and command line editing
# OCI - Oracle Call Interface (Instant Client software)
# OCILIB - C Driver for Oracle - by Vincent Rogier <[email protected]>
# rlibc - C library of useful functions
#
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
#
# Addionatal Software requirements:
# git
# wget
# unzip
#
if ! [ -x "$(command -v git)" ]; then
echo 'Error: git is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v wget)" ]; then
echo 'Error: wget is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v unzip)" ]; then
echo 'Error: unzip is not installed.' >&2
exit 1
fi
# =-=-=-=-=-=-=-=-
# The name of the game
PACKAGE=osh
# Main header file
HEADER=osh.h
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-==-==-==-==-==-==-
# All tcsh builtin extensions (please keep them alphabetically sorted)
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-==-==-==-==-==-==-
EXTRACMDS="about"
EXTRACMDS="$EXTRACMDS chc"
EXTRACMDS="$EXTRACMDS connect"
EXTRACMDS="$EXTRACMDS describe"
EXTRACMDS="$EXTRACMDS disconnect"
EXTRACMDS="$EXTRACMDS help"
EXTRACMDS="$EXTRACMDS license"
EXTRACMDS="$EXTRACMDS lsc"
EXTRACMDS="$EXTRACMDS oping"
EXTRACMDS="$EXTRACMDS select"
EXTRACMDS="$EXTRACMDS tables"
EXTRACMDS="$EXTRACMDS version"
EXTRACMDS="$EXTRACMDS when"
# =-=-=-=-=-=-=-=-
# Project directories tree
ROOTDIR=`pwd`
# Level 1
PUBDIR=$ROOTDIR/3rdparty
EXTDIR=$ROOTDIR/src
SHELLDIR=$ROOTDIR/shell
SHELLNAME=`basename $ROOTDIR/shell`
# Level 2
SPOOLDIR=$PUBDIR/Archive
# =-=-=-=-=-=-=-=-
#
# Required git modules
#
TCSHGIT=https://github.com/tcsh-org/tcsh
OCIURL=https://github.com/bumpx/oracle-instantclient/raw/master
OCILIBGIT=https://github.com/vrogier/ocilib
RLIBCGIT=https://github.com/rcarbone/rlibc
# tcsh - C shell with file name completion and command line editing by Christos Zoulas <[email protected]>
TCSHDIR=tcsh
# Oracle - Client Shared Library 32/64-bit - 12.2.0.1.0
ORADIR=$PUBDIR/oracle
ORALIBDIR=$ORADIR/instantclient_12_2
# Oracle Instant Client software
oraver=$ORADIR/instantclient_12_2
if [ `arch` = "x86_64" ]; then
orabase=instantclient-basic-linux.x64-12.2.0.1.0.zip
orasdk=instantclient-sdk-linux.x64-12.2.0.1.0.zip
oralite=instantclient-basiclite-linux.x64-12.2.0.1.0.zip
else
orabase=instantclient-basic-linux-12.2.0.1.0.zip
orasdk=instantclient-sdk-linux-12.2.0.1.0.zip
oralite=instantclient-basiclite-linux-12.2.0.1.0.zip
fi
# variables
oraso=libclntsh.so.12.1
orahome=$oraver
oraheaders=$orahome/sdk/include
oralibs=$orahome
# OCILIB - C Driver for Oracle - by Vincent Rogier <[email protected]>
OCILIBDIR=ocilib
OCILIB=$PUBDIR/$OCILIBDIR/src/.libs/libocilib.a
# rlibc - C library of useful functions by Rocco Carbone <[email protected]>
RLIBCDIR=$PUBDIR/rlibc/src
RLIBC=$RLIBCDIR/librlibc.a
# osh - C library implementing tcsh extensions
PKGLIB=$EXTDIR/libosh.a
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Functions
# tcsh
do_tcsh()
{
cd $PUBDIR
echo "tcsh - C shell with file name completion and command line editing"
if [ ! -d $TCSHDIR ]; then
echo -n " Cloning tcsh ... "
git clone -q $TCSHGIT
echo "done!"
fi
}
# Oracle Instant Client
do_oracle()
{
cd $PUBDIR
echo "Oracle - Instant Client Shared libraries for Linux `arch`"
# Move to the Oracle root directory
if [ ! -d $ORADIR ]; then
mkdir $ORADIR
fi
cd $ORADIR
# Checking for Oracle instantclient zip files
if [ ! -d $SPOOLDIR ]; then
mkdir $SPOOLDIR
cd $SPOOLDIR
echo -n " Downloading Oracle Instant Client. Please wait ... "
wget -q ${OCIURL}/LICENSE
wget -q ${OCIURL}/$orabase
wget -q ${OCIURL}/$orasdk
# wget -q ${OCIURL}/$oralite
echo "done!"
fi
if [ ! -d $oraver ]; then
mkdir $oraver
fi
cd $ORADIR
echo " Unpacking ..."
echo " Basic $orabase ..."
unzip $SPOOLDIR/$orabase > /dev/null
echo " SDK $orasdk ..."
unzip $SPOOLDIR/$orasdk > /dev/null
echo -n " Linking libclntsh.so ... "
(cd $oraver && ln -s $oraso libclntsh.so)
cp $SPOOLDIR/LICENSE $oraver/LICENSE
echo "done!"
}
# OCILIB
do_ocilib()
{
cd $PUBDIR
echo "OCILIB - C Driver for Oracle"
if [ ! -d $OCILIBDIR ]; then
echo -n " Cloning ocilib ... "
git clone -q $OCILIBGIT
echo "done!"
fi
cd $OCILIBDIR
if [ ! -f config.status ]; then
# Fixing annoying aclocal and automake dependencies
if [ ! -x aclocal-1.15 ]; then
ln -s /usr/bin/aclocal aclocal-1.15
fi
if [ ! -x automake-1.15 ]; then
ln -s /usr/bin/automake automake-1.15
fi
echo -n " Configuring ... "
./configure --with-oracle-home=$orahome --with-oracle-headers-path=$oraheaders --with-oracle-lib-path=$orahome CFLAGS='-g -O2 -fPIC' 1> /dev/null 2>&1
echo "done!"
echo -n " Compiling ..... "
make 1> /dev/null 2>&1
echo "done!"
fi
}
# rlibc
do_rlibc()
{
cd $PUBDIR
echo "rlibc - C library of useful functions"
if [ ! -d $RLIBCDIR ]; then
echo -n " Cloning rlibc ... "
git clone -q $RLIBCGIT
echo "done!"
fi
cd $RLIBCDIR
if [ ! -f $RLIBC ]; then
echo -n " Compiling ... "
make 1> /dev/null 2>&1
echo "done!"
fi
}
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Eval max length of commands
maxn()
{
longest=0
for cmd in $EXTRACMDS; do
n=${#cmd}
if [ $longest -lt $n ]; then
longest=$n
fi
done
echo $longest
}
#
# Return the line in the tcsh file [sh.init.c] where a specific command
# *must* be inserted to have the given extension $cmd full funtional.
#
# Warning: order in the array bfunc[] of [biltins] in file [sh.init.c]
# is relevant in order to have the extensions available.
#
linenumber()
{
cmd=`echo $1`
file=`echo $2`
case $cmd in
# Please keep them alphabetically sorted
about) before=alias ;;
chc) before=chdir ;;
connect) after=complete ;;
describe) after=default ;;
disconnect) before=echo ;;
help) before=history ;;
license) after=kill ;;
lsc) after=ls-F ;;
oping) after=onintr ;;
select) after=sched ;;
tables) after=switch ;;
version) before=wait ;;
when) before=where ;;
*) before=xxx after=xxx ;;
esac
row=0
if [ "$before" != "" -a "$before" != "xxx" ]; then
row=`grep -n \"$before\" $file | head -1 | cut -d":" -f 1`
elif [ "$after" != "" -a "$after" != "xxx" ]; then
row=`grep -n \"$after\" $file | head -1 | cut -d":" -f 1`
row=`expr $row + 1`
fi
echo $row
}
#
# Main processing
#
# Development tree
echo "$PACKAGE development tree"
echo " ."
echo " |-- at-testsuite"
echo " |-- docs"
echo " |-- etc"
echo " |-- `basename $PUBDIR`"
echo " | |-- $OCILIBDIR"
echo " | |-- `basename $ORADIR`"
echo " | | \`-- `basename $oraver`"
echo " | |-- rlibc"
echo " | \`-- tcsh"
echo " |-- `basename $SHELLDIR`"
echo " \`-- src"
echo
# git submodule init
# git submodule update
# Move to the root download directory
if [ ! -d $PUBDIR ]; then
mkdir $PUBDIR
fi
# Oracle Instant Client
do_oracle
# OCILIB
do_ocilib
# rlibc
do_rlibc
# tcsh
do_tcsh
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# -=-=-=-=-=-=-=-=-=-=
# Start patching tcsh
# -=-=-=-=-=-=-=-=-=-=
# evaluate EXTRA items to be included in Makefile.in
USRLIBS="$PKGLIB $RLIBC $OCILIB"
EXTRAFLAGS="-I$PUBDIR/$OCILIBDIR/include -I$RLIBCDIR -I../src"
EXTRALIBS="$USRLIBS -L$ORALIBDIR -lclntsh -lpthread -lm -lcrypt -lcurses"
# extra source files
EXTRASRCS="$HEADER $PACKAGE-tcsh-wrap.c"
# extra object files
EXTRAOBJS="$PACKAGE-tcsh-wrap.o"
# -=-=-=-=-=-=-=-=-=-=-=-=-=
# Move to project top directory
cd $ROOTDIR
# Create and populate the main [shell] directory
if [ ! -d $SHELLNAME ]; then
echo
echo "Populating main directory [$SHELLNAME] ..."
cp -r $PUBDIR/tcsh $SHELLNAME
rm -rf $SHELLNAME/.git $SHELLNAME/.gitignore
fi
echo
echo "Patching now tcsh sources ............"
#
# Patch file $HEADER
#
echo -n " patching header file $HEADER ......... "
cp $EXTDIR/$HEADER $SHELLDIR/$HEADER
for cmd in `echo $EXTRACMDS | sort`; do
cat $SHELLDIR/$HEADER | echo "int $PACKAGE"_$cmd "(int argc, char * argv []);" >> $SHELLDIR/$HEADER
done
echo "done!"
#
# Patch src file tcsh-wrap.c
#
echo -n " patching source file tcsh-wrap.c ... "
cp $EXTDIR/tcsh-wrap.c $SHELLDIR/$PACKAGE-tcsh-wrap.c
echo >> $SHELLDIR/$PACKAGE-tcsh-wrap.c
for cmd in `echo $EXTRACMDS`; do
echo "void tcsh_$cmd (Char ** v, struct command * c) { USE(c); tcsh_xxx (v, osh_$cmd); }" >> $SHELLDIR/$PACKAGE-tcsh-wrap.c
done
echo "done!"
# Move to the build directory
cd $SHELLDIR
# Add links to project sources tree
for f in $FILES; do
if [ ! -h $PACKAGE-$f ]; then
if [ -f $EXTDIR/$f ]; then
ln -sf $EXTDIR/$f $PACKAGE-$f
else
echo " Error: source file `basename $SHELLDIR`/$EXTDIR/$f does not exist!"
exit 0
fi
fi
done
#
# Patch config/linux for tool chain changes
#
echo -n " patching config/linux .............. "
if [ ! -f config/linux.ORG ]; then
cp config/linux config/linux.ORG
fi
cp config/linux.ORG config/linux.tmp
cat config/linux.tmp | sed -e 's|SVID_SOURCE|DEFAULT_SOURCE|g' -e 's|BSD_SOURCE|DEFAULT_SOURCE|g' > config/linux
rm -f config/linux.tmp
echo "done!"
#
# Patch Makefile.in
#
# 1. change the name to the executable
# 2. add search path for project header file to EXTRAFLAGS
# 3. add more to EXTRALIBS
# 4. add ${EXTRASRCS} to the macro SHSRCS
# 5. add ${EXTRAOBJS} to the macro SHOBJS
# 6. add macro EXTRASRCS= with project source files
# 7. add macro EXTRAOBJS= with project object files
# 8.
# 9. change the main target to use name $PACKAGE
#
echo -n " patching Makefile.in ............... "
if [ ! -f Makefile.in.ORG ]; then
cp Makefile.in Makefile.in.ORG
fi
# 1. change the name to the executable
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e "s|/tcsh|/$PACKAGE|" > Makefile.in
# 2. add search path for project header file to EXTRAFLAGS
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e "s|EXTRAFLAGS =\(.*\)|EXTRAFLAGS =\1 $EXTRAFLAGS|" > Makefile.in
# 3. add more to EXTRALIBS
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e "s|EXTRALIBS =\(.*\)|EXTRALIBS =\1 $EXTRALIBS|" > Makefile.in
# 4. add $EXTRASRCS to the macro SHSRCS
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e 's|SHSRCS=\(.*\)|SHSRCS=\1 ${EXTRASRCS}|' > Makefile.in
# 5. add $EXTRAOBJS to the macro SHOBJS
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e 's|OBJS= ${SHOBJS}\(.*\)|OBJS= ${SHOBJS}\1 ${EXTRAOBJS}|' > Makefile.in
# 6. add macro EXTRASRCS= with project source files
line=`grep -n "SHSRCS=" Makefile.in | cut -d":" -f 1`
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed "$line i EXTRASRCS= $EXTRASRCS" > Makefile.in
# 7. add macro EXTRAOBJS= with project object files
line=`grep -n "OBJS=" Makefile.in | tail -1 | cut -d":" -f 1`
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed "$line i EXTRAOBJS= $EXTRAOBJS" > Makefile.in
# 8.
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e "s|tcsh\$(EXEEXT)|$PACKAGE|" > Makefile.in
# 9. change the main target to use name $PACKAGE
cp Makefile.in Makefile.in.tmp
cat Makefile.in.tmp | sed -e "s|$PACKAGE:.*|$PACKAGE: \${OBJS} \${LIBES} ${USRLIBS} |" > Makefile.in
rm -f Makefile.in.tmp
rm -f Makefile
echo "done!"
#
# Patch sh.c
#
# o add [$PACKAGE] initialization function
#
echo -n " patching sh.c ...................... "
if [ ! -f sh.c.ORG ]; then
cp sh.c sh.c.ORG
fi
# Add [$PACKAGE] call to the inizialization function
cp sh.c.ORG sh.c.tmp
line=`grep -n 'process(setintr)' sh.c.tmp | cut -d":" -f 1`
cat sh.c.tmp | sed "$line i {extern void osh_init (char * progname, int quiet); osh_init (progname, fast); }" > sh.c
rm -f sh.c.tmp
echo "done!"
#
# Patch sh.decls.h
#
# o add function declarations
#
echo -n " patching sh.decls.h ................ "
if [ ! -f sh.decls.h.ORG ]; then
cp sh.decls.h sh.decls.h.ORG
fi
cp sh.decls.h.ORG sh.decls.h
for cmd in $EXTRACMDS; do
cp sh.decls.h sh.decls.h.tmp
line=`grep -n '#define' sh.decls.h.tmp | head -1 | cut -d":" -f 1`
line=`expr $line + 2`
cat sh.decls.h.tmp | sed "$line i extern void tcsh_$cmd (Char **, struct command *);" > sh.decls.h
done
cp sh.decls.h sh.decls.h.tmp
line=`grep -n '#define' sh.decls.h.tmp | head -1 | cut -d":" -f 1`
line=`expr $line + 2`
cat sh.decls.h.tmp | sed "$line i /* $PACKAGE extension */" > sh.decls.h
rm -f sh.decls.h.tmp
echo "done!"
#
# Patch sh.init.c
#
# o add entries to the table of builtins => const struct biltins bfunc[]
#
echo " patching sh.init.c ................. "
if [ ! -f sh.init.c.ORG ]; then
cp sh.init.c sh.init.c.ORG
fi
# Add commands to the table of builtins
maxname=`maxn`
cp sh.init.c.ORG sh.init.c
# Patch [while] command to add a trailing comma in the event it serves to add commands as last
cp sh.init.c sh.init.c.tmp
cat sh.init.c.tmp | sed -e 's|{ "while", dowhile, 1, INF }|{ "while", dowhile, 1, INF },|' > sh.init.c
for cmd in $EXTRACMDS; do
cp sh.init.c sh.init.c.tmp
line=`linenumber $cmd sh.init.c.tmp`
if [ "$line" != "" -a "$line" != "0" ]; then
cat sh.init.c.tmp | sed "$line i { \"$cmd\", tcsh_$cmd, 0, INF }, /* $PACKAGE extension */" > sh.init.c
echo $maxname $cmd $line | awk '{ printf (" %-*.*s .................. ok! line [%s]\n", $1, $1, $2, $3) }'
else
echo $maxname $cmd | awk '{ printf (" %-*.*s .................. failed! - Please add case in linenumber()\n", $1, $1, $2) }'
exit 0
fi
if [ "$line" = "1" ]; then
echo " Error: Wrong specification"
exit 0
fi
done
rm -f sh.init.c.tmp
echo
# Attempt to configure and compile the shell
cd $SHELLDIR
if [ ! -f config.status ]; then
echo -n " Configuring $PACKAGE ..... "
./configure --prefix=/usr CFLAGS='-g -O2 -D_DEFAULT_SOURCE -Wno-pointer-compare' 1> /dev/null 2>&1
echo "done!"
fi
if [ ! -f sh.err.h ]; then
echo -n " Pre-compiling $PACKAGE ... "
make sh.err.h tc.const.h ed.defns.h tc.defs.c 1> /dev/null 2>&1
echo "done!"
fi