-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
build
executable file
·568 lines (475 loc) · 12.7 KB
/
build
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
#!/bin/sh
echo "Build (N)compress"
CLS=`sh -c 'tput clear' 2>/dev/null`
if expr `echo "foo\c"` : '.*c' >/dev/null
then
n='-n'
c=''
else
n=''
c='\c'
fi
trap 'rm -f /tmp/sh$$.tm* /tmp/sh$$.f* /tmp/sh$$.log /tmp/sh*.c' 0
trap 'set +x ; exit 1' 1 2 15
[ -f compress.def ] && . ./compress.def
while true
do
if [ "${DEFINED}" = yes ]
then
echo "${CLS} Build (N)compress
1. Directory to install compress in: ${BINDIR}
manual in : ${MANDIR}
2. Memory free for compress : ${USERMEM}
3. Input/Output buffer size : ${IBUFSIZ} ${OBUFSIZ}
4. C Compiler : ${CC}
5. Compiler options : ${CCOPT:---none--}
6. Library options : ${LBOPT:---none--}
7. Special options for your system : ${EXTRA:---none--}
9. Symbolic links : ${LSTAT}
10. Use include <utime.h> : ${UTIME_H}"
echo "
d. Set default settings mkshar. Create shell archive
c. Compile compress mktar. Create tar archive
t. Test compress cleanup. Cleanup
i. Install compress genmake. Generate makefile
q. Stop
"
echo ${n} " Choice [1..10,d,c,t,i,q,mkshar,mktar,cleanup] : ${c}"
(
echo "# Current parameters."
for var in CC CCOPT LBOPT BINDIR MANDIR IBUFSIZ \
OBUFSIZ USERMEM LSTAT \
EXTRA DEFINED UTIME_H
do
echo "${var}='`eval echo \$\{${var}\}`'"
done
) >compress.def
read choice var1 var2 var3 var4 varr
echo ""
else
choice=D
fi
case "${choice}" in
1)
if [ ".${var1}" = . ]
then
echo ${n} "Directory to install compress in (default:${BINDIR}) ? ${c}"
read var1 dummy
fi
BINDIR="${var1:-${BINDIR}}"
if [ ".${var2}" = . ]
then
echo ${n} "Directory to install manuals in (default:${MANDIR}) ? ${c}"
read var2 dummy
fi
MANDIR="${var2:-${MANDIR}}"
;;
2)
if [ ".${var1}" = . ]
then
echo "Compress use a lot of memory, the more memory it can just the faster"
echo "the program is and the better compression is."
echo ${n} "Memory free for compress (default:${USERMEM}) ? ${c}"
read var1 dummy
fi
USERMEM="${var1:-${USERMEM}}"
;;
3)
if [ ".${var1}" = . ]
then
echo "For input and output compress use buffers. A bigger buffer reduce"
echo "system (kernel) overhead. If your system is a 16 bits system don't"
echo "make the buffers bigger than 2048 bytes. The default 2048 is in"
echo "most cases a good answer."
echo ${n} "Best input buffer size (default:${IBUFSIZ}) ? ${c}"
read var1 var2 dummy
if [ ".${var2}" = . ]
then
echo ${n} "Best output buffer size (default:${OBUFSIZ}) ? ${c}"
read D dummy
fi
fi
var2="${var2:-${var1}}"
IBUFSIZ="${var1:-${IBUFSIZ}}"
OBUFSIZ="${var2:-${OBUFSIZ}}"
;;
4)
if [ ".${var1}" = . ]
then
echo "C compiler to use for compilation (must by cc compatible)".
echo ${n} "C Compiler (default:${CC}) ? ${c}"
read var1 dummy
fi
CC="${var1:-${CC}}"
;;
5)
if [ ".${var1}" = . ]
then
echo ${n} "Compiler options (default:${CCOPT:-none}) ? ${c}"
read var1
fi
[ ".${var1}" != . ] && CCOPT="${var1} ${var2} ${var3} ${var4} ${varr}"
;;
6)
if [ ".${var1}" = . ]
then
echo ${n} "Library options (default:${LBOPT:-none}) ? ${c}"
read var1
fi
[ ".${var1}" != . ] && LBOPT="${var1} ${var2} ${var3} ${var4} ${varr}"
;;
7)
if [ ".${var1}" = . ]
then
echo "Some system needs extra defines see README"
echo ${n} "Special for your system (default:${EXTRA:-none}) ? ${c}"
read var1
fi
[ ".${var1}" != . ] && EXTRA="${var1} ${var2} ${var3} ${var4} ${varr}"
;;
9)
if [ ".${var1}" = . ]
then
echo ${n} "Symbolic links (default:${LSTAT}) ? ${c}"
read var1 dummy
fi
case "${var1}" in
y|Y|yes|YES) LSTAT=yes; ;;
*) LSTAT=no; ;;
esac
;;
10)
if [ ".${var1}" = . ]
then
echo ${n} "Do your system support utime.h (default:${UTIME_H}) ? ${c}"
read var1 dummy
fi
case "${var1}" in
y|Y|yes|YES) UTIME_H=yes; ;;
*) UTIME_H=no; ;;
esac
;;
d|D)
echo "Testing the system to find out what kind of system we have."
BINDIR=/usr/bin
MANDIR=/usr/man/man1
UTIME_H=no
IBUFSIZ=2048
OBUFSIZ=2048
USERMEM=0
LSTAT=no
CCOPT='-O'
LBOPT=
EXTRA=
[ -f /usr/include/utime.h ] && { UTIME_H=yes; }
[ -d /usr/local/bin ] && { BINDIR=/usr/local/bin; }
[ -d /usr/local/man ] && { BINDIR=/usr/local/man/man1; }
[ -f /usr/bin/compress ] && { BINDIR=/usr/bin; }
if [ ".${CC}" = . ]
then
echo ${n} "Find compiler. Compiler is: ${c}"
echo 'main() {return 0;}' >/tmp/sh$$.c
for cc in cc gcc
do
if ${cc} -c /tmp/sh$$.c >/dev/null 2>&1
then
rm -f sh$$.o
CC=${cc}
echo ${CC}
break
fi
done
if [ ".${CC}" = . ]
then
echo "Can't find one of the standard compilers. Give C Compiler name"
echo ${n} "C Compiler : ${c}"
read CC dummy
fi
fi
echo ${n} "Test best buffer size: ${c}"
cat >/tmp/sh$$.c <<!
#include <stdio.h>
main()
{
int size;
size = 1024;
#ifdef BUFSIZ
if (size < BUFSIZ) size = BUFSIZ;
#endif
if (sizeof(int)<4) size = 2048;
printf("%d\n", size);
return 0;
}
!
${CC} /tmp/sh$$.c && IBUFSIZ=`./a.out`
rm -f /tmp/sh$$.c a.out
OBUFSIZ=${IBUFSIZ}
echo "${IBUFSIZ}"
echo ${n} "Test if system support symbolic links? ${c}"
cat >/tmp/sh$$.c <<!
main()
{
lstat(0, 0);
}
!
LSTAT=no
${CC} /tmp/sh$$.c >/dev/null 2>&1 && LSTAT=yes
echo "${LSTAT}"
rm -f a.out /tmp/sh$$.c
echo ${n} "Test available memory${c}"
for size in 75000 130000 230000 440000 800000
do
cat >/tmp/sh$$.c <<!
char test[${size}+128000];
extern int alarm();
extern int exit();
extern int signal();
sig() {exit(1);}
main()
{
register int i;
register long j;
for (i = 1 ; i <= 15 ; ++i)
signal(i, sig);
alarm(2);
for (i = 0 ; i < 10 ; ++i)
for (j = 0 ; j < sizeof(test) ; j+= 1024)
test[j] = i;
alarm(0);
return 0;
}
!
${CC} /tmp/sh$$.c >/dev/null 2>&1 || break
./a.out || break
rm a.out /tmp/sh$$.c
USERMEM=${size}
echo ${n} " ${size}${c}"
done
rm a.out /tmp/sh$$.c
echo ""
DEFINED=yes
echo ""
echo "I have now create the default options for compiling compress"
;;
c|C)
options="${CCOPT} -o compress"
[ "${LSTAT}" != no ] && options="${options} -DLSTAT=1"
[ "${UTIME_H}" != no ] && options="${options} -DUTIME_H=1"
options="${options} -DUSERMEM=${USERMEM}"
options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
options="${options} ${EXTRA}"
echo ""
echo "Compiling compress"
echo ${CC} ${options} compress.c ${LBOPT}
if ${CC} ${options} compress.c ${LBOPT}
then
echo ""
./compress -V
echo ""
echo "Compress compiled, use 'i' to install compress in ${BINDIR}"
else
echo ""
echo "Error(s) in compilation"
fi
echo ""
echo ${n} "Press return to continue${c}"
read dummy
;;
s|S)
options="-O -S"
[ "${LSTAT}" != no ] && options="${options} -DLSTAT=1"
[ "${UTIME_H}" != no ] && options="${options} -DUTIME_H=1"
options="${options} -DUSERMEM=${USERMEM}"
options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
options="${options} ${EXTRA}"
echo ""
echo "Compiling compress"
echo ${CC} ${options} compress.c
${CC} ${options} compress.c
echo ""
echo ${n} "Press return to continue${c}"
read dummy
;;
t|T)
if [ ! -x ./compress ]
then
echo "Compile compress first before testing!"
else
if [ ".${var1}" = . ]
then
echo "To test compress you need a test set. For a test set alle filein one"
echo "directory are combined to one file with cpio and compress/decompressed"
echo ${n} "Test directory [default:current]: ${c}"
read var1 varr
fi
if [ ! -d ${var1:-.} ]
then
echo "$var1: no directory"
else
var1=`cd ${var1:-.};pwd`
find ${var1} -type f -print |
( while read fn ; do [ -r ${fn} ] && echo ${fn} ; done ) |
sort >/tmp/sh$$.fi
(
echo "==============================================================================="
echo "Directory: ${var1:-/}"
echo "./compress -V"
./compress -V
if [ -x ${BINDIR}/compress ]
then
old=${var2:-${BINDIR}/compress}
set -- ./compress ${old} \
${old} ./compress \
./compress ./compress \
${old} ${old}
echo "${old} -V"
${old} -V </dev/null dummy-file
else
set -- ./compress ./compress
fi
while [ $# != 0 ]
do
echo "---------------- $1 -> $2 ----------------"
if [ -x /sbin/sync ] ; then /sbin/sync
else sync ; fi
sleep 1
cpio -o </tmp/sh$$.fi |
( time $1 -v 2>/tmp/sh$$.tm1 ) |
( time $2 -d 2>/tmp/sh$$.tm2 ) |
( cpio -ivt >/tmp/sh$$.fo )
awk </tmp/sh$$.fo '{print $8}' >/tmp/sh$$.foo
if cmp /tmp/sh$$.fi /tmp/sh$$.foo
then
:
else
echo ------ ERROR
diff /tmp/sh$$.fi /tmp/sh$$.foo
fi
echo "---------------"
echo "compress $1("`cat /tmp/sh$$.tm1`")"
echo "decompress $2("`cat /tmp/sh$$.tm2`")"
shift 2
done
) 2>&1 | tee /tmp/sh$$.log
cat /tmp/sh$$.log >>comp.log && rm /tmp/sh$$.log
fi
echo ""
fi
echo ${n} "Press return to continue${c}"
read dummy
;;
i|I)
if [ ".${var1}" = . ]
then
echo ${n} "Install compress with user ? (default current user) ? ${c}"
read var1 dummy
fi
pwd=`pwd`
( cat - <<!
set -x
cd ${pwd}
[ -f ${BINDIR}/compress ] &&
{ rm -f ${BINDIR}/compress.old ;
mv ${BINDIR}/compress ${BINDIR}/compress.old || exit 1; }
rm -f ${BINDIR}/uncompress ${BINDIR}/zcat || exit 1
cp compress ${BINDIR}/compress || exit 1
strip ${BINDIR}/compress
rm -f ${BINDIR}/uncompress || exit 1
ln ${BINDIR}/compress ${BINDIR}/uncompress || exit 1
rm -f ${BINDIR}/zcat || exit 1
ln -f ${BINDIR}/compress ${BINDIR}/zcat || exit 1
cp zcmp zdiff zmore ${BINDIR}/. || exit 1
chmod 0755 ${BINDIR}/compress ${BINDIR}/zcmp ${BINDIR}/zdiff \
${BINDIR}/zmore || exit 1
cp compress.1 zcmp.1 zmore.1 ${MANDIR}/. || exit 1
chmod 0644 ${MANDIR}/compress.1 ${MANDIR}/zcmp.1 \
${MANDIR}/zmore.1 || exit 1
if [ ".${var1}" != . ]
then
chown ${var1} ${BINDIR}/compress ${BINDIR}/zcmp \
${BINDIR}/zdiff ${BINDIR}/zmore \
${MANDIR}/compress.1 ${MANDIR}/zcmp.1 \
${MANDIR}/zmore.1
fi
!
) | (
if [ ".${var1}" = . ] ; then sh
else su - ${var1} -c sh ; fi
)
echo ""
echo ${n} "Press return to continue${c}"
read dummy
;;
genmake)
options=
[ "${LSTAT}" != no ] && options="${options} -DLSTAT=1"
[ "${UTIME_H}" != no ] && options="${options} -DUTIME_H=1"
options="${options} -DUSERMEM=${USERMEM}"
options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
options="${options} ${EXTRA}"
cat - <<! >Makefile
# Makefile generated by build.
# C compiler
CC=${CC}
# Install directory for binarys
BINDIR=${BINDIR}
# Install directory for manual
MANDIR=${MANDIR}
# compiler options:
# options is a collection of:
#
# -DAMIGA=1 Amiga support.
# -DLSTAT=1 Use lstat for finding symlinks.
# -DUTIME_H=1 Use utime.h
# -DUSERMEM=<size> Available memory for compress (default 800k).
# -DIBUFSIZ=<size> Input buffer size (default BUFSIZ).
# -DOBUFSIZ=<size> Output buffer size (default BUFSIZ)
#
options=${options}
# library options
LBOPT=${LBOPT}
compress: Makefile compress.c patchlevel.h
$(CC) -o compress $(options) compress.c $(LBOPT)
install: compress
[ -f \$(BINDIR)/compress ] && \\
{ rm -f \$(BINDIR)/compress.old ; \\
mv \$(BINDIR)/compress \$(BINDIR)/compress.old ; }
rm -f \$(BINDIR)/uncompress \$(BINDIR)/zcat
cp compress \$(BINDIR)/compress
strip \$(BINDIR)/compress
rm -f \$(BINDIR)/uncompress
ln \$(BINDIR)/compress \$(BINDIR)/uncompress
rm -f \$(BINDIR)/zcat
ln -f \$(BINDIR)/compress \$(BINDIR)/zcat
cp zcmp zdiff zmore \$(BINDIR)/.
chmod 0755 \$(BINDIR)/compress \$(BINDIR)/zcmp \$(BINDIR)/zdiff \$(BINDIR)/zmore
cp compress.1 zcmp.1 zmore.1 \$(MANDIR)/.
chmod 0644 \$(MANDIR)/compress.1 \$(MANDIR)/zcmp.1 \$(MANDIR)/zmore.1
cleanup:
rm -f compress compress.def comp.log
!
;;
mkshar)
xshar -sc -opart -l64 MANIFEST Acknowleds zmore Changes compress.1 \
zcmp zmore.1 README LZW.INFO zcmp.1 zdiff build Makefile.def \
compress.c patchlevel.h
;;
mktar)
rm -f comp.tar
tar cvf comp.tar MANIFEST Acknowleds zmore Changes compress.1 \
zcmp zmore.1 README LZW.INFO zcmp.1 zdiff build Makefile.def \
compress.c patchlevel.h
;;
cleanup)
rm -f compress compress.def comp.log
exit 0
;;
q|Q)
exit 0
;;
*)
echo " Unknown choice ${choice}"
sleep 2
;;
esac
done