#note: DISTRO_BINARY_COMPAT and DISTRO_FILE_PREFIX are visible here, exported in 2createpackages.
#140117 xARCHDIR, ARCHDIR and DISTRO_ARCHDIR_SYMLINKS exported in 2createpackages. 
#140117 note, 2createpackages may move /lib, /usr/lib, /usr/bin in template to ARCHDIR subdir.

#120517 gentoo...
#DISTRO_BINARY_COMPAT is exported in 2createpackages.
if [ "$DISTRO_BINARY_COMPAT" = "gentoo" ];then
 GCCEXE="`find usr -name 'gcc' | head -n 1`"
 if [ "$GCCEXE" ];then
  GCCBINDIR="`dirname $GCCEXE`"
  cp -a -f --remove-destination ${GCCBINDIR}/* usr/bin/
  #rm -rf ./${GCCBINDIR}
 fi
fi

#ubuntu is the problem, these symlinks are missing...
if [ "$xARCHDIR" ];then #140117
 if [ ! -e usr/bin/${ARCHDIR}/g++ ];then
  REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name "g++-*" 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  if [ "$REALFILE" ];then
   ln -s $REALFILE usr/bin/${ARCHDIR}/g++
   ln -s $REALFILE usr/bin/${ARCHDIR}/c++
  fi
 fi
fi
if [ ! -e usr/bin/g++ ];then
 REALFILE="`find usr/bin/ -maxdepth 1 -type f -name "g++-*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 if [ "$REALFILE" ];then
  ln -s $REALFILE usr/bin/g++
  ln -s $REALFILE usr/bin/c++
 fi
fi

#121028 01micko: Slackware ships with exec named gcc-4.7.1 and another util named gcc-somethingelse (forget sorry)
# change -name "gcc-*" to -name "gcc-*.*" ...
if [ "$xARCHDIR" ];then #140117
 if [ ! -e usr/bin/${ARCHDIR}/gcc ];then
  REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name "gcc-*.*" 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  if [ "$REALFILE" ];then
   ln -s $REALFILE usr/bin/${ARCHDIR}/gcc
   ln -s $REALFILE usr/bin/${ARCHDIR}/cc
  fi
 fi
fi
if [ ! -e usr/bin/gcc ];then
 REALFILE="`find usr/bin/ -maxdepth 1 -type f -name "gcc-*.*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 if [ "$REALFILE" ];then
  ln -s $REALFILE usr/bin/gcc
  ln -s $REALFILE usr/bin/cc
 fi
fi

#t2, i had to recompile gcc in running quirky, my new binary tarball has some things missing...
if [ "$xARCHDIR" ];then #140117
 if [ ! -e usr/bin/${ARCHDIR}/cc ];then
  REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name gcc 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  [ "$REALFILE" = "" ] && REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name "gcc-*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  [ "$REALFILE" ] && ln -s $REALFILE usr/bin/${ARCHDIR}/cc
 fi
 if [ ! -e usr/lib/${ARCHDIR}/libgcc_s.so ];then
  REALFILE="`find usr/lib/${ARCHDIR}/ -maxdepth 1 -type f -name "libgcc_s.so*" 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  [ "$REALFILE" ] && ln -s $REALFILE usr/lib/${ARCHDIR}/libgcc_s.so
 fi
 if [ ! -e usr/bin/${ARCHDIR}/c++ ];then
  REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name g++ 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  [ "$REALFILE" = "" ] && REALFILE="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name "g++-*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
  [ "$REALFILE" ] && ln -s $REALFILE usr/bin/${ARCHDIR}/c++
 fi
fi
if [ ! -e usr/bin/cc ];then
 REALFILE="`find usr/bin/ -maxdepth 1 -type f -name gcc | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 [ "$REALFILE" = "" ] && REALFILE="`find usr/bin/ -maxdepth 1 -type f -name "gcc-*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 [ "$REALFILE" ] && ln -s $REALFILE usr/bin/cc
fi
if [ ! -e usr/lib/libgcc_s.so ];then
 REALFILE="`find usr/lib/ -maxdepth 1 -type f -name "libgcc_s.so*" 2>/dev/null | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 [ "$REALFILE" ] && ln -s $REALFILE usr/lib/libgcc_s.so
fi
if [ ! -e usr/bin/c++ ];then
 REALFILE="`find usr/bin/ -maxdepth 1 -type f -name g++ | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 [ "$REALFILE" = "" ] && REALFILE="`find usr/bin/ -maxdepth 1 -type f -name "g++-*" | head -n 1 | rev | cut -f 1 -d '/' | rev`"
 [ "$REALFILE" ] && ln -s $REALFILE usr/bin/c++
fi

#110628 mageia 1...
if [ "$xARCHDIR" ];then #140117
 if [ ! -e usr/bin/${ARCHDIR}/cpp ];then
  CPPBIN="`find usr/bin/${ARCHDIR}/ -maxdepth 1 -type f -name 'cpp-*' 2>/dev/null | head -n 1`"
  if [ "$CPPBIN" ];then
   CPPBASE="`basename $CPPBIN`"
   ln -s $CPPBASE usr/bin/${ARCHDIR}/cpp
  fi
 fi
fi
if [ ! -e usr/bin/cpp ];then
 CPPBIN="`find usr/bin/ -maxdepth 1 -type f -name 'cpp-*' | head -n 1`"
 if [ "$CPPBIN" ];then
  CPPBASE="`basename $CPPBIN`"
  ln -s $CPPBASE usr/bin/cpp
 fi
fi

#130707...
if [ "$xARCHDIR" ];then #140117
 BADPYLIB="$(find usr/lib/${ARCHDIR} -mindepth 1 -maxdepth 1 -iname 'libstdc*.py' 2>/dev/null | tr '\n' ' ')"
 if [ "$BADPYLIB" ];then
  for ABADPYLIB in $BADPYLIB
  do
   rm -f $ABADPYLIB
  done
 fi
fi
BADPYLIB="$(find usr/lib -mindepth 1 -maxdepth 1 -iname 'libstdc*.py' | tr '\n' ' ')"
if [ "$BADPYLIB" ];then
 for ABADPYLIB in $BADPYLIB
 do
  rm -f $ABADPYLIB
 done
fi

