"Fossies" - the Fresh Open Source Software Archive

Member "ncompress-5.0/build" (2 Feb 2021, 14634 Bytes) of package /linux/privat/ncompress-5.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "build": 4.2.4.5_vs_4.2.4.6.

    1 #!/bin/sh
    2 
    3 echo "Build (N)compress"
    4 CLS=`sh -c 'tput clear' 2>/dev/null`
    5 
    6 if expr `echo "foo\c"` : '.*c' >/dev/null
    7 then
    8     n='-n'
    9     c=''
   10 else
   11     n=''
   12     c='\c'
   13 fi
   14 
   15 trap 'rm -f /tmp/sh$$.tm* /tmp/sh$$.f* /tmp/sh$$.log /tmp/sh*.c' 0
   16 trap 'set +x ; exit 1' 1 2 15
   17 
   18 [ -f compress.def ] && . ./compress.def
   19 
   20 while true
   21 do
   22     if [ "${DEFINED}" = yes ]
   23     then
   24         echo "${CLS}    Build (N)compress
   25 
   26  1.  Directory to install compress in: ${BINDIR}
   27                           manual in  : ${MANDIR}
   28  2.  Memory free for compress        : ${USERMEM}
   29  3.  Input/Output buffer size        : ${IBUFSIZ} ${OBUFSIZ}
   30  4.  C Compiler                      : ${CC}
   31  5.  Compiler options                : ${CCOPT:---none--}
   32  6.  Libary options                  : ${LBOPT:---none--}
   33  7.  Special options for your system : ${EXTRA:---none--}
   34  9.  Symbolic links                  : ${LSTAT}
   35 10.  Use include <utime.h>           : ${UTIME_H}"
   36 
   37         echo "
   38  d. Set default settings                    mkshar.  Create shell archive
   39  c. Compile compress                        mktar.   Create tar archive
   40  t. Test compress                           cleanup. Cleanup
   41  i. Install compress                        genmake. Generate makefile
   42  q. Stop
   43 "
   44         echo ${n} "   Choice [1..10,d,c,t,i,q,mkshar,mktar,cleanup] : ${c}"
   45 
   46         (
   47             echo "# Current parameters."
   48             for var in CC CCOPT LBOPT BINDIR MANDIR IBUFSIZ \
   49                         OBUFSIZ USERMEM LSTAT BYTEORDER \
   50                         EXTRA DEFINED UTIME_H
   51             do
   52                 echo "${var}='`eval echo \$\{${var}\}`'"
   53             done
   54         ) >compress.def
   55 
   56         read choice var1 var2 var3 var4 varr
   57         echo ""
   58     else
   59         choice=D
   60     fi
   61 
   62     case "${choice}" in
   63     1)
   64         if [ ".${var1}" = . ]
   65         then
   66             echo ${n} "Directory to install compress in (default:${BINDIR}) ? ${c}"
   67             read var1 dummy
   68         fi
   69 
   70         BINDIR="${var1:-${BINDIR}}"
   71 
   72         if [ ".${var2}" = . ]
   73         then
   74             echo ${n} "Directory to install manuals in (default:${MANDIR}) ? ${c}"
   75             read var2 dummy
   76         fi
   77 
   78         MANDIR="${var2:-${MANDIR}}"
   79         ;;
   80 
   81     2)
   82         if [ ".${var1}" = . ]
   83         then
   84             echo "Compress use a lot of memory, the more memory it can just the faster"
   85             echo "the programm is and the better compression is."
   86             echo ${n} "Memory free for compress (default:${USERMEM}) ? ${c}"
   87             read var1 dummy 
   88         fi
   89 
   90         USERMEM="${var1:-${USERMEM}}"
   91         ;;
   92 
   93     3)  
   94         if [ ".${var1}" = . ]
   95         then
   96             echo "For input and output compress use buffers. A bigger buffer reduce"
   97             echo "system (kernel) overhead. If your system is a 16 bits system don't"
   98             echo "make the buffers bigger than 2048 bytes. The default 2048 is in"
   99             echo "most cases a good answer."
  100             echo ${n} "Best input buffer size (default:${IBUFSIZ}) ? ${c}"
  101             read var1 var2 dummy
  102 
  103             if [ ".${var2}" = . ] 
  104             then
  105                 echo ${n} "Best output buffer size (default:${OBUFSIZ}) ? ${c}"
  106                 read D dummy 
  107             fi
  108         fi
  109 
  110         var2="${var2:-${var1}}"
  111         IBUFSIZ="${var1:-${IBUFSIZ}}"
  112         OBUFSIZ="${var2:-${OBUFSIZ}}"
  113         ;;
  114 
  115     4)
  116         if [ ".${var1}" = . ]
  117         then    
  118             echo "C compiler to use for compilation (must by cc compatible)".
  119             echo ${n} "C Compiler (default:${CC}) ? ${c}"
  120             read var1 dummy
  121         fi
  122 
  123         CC="${var1:-${CC}}"
  124         ;;
  125 
  126     5)
  127         if [ ".${var1}" = . ]
  128         then
  129             echo ${n} "Compiler options (default:${CCOPT:-none}) ? ${c}"
  130             read var1
  131         fi
  132 
  133         [ ".${var1}" != . ] && CCOPT="${var1} ${var2} ${var3} ${var4} ${varr}"
  134         ;;  
  135 
  136     6)
  137         if [ ".${var1}" = . ]
  138         then
  139             echo ${n} "Libary options (default:${LBOPT:-none}) ? ${c}"
  140             read var1
  141         fi
  142 
  143         [ ".${var1}" != . ] && LBOPT="${var1} ${var2} ${var3} ${var4} ${varr}"
  144         ;;  
  145 
  146     7)
  147         if [ ".${var1}" = . ]
  148         then
  149             echo "Some system needs extra defines see README"
  150             echo ${n} "Special for your system (default:${EXTRA:-none}) ? ${c}"
  151             read var1
  152         fi
  153 
  154         [ ".${var1}" != . ] && EXTRA="${var1} ${var2} ${var3} ${var4} ${varr}"
  155         ;;  
  156 
  157     9)
  158         if [ ".${var1}" = . ]
  159         then
  160             echo ${n} "Symbolic links (default:${LSTAT}) ? ${c}"
  161             read var1 dummy
  162         fi
  163 
  164         case "${var1}" in
  165         y|Y|yes|YES) LSTAT=yes; ;;
  166         *)           LSTAT=no; ;;
  167         esac
  168         ;;
  169 
  170     10)
  171         if [ ".${var1}" = . ]
  172         then
  173             echo ${n} "Do your system support utime.h (default:${UTIME_H}) ? ${c}"
  174             read var1 dummy
  175         fi
  176 
  177         case "${var1}" in
  178         y|Y|yes|YES) UTIME_H=yes; ;;
  179         *)           UTIME_H=no; ;;
  180         esac
  181         ;;
  182 
  183     d|D)
  184         echo "Testing the system to find out what kind of system we have."
  185         BINDIR=/usr/bin
  186         MANDIR=/usr/man/man1
  187         UTIME_H=no
  188         IBUFSIZ=2048
  189         OBUFSIZ=2048
  190         USERMEM=0
  191         LSTAT=no
  192         CCOPT='-O'
  193         LBOPT=
  194         EXTRA=
  195         [ -f /usr/include/utime.h ] && { UTIME_H=yes; }
  196         [ -d /usr/local/bin ] && { BINDIR=/usr/local/bin; }
  197         [ -d /usr/local/man ] && { BINDIR=/usr/local/man/man1; }
  198         [ -f /usr/bin/compress ] && { BINDIR=/usr/bin; }
  199     
  200         if [ ".${CC}" = . ]
  201         then
  202             echo ${n} "Find compiler. Compiler is: ${c}"
  203             echo 'main() {return 0;}' >/tmp/sh$$.c
  204 
  205             for cc in cc gcc
  206             do
  207                 if ${cc} -c /tmp/sh$$.c >/dev/null 2>&1
  208                 then
  209                     rm -f sh$$.o
  210                     CC=${cc}
  211                     echo ${CC}
  212                     break
  213                 fi
  214             done
  215 
  216             if [ ".${CC}" = . ]
  217             then
  218                 echo "Can't file one of the standaard compilers. Give C Compiler name"
  219                 echo ${n} "C Compiler : ${c}"
  220                 read CC dummy
  221             fi
  222         fi
  223 
  224         echo ${n} "Test best buffer size: ${c}"
  225         cat >/tmp/sh$$.c <<!
  226 #include <stdio.h>
  227         main()
  228             {
  229                 int     size;
  230     
  231                 size = 1024;
  232 #ifdef BUFSIZ
  233                 if (size < BUFSIZ)  size = BUFSIZ;
  234 #endif
  235                 if (sizeof(int)<4)  size = 2048;
  236                 printf("%d\n", size);
  237                 return 0;
  238             }
  239 !
  240         ${CC} /tmp/sh$$.c && IBUFSIZ=`./a.out`
  241         rm -f /tmp/sh$$.c a.out
  242         OBUFSIZ=${IBUFSIZ}
  243         echo "${IBUFSIZ}"
  244 
  245         echo ${n} "Test byte order of system: ${c}"
  246         cat >/tmp/sh$$.c <<!
  247         main()
  248             {
  249                 long    test;
  250         extern  int     write();
  251         
  252                 test = 0x31323334L;
  253                 write(1, (char *)&test, 4);
  254                 return 0;
  255             }
  256 !
  257         ${CC} /tmp/sh$$.c && BYTEORDER=`./a.out`
  258         BYTEORDER="${BYTEORDER:-0000}"
  259         echo ${BYTEORDER}
  260         rm -f /tmp/sh$$.c a.out
  261 
  262         echo ${n} "Test if system support symbolic links? ${c}"
  263         cat >/tmp/sh$$.c <<!
  264         main()
  265             {
  266                 lstat(0, 0);
  267             }
  268 !
  269         LSTAT=no
  270         ${CC} /tmp/sh$$.c >/dev/null 2>&1 && LSTAT=yes
  271         echo "${LSTAT}"
  272         rm -f a.out /tmp/sh$$.c
  273 
  274         echo ${n} "Test availble memory${c}"
  275         for size in 75000 130000 230000 440000 800000
  276         do
  277             cat >/tmp/sh$$.c <<!
  278             char    test[${size}+128000];
  279     
  280             extern  int             alarm();
  281             extern  int             exit();
  282             extern  int             signal();
  283     
  284             sig() {exit(1);}
  285 
  286             main()
  287                 {
  288                     register int    i;
  289                     register long   j;
  290     
  291                     for (i = 1 ; i <= 15 ; ++i)
  292                         signal(i, sig);     
  293 
  294                     alarm(2);
  295     
  296                     for (i = 0 ; i < 10 ; ++i)
  297                         for (j = 0 ; j < sizeof(test) ; j+= 1024)
  298                             test[j] = i;
  299 
  300                     alarm(0);
  301                     return 0;
  302                 }
  303 !
  304             ${CC} /tmp/sh$$.c >/dev/null 2>&1 || break
  305             ./a.out || break
  306             rm a.out /tmp/sh$$.c
  307             USERMEM=${size}
  308             echo ${n} " ${size}${c}"
  309         done
  310 
  311         rm a.out /tmp/sh$$.c
  312 
  313         echo ""
  314 
  315         if [ ${USERMEM} = 0 ]
  316         then
  317             echo ${n} "Memory size is 0, segmented processor: ${c}"
  318             cat >/tmp/sh$$.c <<!
  319             long htab0[8192];
  320             long htab1[8192];
  321             long htab2[8192];
  322             long htab3[8192];
  323             long htab4[8192];
  324             long htab5[8192];
  325             long htab6[8192];
  326             long htab7[8192];
  327             long htab8[8192];
  328             short code0tab[16384];
  329             short code1tab[16384];
  330             short code2tab[16384];
  331             short code3tab[16384];
  332             short code4tab[16384];
  333             main() {return 0;}
  334 !
  335             rm -f ./a.out
  336             if ${CC} /tmp/sh$$.c >/dev/null 2>&1 
  337             then
  338                 :
  339             else
  340                 opt="-Ml"
  341 
  342                 while [ ".${opt}" != . ]
  343                 do
  344                     if ${CC} ${opt} /tmp/sh$$.c >/dev/null 2>&1 
  345                     then
  346                         :
  347                     else
  348                         CCOPT="${CCOPT} ${opt}"
  349                         break
  350                     fi
  351 
  352                     echo ${n} "Large model compile option: ${c}"
  353                     read opt dummy
  354                 done
  355             fi
  356 
  357             if [ -f ./a.out ]
  358             then
  359                 if ./a.out
  360                 then
  361                     echo "Yes"
  362                     MEMSIZE=0
  363                     EXTRA="${EXTRA} -DMAXSEG_64K=1 -DBITS=16"
  364                 else
  365                     echo "No"
  366                 fi
  367             fi
  368 
  369             rm ./a.out /tmp/sh$$.c
  370         fi
  371 
  372         DEFINED=yes
  373         echo ""
  374         echo "I have now create the default options for compiling compress"
  375     ;;
  376 
  377     c|C)
  378         options="${CCOPT} -o compress"
  379         [ "${LSTAT}" != no  ] && options="${options} -DLSTAT=1"
  380         [ "${UTIME_H}" != no  ] && options="${options} -DUTIME_H=1"
  381         options="${options} -DUSERMEM=${USERMEM}"
  382         options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
  383         options="${options} -DBYTEORDER=${BYTEORDER}"
  384         options="${options} ${EXTRA}"
  385 
  386         echo ""
  387         echo "Compiling compress"
  388 
  389         echo ${CC} ${options} compress.c ${LBOPT}
  390 
  391         if ${CC} ${options} compress.c ${LBOPT}
  392         then
  393             echo ""
  394             ./compress -V
  395             echo ""
  396             echo "Compress compiled, use 'i' to install compress in ${BINDIR}"
  397         else
  398             echo ""
  399             echo "Error(s) in compilation"
  400         fi
  401         echo ""
  402         echo ${n} "Press return to continue${c}"
  403         read dummy
  404         ;;
  405 
  406     s|S)
  407         options="-O -S"
  408         [ "${LSTAT}" != no  ] && options="${options} -DLSTAT=1"
  409         [ "${UTIME_H}" != no  ] && options="${options} -DUTIME_H=1"
  410         options="${options} -DUSERMEM=${USERMEM}"
  411         options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
  412         options="${options} -DBYTEORDER=${BYTEORDER}"
  413         options="${options} ${EXTRA}"
  414 
  415         echo ""
  416         echo "Compiling compress"
  417 
  418         echo ${CC} ${options} compress.c
  419 
  420         ${CC} ${options} compress.c
  421         echo ""
  422         echo ${n} "Press return to continue${c}"
  423         read dummy
  424         ;;
  425 
  426     t|T)
  427         if [ ! -x ./compress ]
  428         then
  429             echo "Compile compress first before testing!"
  430         else
  431             if [ ".${var1}" = . ]
  432             then
  433                 echo "To test compress you need a test set. For a test set alle filein one"
  434                 echo "directory are combined to one file with cpio and compress/decompressed"
  435                 echo ${n} "Test directory [default:current]: ${c}"
  436                 read var1 varr
  437             fi
  438 
  439             if [ ! -d ${var1:-.} ]
  440             then
  441                 echo "$var1: no directory"
  442             else
  443                 var1=`cd ${var1:-.};pwd`
  444                 find ${var1} -type f -print |
  445                     ( while read fn ; do [ -r ${fn} ] && echo ${fn} ; done ) |
  446                     sort >/tmp/sh$$.fi
  447 
  448                 (
  449                     echo "==============================================================================="
  450                     echo "Directory: ${var1:-/}"
  451                     echo "./compress -V"
  452                     ./compress -V
  453 
  454                     if [ -x ${BINDIR}/compress ]
  455                     then
  456                         old=${var2:-${BINDIR}/compress}
  457                         set -- ./compress ${old} \
  458                                 ${old} ./compress \
  459                                 ./compress ./compress \
  460                                 ${old} ${old}
  461 
  462                         echo "${old} -V"
  463                         ${old} -V </dev/null dummy-file
  464                     else
  465                         set -- ./compress ./compress
  466                     fi
  467 
  468                     while [ $# != 0 ]
  469                     do
  470                         echo "---------------- $1 -> $2 ----------------"
  471                         if [ -x /sbin/sync ] ;  then /sbin/sync
  472                                                 else sync ; fi
  473 
  474                         sleep 1
  475 
  476                         cpio -o </tmp/sh$$.fi |
  477                             ( time $1 -v 2>/tmp/sh$$.tm1 ) |
  478                             ( time $2 -d 2>/tmp/sh$$.tm2 ) |
  479                             ( cpio -ivt >/tmp/sh$$.fo )
  480         
  481                         awk </tmp/sh$$.fo '{print $8}'  >/tmp/sh$$.foo
  482     
  483                         if cmp /tmp/sh$$.fi /tmp/sh$$.foo
  484                         then
  485                             :
  486                         else
  487                             echo ------ ERROR
  488                             diff /tmp/sh$$.fi /tmp/sh$$.foo
  489                         fi
  490 
  491                         echo "---------------"
  492                         echo "compress   $1("`cat /tmp/sh$$.tm1`")"
  493                         echo "decompress $2("`cat /tmp/sh$$.tm2`")"
  494                         shift 2
  495                     done
  496                 ) 2>&1 | tee /tmp/sh$$.log
  497 
  498                 cat /tmp/sh$$.log >>comp.log && rm /tmp/sh$$.log
  499             fi
  500 
  501             echo ""
  502         fi
  503 
  504         echo ${n} "Press return to continue${c}"
  505         read dummy
  506         ;;
  507     i|I)
  508         if [ ".${var1}" = . ]
  509         then
  510             echo ${n} "Install compress with user ? (default current user) ? ${c}"
  511             read var1 dummy
  512         fi
  513 
  514         pwd=`pwd`
  515 
  516         ( cat - <<!
  517             set -x
  518 
  519             cd ${pwd}
  520 
  521             [ -f ${BINDIR}/compress ] &&
  522                 { rm -f ${BINDIR}/compress.old ;
  523                 mv ${BINDIR}/compress ${BINDIR}/compress.old || exit 1; }
  524 
  525             rm -f ${BINDIR}/uncompress ${BINDIR}/zcat || exit 1
  526 
  527             cp compress ${BINDIR}/compress || exit 1
  528             strip ${BINDIR}/compress
  529             rm -f ${BINDIR}/uncompress || exit 1
  530             ln ${BINDIR}/compress ${BINDIR}/uncompress || exit 1
  531             rm -f  ${BINDIR}/zcat || exit 1
  532             ln -f ${BINDIR}/compress ${BINDIR}/zcat || exit 1
  533             cp zcmp zdiff zmore ${BINDIR}/. || exit 1
  534             chmod 0755 ${BINDIR}/compress ${BINDIR}/zcmp ${BINDIR}/zdiff \
  535                     ${BINDIR}/zmore || exit 1
  536             cp compress.1 zcmp.1 zmore.1 ${MANDIR}/. || exit 1
  537             chmod 0644 ${MANDIR}/compress.1 ${MANDIR}/zcmp.1 \
  538                     ${MANDIR}/zmore.1 || exit 1
  539 
  540             if [ ".${var1}" != . ]
  541             then
  542                 chown ${var1} ${BINDIR}/compress ${BINDIR}/zcmp \
  543                               ${BINDIR}/zdiff ${BINDIR}/zmore \
  544                               ${MANDIR}/compress.1 ${MANDIR}/zcmp.1 \
  545                               ${MANDIR}/zmore.1 
  546             fi
  547 !
  548         ) | (
  549             if [ ".${var1}" = . ] ; then sh 
  550                                     else su - ${var1} -c sh ; fi
  551         )
  552 
  553         echo ""
  554         echo ${n} "Press return to continue${c}"
  555         read dummy
  556         ;;
  557 
  558     genmake)
  559         options=
  560         [ "${LSTAT}" != no  ] && options="${options} -DLSTAT=1"
  561         [ "${UTIME_H}" != no  ] && options="${options} -DUTIME_H=1"
  562         options="${options} -DUSERMEM=${USERMEM}"
  563         options="${options} -DIBUFSIZ=${IBUFSIZ} -DOBUFSIZ=${OBUFSIZ}"
  564         options="${options} -DBYTEORDER=${BYTEORDER}"
  565         options="${options} ${EXTRA}"
  566 
  567         cat - <<! >Makefile
  568 # Makefile generated by build.
  569 
  570 # C complier
  571 CC=${CC}
  572 
  573 # Install directory for binarys
  574 BINDIR=${BINDIR}
  575 
  576 # Install directory for manual
  577 MANDIR=${MANDIR}
  578 
  579 # compiler options:
  580 # options is a collection of:
  581 #
  582 #   -DAMIGA=1                   Amiga support.
  583 #   -DLSTAT=1                   Use lstat for finding symlinks.
  584 #   -DUTIME_H=1                 Use utime.h
  585 #   -DUSERMEM=<size>            Availble memory for compress (default 800k).
  586 #   -DIBUFSIZ=<size>            Input buffer size (default BUFSIZ).
  587 #   -DOBUFSIZ=<size>            Output buffer size (default BUFSIZ)
  588 #   -DBYTEORDER=<order>         Byte order (default: unknown).
  589 #   -DMAXSEG_64K=1 -BITS=16     Support segment processsor like 80286.
  590 #
  591 options=${options}
  592 
  593 # libary options
  594 LBOPT=${LBOPT}
  595 
  596 
  597 compress:   Makefile compress.c patchlevel.h
  598     $(CC) -o compress $(options) compress.c $(LBOPT)
  599 
  600 install:    compress
  601         [ -f \$(BINDIR)/compress ] && \\
  602             { rm -f \$(BINDIR)/compress.old ; \\
  603             mv \$(BINDIR)/compress \$(BINDIR)/compress.old ; }
  604         rm -f \$(BINDIR)/uncompress \$(BINDIR)/zcat
  605         cp compress \$(BINDIR)/compress
  606         strip \$(BINDIR)/compress
  607         rm -f \$(BINDIR)/uncompress
  608         ln \$(BINDIR)/compress \$(BINDIR)/uncompress
  609         rm -f \$(BINDIR)/zcat
  610         ln -f \$(BINDIR)/compress \$(BINDIR)/zcat
  611         cp zcmp zdiff zmore \$(BINDIR)/.
  612         chmod 0755 \$(BINDIR)/compress \$(BINDIR)/zcmp \$(BINDIR)/zdiff \$(BINDIR)/zmore
  613         cp compress.1 zcmp.1 zmore.1 \$(MANDIR)/.
  614         chmod 0644 \$(MANDIR)/compress.1 \$(MANDIR)/zcmp.1 \$(MANDIR)/zmore.1
  615 
  616 cleanup:
  617         rm -f compress compress.def comp.log
  618 !
  619         ;;
  620 
  621     mkshar)
  622         xshar -sc -opart -l64 MANIFEST Acknowleds zmore Changes compress.1 \
  623             zcmp zmore.1 README LZW.INFO zcmp.1 zdiff build Makefile.def \
  624             compress.c patchlevel.h
  625         ;;
  626 
  627     mktar)
  628         rm -f comp.tar
  629         tar cvf comp.tar MANIFEST Acknowleds zmore Changes compress.1 \
  630             zcmp zmore.1 README LZW.INFO zcmp.1 zdiff build Makefile.def \
  631             compress.c patchlevel.h
  632         ;;
  633 
  634     cleanup)
  635         rm -f compress compress.def comp.log
  636         exit 0
  637         ;;
  638 
  639     q|Q)
  640         exit 0
  641         ;;
  642     *)
  643         echo "                                      Unknown choice ${choice}"
  644         sleep 2
  645         ;;
  646     esac
  647 done