init.sh 1.51 KB
#!/bin/bash
# initialize source codes of all supported libraries

# ------------------------------------------------------------------------------
# newlib
# ------------------------------------------------------------------------------
# newlib dir
NEWLIB_DIR=newlib
# git repository: 
NELIB_REPO=git://sourceware.org/git/newlib-cygwin.git
# git commit: 
NEWLIB_COMMIT=6238b1877d3c83b8b9ed589494d0705386b7f4f7
# git patches:
NEWLIB_PATCHES=../patches/newlib-*

# get newlib repository
if [ -d ${NEWLIB_DIR} ] && [ ! -d ${NEWLIB_DIR}/.github ]; then
  echo "* Folder NEWLIB exists without git -> remove"
  rm -r ${NEWLIB_DIR}
fi

if [ -d ${NEWLIB_DIR}/.github ]; then
  echo "Git is already cloned"
else
  echo "* - clone NEWLIB"
  
  if [ ! -f .gitmodules ]; then
    echo "get newlib from a remote repository"
    git clone ${NELIB_REPO} ${NEWLIB_DIR}
  else
#    git submodule init
#    git submodule update
    git clone git://sourceware.org/git/newlib-cygwin.git newlib
  fi
fi

# check the current commit
cd ${NEWLIB_DIR}
CURCOM=$(git rev-parse HEAD)

echo "CURCOM = ${CURCOM}"

if [ "${CURCOM}" == "${NEWLIB_COMMIT}" ]; then
  echo "* right commit"
else
  echo "* - reset to commit"
  git reset --hard ${NEWLIB_COMMIT}
fi

# check if patched
for p in `ls -1 ${NEWLIB_PATCHES}`; do
  echo "* patch ${p}"
  if ! patch -R -p1 -s -f --dry-run <${p}; then
    echo "  * - use"
    patch -p1 <${p}
  else
    echo "  * already used"
  fi
done

# ------------------------------------------------------------------------------

echo "*** done"