1#!/bin/bash
2
3# FIXME: do we need a license (or whatever else) header here?
4
5# This script merges libffi sources from upstream.
6
7# Default to the tip of master branch.
8commit=${1-master}
9
10fatal() {
11  echo "$1"
12  exit 1;
13}
14
15get_upstream() {
16  rm -rf upstream
17  git clone https://github.com/libffi/libffi.git upstream
18  pushd upstream
19  git checkout $commit || fatal "Failed to checkout $commit"
20  popd
21}
22
23get_current_rev() {
24  cd upstream
25  git rev-parse HEAD
26}
27
28pwd | grep 'libffi$' || \
29  fatal "Run this script from the libffi directory"
30get_upstream
31CUR_REV=$(get_current_rev)
32echo Current upstream revision: $CUR_REV
33
34# Remove the unused files.
35pushd upstream
36rm -rf ChangeLog.old .appveyor* .ci .github .gitignore .travis* \
37	config.guess config.sub libtool-ldflags m4 make_sunver.pl \
38	msvc_build
39rm -rf .git autogen.sh
40cp -a . ..
41popd
42
43rm -rf upstream
44
45# Update the MERGE file.
46cat << EOF > MERGE
47$CUR_REV
48
49The first line of this file holds the git revision number of the
50last merge done from the master library sources.
51EOF
52