"Fossies" - the Fresh Open Source Software Archive

Member "fpc-3.2.2.x86_64-linux/install.sh" (16 May 2021, 12706 Bytes) of package /linux/misc/fpc-3.2.2.x86_64-linux.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.

    1 #!/usr/bin/env bash
    2 #
    3 # Free Pascal installation script for Unixy platforms.
    4 # Copyright 1996-2004 Michael Van Canneyt, Marco van de Voort and Peter Vreman
    5 #
    6 # Don't edit this file.
    7 # Everything can be set when the script is run.
    8 #
    9 
   10 # Release Version will be replaced by makepack
   11 VERSION=3.2.2
   12 FULLVERSION=3.2.2
   13 
   14 # some useful functions
   15 # ask displays 1st parameter, and ask new value for variable, whose name is
   16 # in the second parameter.
   17 ask ()
   18 {
   19   askvar=$2
   20   eval old=\$$askvar
   21   eval printf \""$1 [$old] : "\"
   22   read $askvar
   23   eval test -z \"\$$askvar\" && eval $askvar=\'$old\'
   24 }
   25 
   26 # yesno gives 1 on no, 0 on yes $1 gives text to display.
   27 yesno ()
   28 {
   29   while true; do
   30   printf "$1 (Y/n) ? "
   31   read ans
   32   case X"$ans" in
   33    X|Xy|XY) return 0;;
   34    Xn|XN) return 1;;
   35   esac
   36   done
   37 }
   38 #
   39 #
   40 #
   41 CMDGREP="grep"
   42 CMDGGREP="`which ggrep 2> /dev/null`"
   43 if [ -f "$CMDGGREP" ] ; then
   44   CMDGREP="$CMDGGREP"
   45   echo "Using GREP binary=$CMDGREP"
   46 fi
   47 grep_version=`$CMDGREP --version 2> /dev/null `
   48 grep_version_res=$?
   49 if [ $grep_version_res -ne 0 ] ; then
   50   echo "Installed grep command $CMDGREP does not support --version"
   51   grep_version=""
   52 fi
   53 
   54 if [ "${grep_version//GNU/}" != "${grep_version}" ] ; then
   55   is_gnu_grep=1
   56   grep_silent_opt="-q"
   57 else
   58   is_gnu_grep=0
   59   grep_silent_opt=""
   60 fi
   61 
   62 CMDTAR="tar"
   63 # Use GNU tar if present
   64 CMDGTAR="`which gtar 2> /dev/null`"
   65 if [ -f "$CMDGTAR" ]; then
   66   CMDTAR="$CMDGTAR"
   67   echo "Using TAR binary=$CMDTAR"
   68 fi
   69 
   70 tar_version=`$CMDTAR --version 2> /dev/null `
   71 tar_version_res=$?
   72 if [ $tar_version_res -ne 0 ] ; then
   73   echo "Installed tar command $CMDTAR does not support --version"
   74   tar_version=""
   75 fi
   76 
   77 if [ "${tar_version//GNU/}" != "${tar_version}" ] ; then
   78   is_gnu_tar=1
   79   no_same_owner_tar_opt=--no-same-owner
   80   strip_tar_opt="--strip 1"
   81   use_gunzip=0
   82 else
   83   is_gnu_tar=0
   84   no_same_owner_tar_opt=
   85   strip_tar_opt=
   86   use_gunzip=1
   87 fi
   88 
   89 TAR="$CMDTAR $no_same_owner_tar_opt"
   90 # Untar files ($3,optional) from  file ($1) to the given directory ($2)
   91 unztar ()
   92 {
   93  if [ $use_gunzip -eq 0 ] ; then
   94    $TAR -xzf "$HERE/$1" -C "$2" $3
   95  else
   96    startdir="`pwd`" 
   97    targzfile="$HERE/$1"
   98    tarfile="${targzfile/tar.gz/tar}"
   99    if [ ! -f "$tarfile" ] ; then
  100      gunzip "$targzfile"
  101    fi
  102    cd "$2"
  103    $TAR -xf "$tarfile" $3
  104    cd "$startdir"
  105  fi
  106 }
  107 
  108 # Untar tar.gz file ($2) from file ($1) and untar result to the given directory ($3)
  109 unztarfromtar ()
  110 {
  111  if [ $use_gunzip -eq 0 ] ; then
  112    $CMDTAR -xOf "$HERE/$1" "$2" | $TAR -C "$3" -xzf -
  113  else
  114    startdir="`pwd`"
  115    $CMDTAR -xf "$HERE/$1" "$2"
  116    targzfile="$startdir/$2"
  117    tarfile="${targzfile/tar.gz/tar}"
  118    if [ ! -f "$tarfile" ] ; then
  119      gunzip "$targzfile"
  120    fi
  121    cd "$3"
  122    $TAR -xf "$tarfile"
  123    res=$?
  124    if [ $res -eq 0 ] ; then
  125      rm -f "$2"
  126    fi
  127    cd "$startdir"
  128  fi
  129 }
  130 
  131 # Get file list from tar archive ($1) in variable ($2)
  132 # optionally filter result through sed ($3)
  133 listtarfiles ()
  134 {
  135   askvar="$2"
  136   if [ ! -z "$3" ]; then
  137     list=`$CMDTAR tvf "$1" | awk '{ print $(NF) }' | sed -n /"$3"/p`
  138   else
  139      list=`$CMDTAR tvf "$1" | awk '{ print $(NF) }'`
  140   fi
  141   eval $askvar='$list'
  142 }
  143 
  144 # Make all the necessary directories to get $1
  145 makedirhierarch ()
  146 {
  147   mkdir -p "$1"
  148 }
  149 
  150 # check to see if something is in the path
  151 checkpath ()
  152 {
  153  ARG="$1"
  154  OLDIFS="$IFS"; IFS=":";eval set "$PATH";IFS="$OLDIFS"
  155  for i
  156  do
  157    if [ "$i" = "$ARG" ]; then
  158      return 0
  159    fi
  160  done
  161  return 1
  162 }
  163 
  164 # Install files from binary-*.tar
  165 #  $1 = cpu-target
  166 #  $2 = cross prefix
  167 installbinary ()
  168 {
  169   if [ "$2" = "" ]; then
  170     FPCTARGET="$1"
  171     CROSSPREFIX=
  172     PPCPREFIX=ppc
  173   else
  174     FPCTARGET=`echo $2 | sed 's/-$//'`
  175     CROSSPREFIX="$2"
  176     PPCPREFIX=ppcross
  177   fi
  178 
  179   BINARYTAR="${CROSSPREFIX}binary.$1.tar"
  180 
  181   # Select CPU part of FPCTARGET
  182   PPCSUFFIX=${FPCTARGET/-*/}
  183   # conversion from long to short archname for ppc<x>
  184   case $PPCSUFFIX in
  185     aarch64)
  186       PPCSUFFIX=a64;;
  187     alpha)
  188       PPCSUFFIX=axp;;
  189     m68k)
  190       PPCSUFFIX=68k;;
  191     i386)
  192       PPCSUFFIX=386;;
  193     i8086)
  194       PPCSUFFIX=8086;;
  195     powerpc)
  196       PPCSUFFIX=ppc;;
  197     powerpc64)
  198       PPCSUFFIX=ppc64;;
  199     riscv32)
  200       PPCSUFFIX=rv32;;
  201     riscv64)
  202       PPCSUFFIX=rv64;;
  203     x86_64)
  204       PPCSUFFIX=x64;;
  205   esac
  206 
  207   # Install compiler/RTL. Mandatory.
  208   echo "Installing compiler and RTL for $FPCTARGET..."
  209   # Full install builds cross generated on x86_64-linux have a different name for base tar.gz file
  210   basetargz=`$CMDTAR -tf "$BINARYTAR" | sed -n -e "/^base.*tar\.gz/p" -e "/^$FPCTARGET-base.*tar\.gz/p" | head -1 `
  211   if [ -n "$basetargz" ] ; then
  212     unztarfromtar "$BINARYTAR" "$basetargz" "$PREFIX"
  213   else
  214     unztarfromtar "$BINARYTAR" "${CROSSPREFIX}base.$1.tar.gz" "$PREFIX"
  215   fi
  216 
  217   if [ -f "binutils-${CROSSPREFIX}$1.tar.gz" ]; then
  218     if yesno "Install Cross binutils"; then
  219       unztar "binutils-${CROSSPREFIX}$1.tar.gz" "$PREFIX"
  220     fi
  221   fi
  222 
  223   # Install symlink
  224   if [ -f "$LIBDIR/${PPCPREFIX}${PPCSUFFIX}" ] ; then
  225     rm -f "$EXECDIR/${PPCPREFIX}${PPCSUFFIX}"
  226     ln -sf "$LIBDIR/${PPCPREFIX}${PPCSUFFIX}" "$EXECDIR/${PPCPREFIX}${PPCSUFFIX}"
  227   elif [ -f "$LIBDIR/ppc${PPCSUFFIX}" ] ; then
  228     rm -f "$EXECDIR/ppc${PPCSUFFIX}"
  229     ln -sf "$LIBDIR/ppc${PPCSUFFIX}" "$EXECDIR/ppc${PPCSUFFIX}"
  230   else
  231     echo "Warning: Compiler for $FPCTARGET not found"
  232   fi
  233 
  234   echo "Installing rtl packages..."
  235   listtarfiles "$BINARYTAR" packages units-rtl
  236   for f in $packages
  237   do
  238     p=`echo "$f" | sed -e 's+^.*units-\([^\.]*\)\..*+\1+'`
  239     echo "Installing $p"
  240     unztarfromtar "$BINARYTAR" "$f" "$PREFIX"
  241   done
  242 
  243   echo "Installing fcl..."
  244   listtarfiles "$BINARYTAR" packages units-fcl
  245   for f in $packages
  246   do
  247     p=`echo "$f" | sed -e 's+^.*units-\([^\.]*\)\..*+\1+'`
  248     echo "Installing $p"
  249     unztarfromtar "$BINARYTAR" "$f" "$PREFIX"
  250   done
  251 
  252   echo "Installing packages..."
  253   listtarfiles "$BINARYTAR" packages units
  254   for f in $packages
  255   do
  256     if ! echo "$f" | $CMDGREP $grep_silent_opt fcl > /dev/null ; then
  257       if ! echo "$f" | $CMDGREP $grep_silent_opt rtl > /dev/null ; then
  258         p=`echo "$f" | sed -e 's+^.*units-\([^\.]*\)\..*+\1+'`
  259     echo "Installing $p"
  260         unztarfromtar "$BINARYTAR" "$f" "$PREFIX"
  261       fi
  262     fi
  263   done
  264 
  265   echo "Installing utilities..."
  266   listtarfiles "$BINARYTAR" packages ${CROSSPREFIX}utils
  267   for f in $packages
  268   do
  269     p=`echo "$f" | sed -e 's+^.*utils-\([^\.]*\)\..*+\1+' -e 's+^.*\(utils\)[^\.]*\..*+\1+'`
  270     echo "Installing $p"
  271     unztarfromtar "$BINARYTAR" "$f" "$PREFIX"
  272   done
  273 
  274   # Should this be here at all without a big Linux test around it?
  275   if [ "x$UID" = "x0" ]; then
  276     chmod u=srx,g=rx,o=rx "$PREFIX/bin/grab_vcsa"
  277   fi
  278 
  279   ide=`$TAR -tf $BINARYTAR | grep "${CROSSPREFIX}ide.$1.tar.gz"`
  280   if [ "$ide" = "${CROSSPREFIX}ide.$1.tar.gz" ]; then
  281     if yesno "Install Textmode IDE"; then
  282       unztarfromtar "$BINARYTAR" "${CROSSPREFIX}ide.$1.tar.gz" "$PREFIX"
  283     fi
  284   fi
  285 
  286   rm -f *."$1".tar.gz
  287 }
  288 
  289 
  290 # --------------------------------------------------------------------------
  291 # welcome message.
  292 #
  293 
  294 clear
  295 echo "This shell script will attempt to install the Free Pascal Compiler"
  296 echo "version $FULLVERSION with the items you select"
  297 echo
  298 
  299 # Here we start the thing.
  300 HERE=`pwd`
  301 
  302 OSNAME=`uname -s | tr "[:upper:]" "[:lower:]"`
  303 case "$OSNAME" in
  304   haiku)
  305      # Install in /boot/common or /boot/home/config ?
  306      if checkpath /boot/common/bin; then
  307          PREFIX=/boot/common
  308      else
  309          PREFIX=/boot/home/config
  310      fi
  311      # If we can't write on prefix, we are probably 
  312      # on Haiku with package management system.
  313      # In this case, we have to install fpc in the non-packaged subdir
  314      if [ ! -w "$PREFIX" ]; then
  315         PREFIX="$PREFIX/non-packaged"
  316      fi
  317   ;;
  318   freebsd)
  319      PREFIX=/usr/local
  320   ;;
  321   sunos)
  322      # Check if GNU llinker is recent enough, version 2.21 is needed at least
  323      GNU_LD=`which gld`
  324      supported_emulations=`"$GNU_LD" --target-help | sed -n "s|^\(elf.*\):|\1|p" `
  325      supports_elf_i386_sol2=`echo $supported_emulations | grep -w elf_i386_sol2 `
  326      supports_elf_x86_64_sol2=`echo $supported_emulations | grep -w elf_x86_64_sol2 `
  327      if [ "$supports_elf_i386_sol2" = "" ]; then
  328        echo -n "GNU linker $GNU_LD does not support elf_i386_sol2 emulation, please consider "
  329        echo "upgrading binutils package to at least version 2.21"
  330      elif [ "$supports_elf_x86_64_sol2" = "" ]; then
  331        echo -n "GNU linker $GNU_LD does not support elf_x86_64_sol2 emulation, please consider "
  332        echo "upgrading binutils package to at least version 2.21"
  333      fi
  334      PREFIX=/usr/local
  335   ;;
  336   aix)
  337      # Install in /usr/local or /usr ?
  338      if checkpath /usr/local/bin; then
  339          PREFIX=/usr/local
  340      else
  341          PREFIX=/usr
  342      fi
  343   ;;
  344   *)
  345      # Install in /usr/local or /usr ?
  346      if checkpath /usr/local/bin; then
  347          PREFIX=/usr/local
  348      else
  349          PREFIX=/usr
  350      fi
  351   ;;
  352 esac
  353 
  354 # If we can't write on prefix, select subdir of home dir
  355 if [ ! -w "$PREFIX" ]; then
  356   PREFIX="$HOME/fpc-$VERSION"
  357 fi
  358 
  359 case "$OSNAME" in
  360   haiku)
  361      ask "Install prefix (/boot/common or /boot/home/config) " PREFIX
  362   ;;
  363   *)
  364      ask "Install prefix (/usr or /usr/local) " PREFIX
  365   ;;
  366 esac
  367 
  368 # Support ~ expansion
  369 PREFIX=`eval echo $PREFIX`
  370 export PREFIX
  371 makedirhierarch "$PREFIX"
  372 
  373 # Set some defaults.
  374 LIBDIR="$PREFIX/lib/fpc/$VERSION"
  375 SRCDIR="$PREFIX/src/fpc-$VERSION"
  376 EXECDIR="$PREFIX/bin"
  377 
  378 BSDHIER=0
  379 case "$OSNAME" in
  380 *bsd)
  381   BSDHIER=1;;
  382 esac
  383 
  384 SHORTARCH="$ARCHNAME"
  385 FULLARCH="$ARCHNAME-$OSNAME"
  386 DOCDIR="$PREFIX/share/doc/fpc-$VERSION"
  387 
  388 case "$OSNAME" in
  389   freebsd)  
  390      # normal examples are already installed in fpc-version. So added "demo"
  391      DEMODIR="$PREFIX/share/examples/fpc-$VERSION/demo"
  392      ;;
  393   *)
  394      DEMODIR="$DOCDIR/examples"
  395      ;;
  396 esac
  397 
  398 # Install all binary releases
  399 for f in *binary*.tar
  400 do
  401   target=`echo $f | sed 's+^.*binary\.\(.*\)\.tar$+\1+'`
  402   cross=`echo $f | sed 's+binary\..*\.tar$++'`
  403 
  404   # cross install?
  405   if [ "$cross" != "" ]; then
  406     if [ "`which fpc 2>/dev/null`" = '' ]; then
  407       echo "No native FPC found."
  408       echo "For a proper installation of a cross FPC the installation of a native FPC is required."
  409       exit 1
  410     else
  411       if [ `fpc -iV` != "$VERSION" ]; then
  412         echo "Warning: Native and cross FPC doesn't match; this could cause problems"
  413       fi
  414     fi
  415   fi
  416   installbinary "$target" "$cross"
  417 done
  418 
  419 echo Done.
  420 echo
  421 
  422 # Install the documentation. Optional.
  423 if [ -f doc-pdf.tar.gz ]; then
  424   if yesno "Install documentation"; then
  425     echo Installing documentation in "$DOCDIR" ...
  426     makedirhierarch "$DOCDIR"
  427     unztar doc-pdf.tar.gz "$DOCDIR" "$strip_tar_opt"
  428     echo Done.
  429   fi
  430 fi
  431 echo
  432 
  433 # Install the demos. Optional.
  434 if [ -f demo.tar.gz ]; then
  435   if yesno "Install demos"; then
  436     ask "Install demos in" DEMODIR
  437     echo Installing demos in "$DEMODIR" ...
  438     makedirhierarch "$DEMODIR"
  439     unztar demo.tar.gz "$DEMODIR"
  440     echo Done.
  441   fi
  442 fi
  443 echo
  444 
  445 # Post substitution of FPC_VERSION to $fpc_version in cfg scripts
  446 subst_pattern=ask
  447 
  448 function substitute_version_string ()
  449 {
  450   file=$1
  451   has_version=`grep $VERSION $file`
  452   if [ ! -z "$has_version" ] ; then
  453     if [ "$subst_pattern" == "ask" ] ; then
  454       if yesno "Subtitute $VERSION by \$fpcversion in config files"; then
  455         subst_pattern=yes
  456       else
  457         subst_pattern=no
  458       fi
  459     fi
  460     if [ "$subst_pattern" == "yes" ] ; then
  461       has_dollar_fpcversion=`grep '\$fpcversion' $file`
  462       has_CompilerVersion=`grep '\{CompilerVersion\}' $file`
  463       if [ -n "$has_dollar_fpcversion" ] ; then
  464         echo "File $file contains string \"$VERSION\", trying to subtitute with \"\$fpcversion\""
  465         sed "s:$VERSION:\$fpcversion:g" $file > $file.tmp
  466         sed_res=$?
  467         if [ $sed_res -eq 0 ] ; then
  468           mv -f $file.tmp $file
  469         else
  470           echo "sed failed, res=$sed_res"
  471         fi
  472       elif [ -n "$has_CompilerVersion" ] ; then
  473         echo "File $file contains string \"$VERSION\", trying to subtitute with \"{CompilerVersion}\""
  474         sed "s:$VERSION:\{CompilerVersion\}:g" $file > $file.tmp
  475         sed_res=$?
  476         if [ $sed_res -eq 0 ] ; then
  477           mv -f $file.tmp $file
  478         else
  479           echo "sed failed, res=$sed_res"
  480         fi
  481       fi
  482     fi
  483   fi
  484 }
  485 
  486 # Install /etc/fpc.cfg, this is done using the samplecfg script
  487 if [ "$cross" = "" ]; then
  488   "$LIBDIR/samplecfg" "$LIBDIR" | tee samplecfg.log
  489   file_list=`sed -n 's:.*Writing sample configuration file to ::p' samplecfg.log`
  490   if [ ! -z "$file_list" ] ; then
  491     for file in $file_list ; do
  492       if [ -w $file ] ; then
  493         substitute_version_string $file
  494       fi
  495     done
  496   fi
  497   rm samplecfg.log
  498 else
  499   echo "No fpc.cfg created because a cross installation has been done."
  500 fi
  501 
  502 # The End
  503 echo
  504 echo End of installation.
  505 echo
  506 echo Refer to the documentation for more information.
  507 echo